Joker(Div)
Always Here..
- Reaction score
- 86
HeroRevive (HR) System v1.0c
By: Joker(Div)
Requires
Code:
Example:
I was just practicing struct usage and thought I'd release it in case someone found it useful.
Changelog
By: Joker(Div)
Requires
- vJASS
- TimerUtils
Code:
JASS:
library HR uses TimerUtils
//*************************************************************************************************
//* HeroRevive System v1.0c
//* By: Joker(Div)
//*************************************************************************************************
//*
//* Requirements:
//* -------------
//* -vJass (JassHelper/NewGen)
//* -TimerUtils
//*
//* How to Implement:
//* -----------------
//* -Copy the trigger and paste it onto your map
//*
//* What Does it Do:
//* ----------------
//* -Revives your hero after a set time
//*
//* Functions (methods):
//* -----------
//* -Revive.Set takes unit a, real x, real y, boolean eyecandy returns nothing
//* -Revive.SetSelf takes unit a, real x, real y, boolean eyecandy, real duration returns nothing
//*
//* (The difference? .SetSelf lets you use your own delay)
//*
//*************************************************************************************************
globals
private constant real BASE = 5. //Starting interval
private constant real LVL_FACTOR = 1.5 //Increments based on Hero lvl
private constant boolean USE_UNIT_NAME = true //If false, uses the owner's name
private constant boolean PAN_CAMERA = true //Pans the owners camera to the hero when revived
private constant boolean SELECT_HERO = true //Selects the hero when revived for the owner
private constant boolean ROUND_DELAY = false //Timer dialogs show the countdown as an integer. Timers use real timeouts.
endglobals
//-----------
struct Revive
unit a
real x
real y
timer t
timerdialog td
boolean eyecandy
//==============================================================================================
static method Set takes unit a, real x, real y, boolean eyecandy returns nothing
local Revive dat = Revive.create()
local real Lvl = GetHeroLevel(a)*1.
set dat.a = a
set dat.y = y
set dat.x = x
set dat.t = NewTimer() //TimerUtils
set dat.td = CreateTimerDialog(dat.t)
set dat.eyecandy = eyecandy
call SetTimerData(dat.t, dat) //TimerUtils
if ROUND_DELAY then
call TimerStart(dat.t, R2I(BASE+(LVL_FACTOR*Lvl)+0.5), false, function Revive.Callback)
else
call TimerStart(dat.t, BASE+(LVL_FACTOR*Lvl), false, function Revive.Callback)
endif
if USE_UNIT_NAME then
call TimerDialogSetTitle(dat.td, GetUnitName(a))
else
call TimerDialogSetTitle(dat.td, GetPlayerName(GetOwningPlayer(a)))
endif
call TimerDialogDisplay(dat.td, true)
endmethod
static method SetSelf takes unit a, real x, real y, boolean eyecandy, real delay returns nothing
local Revive dat = Revive.create()
local real Lvl = GetHeroLevel(a)*1.
set dat.a = a
set dat.y = y
set dat.x = x
set dat.t = NewTimer() //TimerUtils
set dat.td = CreateTimerDialog(dat.t)
set dat.eyecandy = eyecandy
call SetTimerData(dat.t, dat) //TimerUtils
if ROUND_DELAY then
call TimerStart(dat.t, R2I(delay+0.5), false, function Revive.Callback)
else
call TimerStart(dat.t, delay, false, function Revive.Callback)
endif
if USE_UNIT_NAME then
call TimerDialogSetTitle(dat.td, GetUnitName(a))
else
call TimerDialogSetTitle(dat.td, GetPlayerName(GetOwningPlayer(a)))
endif
call TimerDialogDisplay(dat.td, true)
endmethod
//==============================================================================================
private static method Callback takes nothing returns nothing
local Revive dat = GetTimerData(GetExpiredTimer()) //TimerUtils
call ReviveHero(dat.a, dat.x, dat.y, dat.eyecandy)
if PAN_CAMERA and GetLocalPlayer() == GetOwningPlayer(dat.a) then
call PanCameraToTimed(dat.x, dat.y, 0)
endif
if SELECT_HERO and GetLocalPlayer() == GetOwningPlayer(dat.a) then
call SelectUnit(dat.a, true)
endif
call dat.destroy()
endmethod
//==============================================================================================
method onDestroy takes nothing returns nothing
call ReleaseTimer(.t)
call DestroyTimerDialog(.td)
endmethod
endstruct
//*************************************************************************************************
//* End of HeroRevive System
//*************************************************************************************************
endlibrary
Example:
JASS:
scope Example initializer Init
//==========================================================================
private function Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true
endfunction
//==========================================================================
private function Actions takes nothing returns nothing
local unit a = GetDyingUnit()
local real x = GetUnitX(a)
local real y = GetUnitY(a)
call Revive.Set(a, x, y, true)
//call Revive.SetSelf(a, x, y, true, 1.)
set a = null
endfunction
//==========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
endfunction
endscope
I was just practicing struct usage and thought I'd release it in case someone found it useful.
Changelog
Code:
Changelog:
<1.0c> (9/26/08)
-No longer need to create instance
<1.0b> (9/25/08)
-Added a ROUND_DELAY boolean
-Made the .Callback method private