- Joined
- Jun 17, 2007
- Messages
- 1,433
A simple library that modifies a unit's unitstate periodically. Here it is.
JASS:
library ModifyStatePeriodic requires TimerUtils
struct MSP
static method create takes unit whichunit, real amount, real interval, real duration, unitstate state returns thistype
local thistype da = thistype.allocate()
local timer t = CreateTimer()
set da.target = whichunit
set da.amount = amount
set da.max = duration/interval
set da.state = state
call SetTimerData(t, da)
call TimerStart(t, interval, true, function thistype.Callback)
return da
endmethod
private static method Callback takes nothing returns nothing
local thistype d = GetTimerData(GetExpiredTimer())
call SetUnitState(d.target, d.state, GetUnitState(d.target, d.state) + d.amount)
set d.tick = d.tick + 1
if d.tick >= d.max then
call d.destroy()
call ReleaseTimer(GetExpiredTimer())
endif
endmethod
real tick = 0
real max = 0
unit target = null
real amount = 0
unitstate state = null
endstruct
function ModifyStatePeriodic takes unit whichunit, real amount, real interval, real duration, unitstate state returns nothing
call MSP.create(whichunit, amount, interval, duration, state)
endfunction
endlibrary
Last edited: