function RestorePossession takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer index = GetHandleId(t)
local unit which = LoadUnitHandle(<hash_var>, index, 2)
call SetUnitOwner(which, Player(LoadInteger(<hash_var>, index, 1), true))
call FlushChildHashtable(<hash_var>, index)
call DestroyTimer(t)
set t = null
set which = null
endfunction
function StartPossession takes unit which, player newOwner, real duration returns nothing
local timer t
if delay <= 0. then
// The duration is instantaneous, so the system guesses that it will be permanent
call SetUnitOwner(which, newOwner, true)
else
// We create a timer to determine when the possession will exactly end.
// By creating a timer, I am insinuating that TriggerSleepActions are generally not recommended in JASS.
set t = CreateTimer()
// We save the following data into our timer.
call SaveInteger(<hash_var>, GetHandleId(t), 1, GetPlayerId(GetOwningPlayer(which)))
call SaveUnitHandle(<hash_var>, GetHandleId(t), 2, which)
// Change Ownership
call SetUnitOwner(which, newOwner, true)
// Start the timer with the specified duration.
call TimerStart(t, duration, false, function RestorePossession)
set t = null
endif
endfunction
function InitTrig_Hashtable_Init takes nothing returns nothing
set <hash_var> = InitHashtable()
endfunction