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
SHRS Variables create

Events

Conditions

Actions


Hashtable - Create a hashtable


Set SHRS_Hashtable = (Last created hashtable)


Set SHRS_N = 0


Set SHRS_Timers[0] = (Last started timer)
Test GUI FRIENDLY

Events


Unit - A unit Dies

Conditions


((Triggering unit) is A Hero) Equal to True

Actions


-------- This is the unit that will be Revived by the system --------


-------- set it to whatever unit you want to --------


-------- that you want the system to revive after set time --------


Set TempUnit = (Triggering unit)


-------- Here we get the location, where the unit will be revived at --------


-------- as we will use the "loc" function --------


-------- also more friendly for GUI users --------


Set TempLoc = (Position of TempUnit)


-------- This variable shouldn't be necessary but just for an example --------


-------- and to help GUI coders --------


-------- This value below will represent the revival time of the hero --------


Set TempReal = 7.00


-------- This variable below will tell the system that it should --------


-------- Show revival animations (birth animation) --------


-------- Set it to true and it will show, set it to false and it wont --------


Set TempEff = True


-------- That was it --------


-------- Now I will call the function below --------


-------- And it will start reviving the unit --------


Custom script: call SHRS_HeroReviveLoc(udg_TempUnit, udg_TempReal, udg_TempLoc, udg_TempEff)


-------- Clear the point leak --------


Custom script: call RemoveLocation(udg_TempLoc)


-------- Just to show in-game that the unit will be revived soon. --------


Game - Display to (All players) the text: ((Proper name of (Triggering unit)) + will be revived in 7 seconds!)