library HeroRevival requires TimerUtils
//*******************************************************************************************************************************
//
// This is just a simple hero revival
// by baassee
// Credits is appreciated
// and please credit Bribe too for his brilliant remake.
//
// *Requires:
// TimerUtils by Vexorian
// A vJass Compiler
//
//
// Credits flies out to:
// Axarion for showing me his scope
// Hell Gate and Deaod for their Health Reserve system, taught me alot
// Vexorian for TimerUtils, JassHelper and vJass
// Bribe for recoding the system.
//
// How to use:
// This library provides you with these functions
// function HeroRevive takes unit hero, real time, real x, real y, boolean eff
// function HeroReviveLoc takes unit hero, real time, location loc, boolean eff
//
// The unit hero is obviously the hero you are going to revive.
// The real time is the time you want to revive your hero.
// ps. you can set this to 0 and use the GetTime func to make your formula.
// The real x states which x coordinate where you are going to revive your hero.
// The real y states which y coordinate where you are going to revive your hero.
// The location loc is for those who don't know to use coordinates.
// The boolean eff is for show or not show rebirth effect.
//
// Example 1:
// call HeroRevive(GetTriggerUnit(), 30., 0., 0., true)
//
// If you use this with an event "A Unit Dies" then it will
// Revive the dying unit, revive it after 30 seconds at coord (0,0) showing revival effect
//
// Example 2:
// call HeroRevive(GetTriggerUnit(), 0., GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), false)
//
// If you use this as said above it will
// Revive the dying unit, it will USE the formula function so you better customize it there.
// It will revive where it died and will not show revival effect.
//
// Example 3:
// call HeroReviveLoc(GetTriggerUnit(), 0., udg_TempLoc, true)
//
// If you use this as said above with a location for all GUI users it will
// Revive the dying unit, it will USE the formula function so you better customize it there.
// It will revive the unit at a location you've set
// Just remember to remove the location afterwards!
//
// End of Documentation
//
//***************************************************************************************************************************
//
// SETUP
//
//
globals
//
//*************GUI USERS LOOK BELOW HERE****************************
//
// This variable is where you can set how fast the camera should pan to the revived unit.
// As this usally is set to a low value, lower the greater the size is, you can set it
// to 0. if you want to, then it will be panned instantly.
//
private constant real PANCAM = 0.6
endglobals
private function GetAdjustedTime takes real time, unit hero returns real
return time + 0. * GetHeroLevel(hero)
//if you want something extra or you can set the time to 0
//and use this for a formula instead
//I call this function for the formula func in the documentation
endfunction
private function FilterHero takes unit u returns boolean
return IsUnitType(u, UNIT_TYPE_HERO) and IsUnitType(u, UNIT_TYPE_DEAD)
//just check if the unit is a hero
//and to check if the unit is already dead (thanks to axarion for this one)
//you can edit the filter if you want
endfunction
// END SETUP
//******************************************************************************************************************************
//
globals
//
// To make sure that the users wont run several instances with the same unit
//
private group NOSTACK = CreateGroup()
endglobals
private struct data extends array
static integer i = 0
static integer array r
unit hero
real x
real y
boolean eff
endstruct
private function finish takes nothing returns nothing
local timer t = GetExpiredTimer()
local data dat = GetTimerData(t)
call ReleaseTimer(t) //recycle timer
set t = null
call ReviveHero(dat.hero, dat.x, dat.y, dat.eff) //revive hero
call GroupRemoveUnit(NOSTACK, dat.hero)
if GetLocalPlayer() == GetOwningPlayer(dat.hero) then
call PanCameraToTimed(dat.x, dat.y, PANCAM)
call ClearSelection()
call SelectUnit(dat.hero, true)
endif
set data.r[0] = data.r[data.r[0]]
set data.r[data.r[0]] = dat
endfunction
function HeroRevive takes unit hero, real time, real x, real y, boolean eff returns nothing
local data dat
local timer t
if FilterHero(hero) and not IsUnitInGroup(hero, NOSTACK) then
if 0 == data.r[0] then
set data.i = data.i + 1
set dat = data.i
else
set dat = data.r[0]
set data.r[0] = data.r[data.r[0]]
endif
set t = NewTimer()
set dat.hero = hero
set dat.x = x
set dat.y = y
set dat.eff = eff
call GroupAddUnit(NOSTACK, hero)
call SetTimerData(t, dat)
call TimerStart(t, GetAdjustedTime(time, hero), false, function finish)
set t = null
debug else
debug call BJDebugMsg("HeroRevival Error: The unit is either alive or isn't a hero unit or is already in the system, please check your trigger calls.")
endif
endfunction
function HeroReviveLoc takes unit hero, real time, location loc, boolean eff returns nothing
call HeroRevive(hero, time, GetLocationX(loc), GetLocationY(loc), eff)
endfunction
endlibrary