library GUISimpleTimers
// created by Uncle
globals
hashtable GST_Hash = InitHashtable()
timer GST_LoadedTimer
integer GST_NewKey = 0
integer GST_Index = 0
endglobals
// Call this function to destroy and clean up an expired repeating timer.
// Example: Custom script: call GST_DestroyTimer()
// You would call this inside of your GST_Trigger.
function GST_DestroyTimer takes nothing returns nothing
local timer t = GetExpiredTimer()
call FlushChildHashtable(GST_Hash, GetHandleId(t))
call PauseTimer(t)
call DestroyTimer(t)
set t = null
endfunction
// Do NOT call this function yourself.
// This is used with the Key system to "restart" a timer.
// It destroys the previously created timer (if one is found).
// Then the new timer that was just created replaces it.
function GST_RestartTimer takes nothing returns nothing
local integer trigId = GetHandleId(udg_GST_Trigger)
set GST_NewKey = (-1000000000 + (100000 * LoadInteger(GST_Hash, -1, trigId)))
if (GST_NewKey != -1000000000) then
// key already exists
set GST_NewKey = GST_NewKey + udg_GST_RestartKey
else
// key doesn't exist, initialize it
set GST_Index = GST_Index + 1
set GST_NewKey = (-1000000000 + (100000 * GST_Index)) + udg_GST_RestartKey
call SaveInteger(GST_Hash, -1, trigId, GST_Index)
endif
set GST_LoadedTimer = LoadTimerHandle(GST_Hash, GST_NewKey, trigId)
// remove the old timer stored at these keys
if (GST_LoadedTimer != null) then
call PauseTimer(GST_LoadedTimer)
call DestroyTimer(GST_LoadedTimer)
call RemoveSavedInteger(GST_Hash, GST_NewKey, trigId)
endif
endfunction
// Callback functions which run when a timer expires:
function GST_Int_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 2)
local boolean repeating = LoadBoolean(GST_Hash, id, 1)
set udg_GST_Integer1 = LoadInteger(GST_Hash, id, 0)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_IntInt_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 3)
local boolean repeating = LoadBoolean(GST_Hash, id, 2)
set udg_GST_Integer1 = LoadInteger(GST_Hash, id, 0)
set udg_GST_Integer2 = LoadInteger(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_IntIntInt_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 4)
local boolean repeating = LoadBoolean(GST_Hash, id, 3)
set udg_GST_Integer1 = LoadInteger(GST_Hash, id, 0)
set udg_GST_Integer2 = LoadInteger(GST_Hash, id, 1)
set udg_GST_Integer3 = LoadInteger(GST_Hash, id, 2)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_Real_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 2)
local boolean repeating = LoadBoolean(GST_Hash, id, 1)
set udg_GST_Real1 = LoadReal(GST_Hash, id, 0)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_RealReal_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 3)
local boolean repeating = LoadBoolean(GST_Hash, id, 2)
set udg_GST_Real1 = LoadReal(GST_Hash, id, 0)
set udg_GST_Real2 = LoadReal(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_RealRealReal_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 4)
local boolean repeating = LoadBoolean(GST_Hash, id, 3)
set udg_GST_Real1 = LoadReal(GST_Hash, id, 0)
set udg_GST_Real2 = LoadReal(GST_Hash, id, 1)
set udg_GST_Real2 = LoadReal(GST_Hash, id, 2)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_IntReal_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 3)
local boolean repeating = LoadBoolean(GST_Hash, id, 2)
set udg_GST_Integer1 = LoadInteger(GST_Hash, id, 0)
set udg_GST_Real1 = LoadReal(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_Unit_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 2)
local boolean repeating = LoadBoolean(GST_Hash, id, 1)
set udg_GST_Unit1 = LoadUnitHandle(GST_Hash, id, 0)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_UnitUnit_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 3)
local boolean repeating = LoadBoolean(GST_Hash, id, 2)
set udg_GST_Unit1 = LoadUnitHandle(GST_Hash, id, 0)
set udg_GST_Unit2 = LoadUnitHandle(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_UnitUnitUnit_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 4)
local boolean repeating = LoadBoolean(GST_Hash, id, 3)
set udg_GST_Unit1 = LoadUnitHandle(GST_Hash, id, 0)
set udg_GST_Unit2 = LoadUnitHandle(GST_Hash, id, 1)
set udg_GST_Unit3 = LoadUnitHandle(GST_Hash, id, 2)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_UnitReal_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 3)
local boolean repeating = LoadBoolean(GST_Hash, id, 2)
set udg_GST_Unit1 = LoadUnitHandle(GST_Hash, id, 0)
set udg_GST_Real1 = LoadReal(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_UnitInt_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 3)
local boolean repeating = LoadBoolean(GST_Hash, id, 2)
set udg_GST_Unit1 = LoadUnitHandle(GST_Hash, id, 0)
set udg_GST_Integer1 = LoadInteger(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
function GST_Simple_Expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local trigger trig = LoadTriggerHandle(GST_Hash, id, 0)
local boolean repeating = LoadBoolean(GST_Hash, id, 1)
// run the GUI trigger
call TriggerExecute(trig)
// the timer is not repeating so destroy it
if (repeating == false) then
call FlushChildHashtable(GST_Hash, id)
call PauseTimer(t)
call DestroyTimer(t)
endif
// clean up memory leaks
set t = null
set trig = null
endfunction
// Functions to start timers:
function GST_Real takes real r1, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveReal(GST_Hash, id, 0, r1)
call SaveBoolean(GST_Hash, id, 1, repeating)
call SaveTriggerHandle(GST_Hash, id, 2, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_Real_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_RealReal takes real r1, real r2, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveReal(GST_Hash, id, 0, r1)
call SaveReal(GST_Hash, id, 1, r2)
call SaveBoolean(GST_Hash, id, 2, repeating)
call SaveTriggerHandle(GST_Hash, id, 3, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_RealReal_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_RealRealReal takes real r1, real r2, real r3, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveReal(GST_Hash, id, 0, r1)
call SaveReal(GST_Hash, id, 1, r2)
call SaveReal(GST_Hash, id, 2, r3)
call SaveBoolean(GST_Hash, id, 3, repeating)
call SaveTriggerHandle(GST_Hash, id, 4, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_RealRealReal_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_IntReal takes integer i1, real r1, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveInteger(GST_Hash, id, 0, i1)
call SaveReal(GST_Hash, id, 1, r1)
call SaveBoolean(GST_Hash, id, 2, repeating)
call SaveTriggerHandle(GST_Hash, id, 3, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_IntReal_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_Int takes integer i1, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveInteger(GST_Hash, id, 0, i1)
call SaveBoolean(GST_Hash, id, 1, repeating)
call SaveTriggerHandle(GST_Hash, id, 2, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_Int_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_IntInt takes integer i1, integer i2, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveInteger(GST_Hash, id, 0, i1)
call SaveInteger(GST_Hash, id, 1, i2)
call SaveBoolean(GST_Hash, id, 2, repeating)
call SaveTriggerHandle(GST_Hash, id, 3, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_IntInt_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_IntIntInt takes integer i1, integer i2, integer i3, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveInteger(GST_Hash, id, 0, i1)
call SaveInteger(GST_Hash, id, 1, i2)
call SaveInteger(GST_Hash, id, 2, i3)
call SaveBoolean(GST_Hash, id, 3, repeating)
call SaveTriggerHandle(GST_Hash, id, 4, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_IntIntInt_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_UnitInt takes unit u1, integer i1, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveUnitHandle(GST_Hash, id, 0, u1)
call SaveInteger(GST_Hash, id, 1, i1)
call SaveBoolean(GST_Hash, id, 2, repeating)
call SaveTriggerHandle(GST_Hash, id, 3, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_UnitInt_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_UnitReal takes unit u1, real r1, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveUnitHandle(GST_Hash, id, 0, u1)
call SaveReal(GST_Hash, id, 1, r1)
call SaveBoolean(GST_Hash, id, 2, repeating)
call SaveTriggerHandle(GST_Hash, id, 3, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_UnitReal_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_UnitUnitUnit takes unit u1, unit u2, unit u3, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveUnitHandle(GST_Hash, id, 0, u1)
call SaveUnitHandle(GST_Hash, id, 1, u2)
call SaveUnitHandle(GST_Hash, id, 2, u2)
call SaveBoolean(GST_Hash, id, 3, repeating)
call SaveTriggerHandle(GST_Hash, id, 4, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_UnitUnitUnit_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_UnitUnit takes unit u1, unit u2, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveUnitHandle(GST_Hash, id, 0, u1)
call SaveUnitHandle(GST_Hash, id, 1, u2)
call SaveBoolean(GST_Hash, id, 2, repeating)
call SaveTriggerHandle(GST_Hash, id, 3, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_UnitUnit_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_Unit takes unit u1, boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveUnitHandle(GST_Hash, id, 0, u1)
call SaveBoolean(GST_Hash, id, 1, repeating)
call SaveTriggerHandle(GST_Hash, id, 2, udg_GST_Trigger)
// start timer
call TimerStart(t, interval, repeating, function GST_Unit_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
function GST_Simple takes boolean repeating, real interval returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
// save to hashtable
call SaveTriggerHandle(GST_Hash, id, 0, udg_GST_Trigger)
call SaveBoolean(GST_Hash, id, 1, repeating)
// start timer
call TimerStart(t, interval, repeating, function GST_Simple_Expire)
// check for keys which are used to restart existing timers
if udg_GST_RestartKey >= 0 then
call GST_RestartTimer()
// keep track of the new timer stored at these keys
call SaveTimerHandle(GST_Hash, GST_NewKey, GetHandleId(udg_GST_Trigger), t)
set udg_GST_RestartKey = -1
endif
// clean up memory leaks
set t = null
endfunction
endlibrary