- Joined
- Dec 11, 2007
- Messages
- 755
Ok, I made a working Jass spell, it works quite nicely, but I"m just wondering if it has any leaks in it. I'm quite confused about jass leaks and locals, so help would be much apprecated. I'm kinda a jass noob right now XD
JASS:
globals
//Below is the customizable section of the spell----------------------------------------------------------------------------------
integer Id = 'A000'//This is the rawcode of the ability you want to add.
real TimeStill = 2.//this is the amount of time the unit needs to be standing still before the ability is added. It is in seconds
//Dont Touch These, or anything below this line!!!--------------------------------------------------------------------------------
integer array UnitUsed
unit array Units
real array UnitTimeStill
real array UnitX
real array UnitY
integer array UnitHasAbility
integer maxunits = 0
endglobals
function AddUnit_TimedAbility takes unit u returns nothing
local integer i = 0
loop
exitwhen UnitUsed[i] == 0
set i = i+1
endloop
set Units[i] = u
set UnitHasAbility[i] = 0
set UnitUsed[i] = 1
if i > maxunits then
set maxunits = i
endif
set u = null
endfunction
function RemoveUnit_TimedAbility takes unit u returns nothing
local integer i = 0
loop
exitwhen Units[i] == u
set i = i+1
endloop
set UnitUsed[i] = 0
set Units[i] = null
set UnitTimeStill[i] = 0.
set UnitX[i] = 0.
set UnitY[i] = 0.
endfunction
function Trig_Adding_Abilitys_Actions takes nothing returns nothing
local integer i = 0
local real X
local real Y
local location p
loop
exitwhen i > maxunits
if UnitUsed[i] == 1 then
set p = GetUnitLoc(Units[i])
set X = GetLocationX(p)
set Y = GetLocationY(p)
if X == UnitX[i] and Y == UnitY[i] then
set UnitTimeStill[i] = UnitTimeStill[i] + 0.2
else
set UnitTimeStill[i] = 0.
set UnitX[i] = X
set UnitY[i] = Y
set UnitHasAbility[i] = 0
call UnitRemoveAbility(Units[i], Id)
endif
call RemoveLocation(p)
if UnitTimeStill[i] >= TimeStill then
if UnitHasAbility[i] == 0 then
call UnitAddAbility(Units[i], Id)
set UnitHasAbility[i] = 1
endif
endif
endif
set i = i+1
endloop
endfunction
//===========================================================================
function InitTrig_Adding_Abilitys takes nothing returns nothing
set UnitUsed[0] = 1
set gg_trg_Adding_Abilitys = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Adding_Abilitys, 0.20 )
call TriggerAddAction( gg_trg_Adding_Abilitys, function Trig_Adding_Abilitys_Actions )
endfunction