// This code will create a timer and link it to the designated farm.
// Use the GUI variables: FarmUnit, FarmDuration, and FarmTrigger.
// FarmUnit will be set to the associated Farm when it's Timer expires.
// You can use this to create GUI-friendly local timers.
function FarmTimerCallback takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(udg_FarmHash, id, 1)
set udg_FarmUnit = LoadUnitHandle(udg_FarmHash, id, 0)
// run the GUI trigger
call TriggerExecute(trig)
// clean up memory leaks
set t = null
set trig = null
endfunction
function FarmTimerStart takes nothing returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveUnitHandle(udg_FarmHash, id, 0, udg_FarmUnit)
call SaveTriggerHandle(udg_FarmHash, id, 1, udg_FarmTrigger)
call SaveTimerHandle(udg_FarmHash, GetHandleId(udg_FarmUnit), 0, t)
// start timer
call TimerStart(t, udg_FarmDuration, true, function FarmTimerCallback)
// clean up memory leaks
set t = null
endfunction
function FarmDestroyExpiredTimer takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
call FlushChildHashtable(udg_FarmHash, id)
call PauseTimer(t)
call DestroyTimer(t)
set t = null
endfunction
function FarmDestroyTimer takes nothing returns nothing
local timer t = LoadTimerHandle(udg_FarmHash, GetHandleId(udg_FarmUnit), 0)
local integer id = GetHandleId(t)
if id == 0 then
set t = null
return
endif
call FlushChildHashtable(udg_FarmHash, id)
call PauseTimer(t)
call DestroyTimer(t)
set t = null
endfunction