Avoid Memories leak

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

HINDYhat
Senior Member
Posts: 101
Joined: June 1st, 2007, 9:05 pm

Re: set patrol to teleport.

Post by HINDYhat »

Ahem... Aero, why aren't you using GetOrderPointX/Y instead of locations? o.O
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: set patrol to teleport.

Post by Aero »

I got it mixed up with GetSpellTargetLoc() (As there is no GetSpellTargetX/Y)

That aside, it was to show initiald how to deal with locations.
initialD
Some Honorary Title
Posts: 1713
Joined: June 8th, 2007, 5:08 am
Title: Angry Bird

Re: Advoid Memories leak

Post by initialD »

Thanks Aero. Here are two more function. I will aprreciate it if you could just tell me if they are leaking or not.
If those two function leaks, how to solve it? Thanks
Spoiler:

Code: Select all

function ControlOff takes nothing returns nothing
local integer udg_integerfai=16
set udg_integerfai=S2I(SubStringBJ(GetEventPlayerChatString(),6,8))
call TriggerSleepAction(.1)
call SetUserControlForceOff(GetForceOfPlayer(Player(-1+(udg_integerfai))))
set udg_integerfai=16
endfunction

function ModSP takes nothing returns nothing
call ModifyHeroSkillPoints(GetEnumUnit(),2,S2I(SubStringBJ(GetEventPlayerChatString(),4,20)))
endfunction
about the fucntion TP, so if I use getorderpointx/y, it will not leak, right?

Code: Select all

function Tp takes nothing returns nothing
local unit u=GetTriggerUnit()
local location l=GetOrderPointLoc()
call SetUnitX(u,GetOrderPointX(l))
call SetUnitY(u,GetOrderPointY(l))
set u=null
set l=null
endfunction

