function TimeredDamage takes nothing returns nothing
local timer t = GetExpiredTimer()
//Now here we get the stuff we associated with our timer
local unit target = H2U(GetHandlHandle(t, "target") //Since the GetHandleHandle function returns a handle we cannot directly assign that to our local unit so we convert it using the return bug
local unit caster = H2U(GetHandleHandle(t,"caster")
local real damage = GetHandleReal(t,"damage")
local real duration = GetHandleReal(t, "duration")
set duration = duration-1
SetHandleVars(t,"duration")
call UnitDamageTargetBJ(caster, target, damage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_SPELLS)
if(duration == 0) then
PauseTimer(t)
FlushHandleLocals() //This line is VERY IMPORTANT it is what releases the memory from the vars you associated so that i can be reused
DestroyTimer(t)
return
endif
endfunction
function InitTimeredDamage takes unit target, unit caster, real damage, real duration
local timer t = CreateTimer()
//heres where we associate the unit information with the timer
SetHandleHandle(t, "target", target)
SetHandleHandle(t, "caster", caster)
SetHandleReal(t, "damage", damage)
SetHandleReal(t, "duration", duration
StartTimer(t, 1.00, true, function TimeredDamage)
//AT this point this function finishes but the timer we created it still running and every time it expires it will call our "TimeredDamage" function
endfunction