globals
hashtable ht
endglobals
struct Revive
player p
integer id
real x
real y
real a
endstruct
function unitDeath takes nothing returns nothing
local Revive r = Revive.create()
local unit u = GetTriggerUnit()
local timer t = CreateTimer()
set r.p = GetOwningPlayer(u)
set r.id = GetUnitTypeId(u)
set r.x = GetUnitX(u)
set r.y = GetUnitY(u)
set r.a = GetUnitFacing(u)
call SaveInteger(ht, GetHandleId(t), 1, r)
call TimerStart(t, 20, false, function reviveUnit)
endfunction
function reviveUnit takes nothing returns nothing
local timer t = GetExpiredTimer()
local int hid = GetHandleId(t)
local Revive r = LoadInteger(ht, hid, 1)
call CreateUnit(r.p, r.id, r.x, r.y, r.a)
call FlushChildHashtable(ht, hid)
call DestroyTimer(t) // with TimerUtils: ReleaseTimer(t)
endfunction
function InitTrig_Revive takes nothing returns nothing
set ht = InitHashtable()
set gg_trg_Revive=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Revive,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(gg_trg_Revive,function unitDeath)
endfunction