lastly, if it possible to make -armor XX and -damage XX commmands (to set hero's dmg and armor) with only pure JASS? If possible how to do it?
Sorry for bothering. I am a noob though. Is there any website I can learn all the functions for JASS? or should I don't click me a book for learning JASS?
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Advoid Memories leak

Post by weirdone2 »

Well in my cheatpack their are two commands called deca and inca, I think, that do this though you wont actually see the attack go up or anything it just adds dmg to your atks and makes enemys do less dmg. As for learning jass best advise is experimenting, though also theirs something like a guide in the map pack in my sig.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Advoid Memories leak

Post by Aero »

Code: Select all

function ControlOff takes nothing returns nothing
local integer playerId = S2I(SubString(GetEventPlayerChatString(),5,7))
if (playerId < 1) or (playerId > 12) then
    return
endif
if Player(playerId-1)==GetLocalPlayer() then
    call EnableUserControl(false)
endif
endfunction

------------If only 1 player at a time will have control disabled, use this instead---------------

function ControlOff takes nothing returns nothing
local integer playerId = S2I(SubString(GetEventPlayerChatString(),5,7))
if (playerId < 1) or (playerId > 12) then
    return
endif
call EnableUserControl(GetLocalPlayer()!=Player(playerId-1))
endfunction

--------------------------------------------------------------------------------------------------

function ModSP takes nothing returns nothing
local unit whichUnit = GetEnumUnit()
local integer howManySkillPoints = S2I(SubString(GetEventPlayerChatString(),3,10))
call UnitModifySkillPoints(whichUnit,howManySkillPoints-GetHeroSkillPoints(whichUnit))
set u=null
endfunction

function Tp takes nothing returns nothing
local unit u=GetTriggerUnit()
call SetUnitX(u,GetOrderPointX())
call SetUnitY(u,GetOrderPointY())
set u=null
endfunction
Note: Input for the ControlOff function is as follows:
1 = Player(0) Red
2 = Player(1) Blue
...
12 = Player(11) Brown

It's better to keep it this way so if the user uses '-1' or something similar as input, it won't crash, and in case the user inputs non-numeric strings (Which S2I returns as 0... Player(0) = red)

-------------------------------------------------------

The only leaks were...

GetForceOfPlayer(Player(-1+(udg_integerfai)))

Code: Select all

function GetForceOfPlayer takes player whichPlayer returns force
    local force f = CreateForce()
    call ForceAddPlayer(f, whichPlayer)
    return f
endfunction
This function leaks as a force (A handle) is not cleaned up.

and this leaks...

local location l=GetOrderPointLoc()

because there is no "RemoveLocation(l)" call in the code block.
initialD
Some Honorary Title
Posts: 1713
Joined: June 8th, 2007, 5:08 am
Title: Angry Bird

Re: Advoid Memories leak

Post by initialD »

thanks aero and weirdone.

Code: Select all

call EnableUserControl(whichPlayer)
Why syntax checker say " cannot convert player to boolean" What I did wrong?

Code: Select all

function ModSP takes nothing returns nothing
local unit whichUnit = GetEnumUnit()
local integer howManySkillPoints = S2I(SubString(GetEventPlayerChatString(),3,10))
call UnitModifySkillPoints(whichUnit,howManySkillPoints-GetHeroSkillPoints(whichUnit))
set u=null
endfunction
Aero, could explain a bit why is this better then the previous code? For learning purpose. Thanks
Dekar
Forum Drunk
Posts: 2918
Joined: January 17th, 2007, 4:22 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Advoid Memories leak

Post by Dekar »

initiald wrote:thanks aero and weirdone.

Code: Select all

call EnableUserControl(whichPlayer)
Why syntax checker say " cannot convert player to boolean" What I did wrong?
maybe EnableUserControl takes boolean?
Don't pm me with Warcraft questions, this is a forum so just make a post!
In the world of thinking we are all immigrants. -Robert Nozick
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Advoid Memories leak

Post by Aero »

initiald wrote:thanks aero and weirdone.

Code: Select all

call EnableUserControl(whichPlayer)
Why syntax checker say " cannot convert player to boolean" What I did wrong?

Code: Select all

function ModSP takes nothing returns nothing
local unit whichUnit = GetEnumUnit()
local integer howManySkillPoints = S2I(SubString(GetEventPlayerChatString(),3,10))
call UnitModifySkillPoints(whichUnit,howManySkillPoints-GetHeroSkillPoints(whichUnit))
set u=null
endfunction
Aero, could explain a bit why is this better then the previous code? For learning purpose. Thanks
call EnableUserControl(whichPlayer)

That was just a typo. I originally had call EnableUserControl(GetLocalPlayer()!=Player(playerId-1)) and from the copy pasting it got screwed up.
Anyways, I optimized that piece of code a bit and fixed the syntax error.

As for "function ModSP". You used a BJ function ...

Code: Select all

function ModifyHeroSkillPoints takes unit whichHero, integer modifyMethod, integer value returns boolean
    if (modifyMethod == bj_MODIFYMETHOD_ADD) then
        return UnitModifySkillPoints(whichHero, value)
    elseif (modifyMethod == bj_MODIFYMETHOD_SUB) then
        return UnitModifySkillPoints(whichHero, -value)
    elseif (modifyMethod == bj_MODIFYMETHOD_SET) then
        return UnitModifySkillPoints(whichHero, value - GetHeroSkillPoints(whichHero))
    else
        // Unrecognized modification method - ignore the request and return failure.
        return false
    endif
endfunction
I just optimized it and sped it up.
Also, I could of simply subbed in "S2I(SubStringBJ(GetEventPlayerChatString(),4,20))" for "howManySkillPoints" but I chose to put it in a variable first. The reason? Well, the code executes equally fast and it has better readability.
initialD
Some Honorary Title
Posts: 1713
Joined: June 8th, 2007, 5:08 am
Title: Angry Bird

Re: Avoid Memories leak

Post by initialD »

Thanks Aero for all the helps. :) You are awesome.

If you have time would you please take a look at this cheat comand? I guess there are memory leaks somewhere here and there, just not sure of it, becasue it obviously make some stupid 56k PC laggy. lol Would it make less laggy if I remove those Globals and put them as locals?
And...... If there any possible to make it shorter and cleaner? This command (similar to -hear in JJ's CP, or -echo in Xantan's CP or "Hear enemy chat" in Cheat Menu) seems like taking a lot of spaces.....haha
Take your time.
Spoiler:

Code: Select all

globals
force udg_Spy=CreateForce()
trigger gg_trg_Spy=CreateTrigger()

