Moderator
M
Moderator
11:24, 28th Feb 2011
Bribe:
A simple utility which could prove useful for GUI users.
Bribe:
A simple utility which could prove useful for GUI users.
function SHRS_Revive takes nothing returns nothing
local integer id = GetHandleId(GetExpiredTimer()) //just for simpleness and no indexing
//recycle the timer
set udg_SHRS_Timers[udg_SHRS_N] = GetExpiredTimer()
set udg_SHRS_N = udg_SHRS_N + 1
//revive
call ReviveHero(LoadUnitHandle(udg_SHRS_Hashtable, id, 1), LoadReal(udg_SHRS_Hashtable, id, 2), LoadReal(udg_SHRS_Hashtable, id, 3), LoadBoolean(udg_SHRS_Hashtable, id, 4))
//flush the child keys of the id
call FlushChildHashtable(udg_SHRS_Hashtable, id)
endfunction
function HeroRevive takes unit hero, real time, real x, real y, boolean eff returns nothing
local timer t
local integer id
//the if below is just to protect the users from making mistakes
if IsUnitType(hero, UNIT_TYPE_HERO) and IsUnitType(hero, UNIT_TYPE_DEAD) and GetUnitTypeId(hero) != 0 then
// Simple timer recycling
if (udg_SHRS_N == 0) then
set t = CreateTimer()
else
set udg_SHRS_N = udg_SHRS_N - 1
set t = udg_SHRS_Timers[udg_SHRS_N]
endif
set id = GetHandleId(t)
// store unit
call SaveUnitHandle(udg_SHRS_Hashtable, id, 1, hero)
// store x coordinate
call SaveReal(udg_SHRS_Hashtable, id, 2, x)
// store y coordinate
call SaveReal(udg_SHRS_Hashtable, id, 3, y)
// store the boolean
call SaveBoolean(udg_SHRS_Hashtable, id, 4, eff)
// fire the timer
call TimerStart(t, time, false, function SHRS_Revive)
set t = null
debug else
// just a simple error message for those who don't understand the words dead and hero
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "SHRS Error - The unit is either not dead or is not a hero")
endif
endfunction
// A location-wrapper for the above function
function HeroReviveLoc takes unit hero, real time, location loc, boolean eff returns nothing
call HeroRevive(hero, time, GetLocationX(loc), GetLocationY(loc), eff)
endfunction