endglobals
function Trig_Spy_Func001C takes nothing returns boolean
return(IsPlayerInForce(Player(0),udg_Spy)==false)and(GetTriggerPlayer()==Player(0))
endfunction
function Trig_Spy_Func002C takes nothing returns boolean
return(IsPlayerInForce(Player(1),udg_Spy)==false)and(GetTriggerPlayer()==Player(1))
endfunction
function Trig_Spy_Func003C takes nothing returns boolean
return(IsPlayerInForce(Player(2),udg_Spy)==false)and(GetTriggerPlayer()==Player(2))
endfunction
function Trig_Spy_Func004C takes nothing returns boolean
return(IsPlayerInForce(Player(3),udg_Spy)==false)and(GetTriggerPlayer()==Player(3))
endfunction
function Trig_Spy_Func005C takes nothing returns boolean
return(IsPlayerInForce(Player(4),udg_Spy)==false)and(GetTriggerPlayer()==Player(4))
endfunction
function Trig_Spy_Func006C takes nothing returns boolean
return(IsPlayerInForce(Player(5),udg_Spy)==false)and(GetTriggerPlayer()==Player(5))
endfunction
function Trig_Spy_Func007C takes nothing returns boolean
return(IsPlayerInForce(Player(6),udg_Spy)==false)and(GetTriggerPlayer()==Player(6))
endfunction
function Trig_Spy_Func008C takes nothing returns boolean
return(IsPlayerInForce(Player(7),udg_Spy)==false)and(GetTriggerPlayer()==Player(7))
endfunction
function Trig_Spy_Func009C takes nothing returns boolean
return(IsPlayerInForce(Player(8),udg_Spy)==false)and(GetTriggerPlayer()==Player(8))
endfunction
function Trig_Spy_Func010C takes nothing returns boolean
return(IsPlayerInForce(Player(9),udg_Spy)==false)and(GetTriggerPlayer()==Player(9))
endfunction
function Trig_Spy_Func011C takes nothing returns boolean
return(IsPlayerInForce(Player(10),udg_Spy)==false)and(GetTriggerPlayer()==Player(10))
endfunction
function Trig_Spy_Func012C takes nothing returns boolean
return(IsPlayerInForce(Player(11),udg_Spy)==false)and(GetTriggerPlayer()==Player(11))
endfunction
function Trig_Spy_Actions takes nothing returns nothing
if(Trig_Spy_Func001C())then
call DisplayTextToForce(udg_Spy,("|cffFF0000"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func002C())then
call DisplayTextToForce(udg_Spy,("|cff0000FF"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func003C())then
call DisplayTextToForce(udg_Spy,("|cff00FFFF"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func004C())then
call DisplayTextToForce(udg_Spy,("|cffA020F0"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func005C())then
call DisplayTextToForce(udg_Spy,("|cffFFFF00"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func006C())then
call DisplayTextToForce(udg_Spy,("|cffFFA500"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func007C())then
call DisplayTextToForce(udg_Spy,("|cff00FF00"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func008C())then
call DisplayTextToForce(udg_Spy,("|cffFF1493"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func009C())then
call DisplayTextToForce(udg_Spy,("|cff696969"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func010C())then
call DisplayTextToForce(udg_Spy,("|cff9AC0CD"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func011C())then
call DisplayTextToForce(udg_Spy,("|cff006400"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
if(Trig_Spy_Func012C())then
call DisplayTextToForce(udg_Spy,("|cff8B4513"+(GetPlayerName(GetTriggerPlayer())+("|r : "+GetEventPlayerChatString()))))
endif
endfunction
function Eyes takes nothing returns nothing
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(0),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(1),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(2),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(3),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(4),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(5),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(6),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(7),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(8),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(9),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(10),"",false)
call TriggerRegisterPlayerChatEvent(gg_trg_Spy,Player(11),"",false)
call TriggerAddAction(gg_trg_Spy,function Trig_Spy_Actions)
endfunction

function cheatuse takes nothing returns nothing
local string s=GetEventPlayerChatString()
if SubString(s,0,3)=="-ha"then
call ForceAddPlayer(udg_Spy,GetTriggerPlayer())
call Eyes()
elseif SubString(s,0,5)=="-noha"then
call ForceRemovePlayer(udg_Spy,GetTriggerPlayer())
endif
endfunction
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Avoid Memories leak

Post by Aero »

That is extremely leaky.
It doesn't leak handles but strings are where it leaks.

When you display text to a player, it sucks up a little bit of memory permanently.
If that same string is re-displayed, no additional memory is sucked up.

If it's a different string, it sucks up even more memory.

Text on leaderboards leak (and maybe) multiboards seem to leak the same way (Titles only I think from what I tested).
The above is just a guess but the string leaks are for real.

The code could also be optimized a lot (I would do it but don't have any of my wc tools with me as I'm on vacation).

Now, when I get back, I'll show you an awesome texttag system with trackable I have in mind.