Name | Type | is_array | initial_value |
d | destructable | No | |
time | real | No |
//TESH.scrollpos=12
//TESH.alwaysfold=0
library Event
//2.0.0.1
/////////////////////////////////////////////////////////////////////////
//function CreateEvent takes nothing returns integer
//function TriggerRegisterEvent takes trigger t, integer ev returns nothing
//function RegisterEvent takes boolexpr c, integer ev returns nothing
//function FireEvent takes integer ev returns nothing
//struct Event extends array
//static method create takes nothing returns thistype
//method registerTrigger takes trigger t returns nothing
//method register takes boolexpr c returns nothing
//method fire takes nothing returns nothing
/////////////////////////////////////////////////////////////////////////
globals
private real q=0
endglobals
struct Event extends array
private static integer w=0
private static trigger array e
static method create takes nothing returns thistype
set w=w+1
set e[w]=CreateTrigger()
return w
endmethod
method registerTrigger takes trigger t returns nothing
call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod
method register takes boolexpr c returns nothing
call TriggerAddCondition(e[this],c)
endmethod
method fire takes nothing returns nothing
set q=0
set q=this
call TriggerEvaluate(e[this])
endmethod
endstruct
function CreateEvent takes nothing returns Event
return Event.create()
endfunction
function TriggerRegisterEvent takes trigger t,Event ev returns nothing
call ev.registerTrigger(t)
endfunction
function RegisterEvent takes boolexpr c,Event ev returns nothing
call ev.register(c)
endfunction
function FireEvent takes Event ev returns nothing
call ev.fire()
endfunction
endlibrary
//TESH.scrollpos=27
//TESH.alwaysfold=0
library TimerUtilsEx requires optional Table
/*************************************************
*
* TimerUtilsEx
* v2.1.0.2
* By Vexorian, Bribe & Magtheridon96
*
* Original version by Vexorian.
*
* Flavors:
* Hashtable:
* - RAM: Minimal
* - TimerData: Slow
*
* Array:
* - RAM: Maximal
* - TimerData: Fast
*
* All the functions have O(1) complexity.
* The Array version is the fastest, but the hashtable
* version is the safest. The Array version is still
* quite safe though, and I would recommend using it.
* The system is much slower in debug mode.
*
* Optional Requirement:
* - Table by Bribe
* - hiveworkshop.com/forums/showthread.php?t=188084
*
* API:
* ----
* - function NewTimer takes nothing returns timer
* - Returns a new timer from the stack.
* - function NewTimerEx takes integer i returns timer
* - Returns a new timer from the stack and attaches a value to it.
* - function ReleaseTimer takes timer t returns integer
* - Throws a timer back into the stack. Also returns timer data.
* - function SetTimerData takes timer t, integer value returns nothing
* - Attaches a value to a timer.
* - function GetTimerData takes timer t returns integer
* - Returns the attached value.
*
*************************************************/
// Configuration
globals
// Use hashtable, or fast array?
private constant boolean USE_HASH = false
// Max Number of Timers Held in Stack
private constant integer QUANTITY = 256
endglobals
globals
private timer array tT
private integer tN = 0
endglobals
private module Init
private static method onInit takes nothing returns nothing
static if not USE_HASH then
local integer i = QUANTITY
loop
set i = i - 1
set tT[i] = CreateTimer()
exitwhen i == 0
endloop
set tN = QUANTITY
elseif LIBRARY_Table then
set tb = Table.create()
endif
endmethod
endmodule
// JassHelper doesn't support static ifs for globals.
private struct Data extends array
static if not USE_HASH then
static integer array data
endif
static if LIBRARY_Table then
static Table tb = 0
else
static hashtable ht = InitHashtable()
endif
implement Init
endstruct
// Double free protection
private function ValidTimer takes integer i returns boolean
static if LIBRARY_Table then
return Data.tb.boolean[-i]
else
return LoadBoolean(Data.ht, i, 1)
endif
endfunction
private function Get takes integer id returns integer
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to get data from invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
return Data.tb[id]
else
return LoadInteger(Data.ht, id, 0)
endif
else
return Data.data[id - 0x100000]
endif
endfunction
private function Set takes integer id, integer data returns nothing
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to attach data to invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
set Data.tb[id] = data
else
call SaveInteger(Data.ht, id, 0, data)
endif
else
set Data.data[id - 0x100000] = data
endif
endfunction
function SetTimerData takes timer t, integer data returns nothing
call Set(GetHandleId(t), data)
endfunction
function GetTimerData takes timer t returns integer
return Get(GetHandleId(t))
endfunction
function NewTimerEx takes integer data returns timer
local integer id
if tN == 0 then
static if USE_HASH then
set tT[0] = CreateTimer()
else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: No Timers In The Stack! You must increase 'QUANTITY'")
return null
endif
else
set tN = tN - 1
endif
set id = GetHandleId(tT[tN])
static if LIBRARY_Table then
set Data.tb.boolean[-id] = true
else
call SaveBoolean(Data.ht, id, 1, true)
endif
call Set(id, data)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
function ReleaseTimer takes timer t returns integer
local integer id = GetHandleId(t)
local integer data = 0
// Pause the timer just in case.
call PauseTimer(t)
// Make sure the timer is valid.
if ValidTimer(id) then
// Get the timer's data.
set data = Get(id)
// Unmark handle id as a valid timer.
static if LIBRARY_Table then
call Data.tb.boolean.remove(-id)
else
call RemoveSavedBoolean(Data.ht, id, 1)
endif
//If it's not run in USE_HASH mode, this next block is useless.
static if USE_HASH then
//At least clear hash memory while it's in the recycle stack.
static if LIBRARY_Table then
call Data.tb.remove(id)
else
call RemoveSavedInteger(Data.ht, id, 0)
endif
// If the recycle limit is reached
if tN == QUANTITY then
// then we destroy the timer.
call DestroyTimer(t)
return data
endif
endif
//Recycle the timer.
set tT[tN] = t
set tN = tN + 1
//Tried to pass a bad timer.
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to release non-active timer!")
endif
//Return Timer Data.
return data
endfunction
endlibrary
library TimerUtils requires TimerUtilsEx
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library UnitIndexer /* v4.0.2.8
*************************************************************************************
*
* Assigns unique indexes to units via unit user data.
*
*************************************************************************************
*
* */uses/*
*
* */ WorldBounds /* hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
* */ Event /* hiveworkshop.com/forums/submissions-414/snippet-event-186555/
*
************************************************************************************
*
* Functions
*
* function RegisterUnitIndexEvent takes boolexpr codeToRegister, Event unitIndexEvent returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger triggerToRegister, Event unitIndexEvent returns nothing
*
* function GetUnitById takes integer index returns unit
* - Returns unit given a unit index
* function GetUnitId takes unit u returns integer
* - Returns unit index given a unit
*
* function IsUnitIndexed takes unit u returns boolean
* function IsUnitDeindexing takes unit u returns boolean
*
* function GetIndexedUnitId takes nothing returns integer
* function GetIndexedUnit takes nothing returns unit
*
************************************************************************************
*
* module UnitIndexStructMethods
* static method operator [] takes unit u returns thistype
* - Return GetUnitUserData(u)
*
* readonly unit unit
* - The indexed unit of the struct
*
************************************************************************************
*
* module UnitIndexStruct extends UnitIndexStructMethods
*
* - A pseudo module interface that runs a set of methods if they exist and provides
* - a few fields and operators. Runs on static ifs to minimize code.
*
* readonly boolean allocated
* - Is unit allocated for the struct
*
* Interface:
*
* - These methods don't have to exist. If they don't exist, the code
* - that calls them won't even be in the module.
*
* private method index takes nothing returns nothing
* - called when a unit is indexed and passes the filter.
* -
* - thistype this: Unit's index
* private method deindex takes nothing returns nothing
* - called when a unit is deindexed and is allocated for struct
* -
* - thistype this: Unit's index
* private static method filter takes unit unitToIndex returns boolean
* - Determines whether or not to allocate struct for unit
* -
* - unit unitToIndex: Unit being filtered
*
************************************************************************************
*
* struct UnitIndexer extends array
*
* - Controls the unit indexer system.
*
* static constant Event UnitIndexer.INDEX
* static constant Event UnitIndexer.DEINDEX
* - Don't register functions and triggers directly to the events. Register them via
* - RegisterUnitIndexEvent and TriggerRegisterUnitIndexEvent.
*
* static boolean enabled
* - Enables and disables unit indexing. Useful for filtering out dummy units.
*
************************************************************************************
*
* struct UnitIndex extends UnitIndexStructMethods
*
* - Constrols specific unit indexes.
*
* method lock takes nothing returns nothing
* - Locks an index. When an index is locked, it will not be recycled
* - when the unit is deindexed until all locks are removed. Deindex
* - events still fire at the appropriate times, the index just doesn't
* - get thrown into the recycler.
* method unlock takes nothing returns nothing
* - Unlocks an index.
*
************************************************************************************/
globals
private constant integer ABILITIES_UNIT_INDEXER = 'A001'
private trigger q=CreateTrigger()
private trigger l=CreateTrigger()
private unit array e
private integer r=0
private integer y=0
private integer o=0
private boolean a=false
private integer array n
private integer array p
private integer array lc
endglobals
function GetIndexedUnitId takes nothing returns integer
return o
endfunction
function GetIndexedUnit takes nothing returns unit
return e[o]
endfunction
//! runtextmacro optional UNIT_LIST_LIB()
private struct PreLoader extends array
public static method run takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
set a=true
endmethod
public static method eval takes trigger t returns nothing
local integer f=n[0]
local integer d=o
loop
exitwhen 0==f
if (IsTriggerEnabled(t)) then
set o=f
if (TriggerEvaluate(t)) then
call TriggerExecute(t)
endif
else
exitwhen true
endif
set f=n[f]
endloop
set o=d
endmethod
public static method evalb takes boolexpr c returns nothing
local trigger t=CreateTrigger()
local thistype f=n[0]
local integer d=o
call TriggerAddCondition(t,c)
loop
exitwhen 0==f
set o=f
call TriggerEvaluate(t)
set f=n[f]
endloop
call DestroyTrigger(t)
set t=null
set o=d
endmethod
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO()
private module UnitIndexerInit
private static method onInit takes nothing returns nothing
local integer i=15
local boolexpr bc=Condition(function thistype.onLeave)
local boolexpr bc2=Condition(function thistype.onEnter)
local group g=CreateGroup()
local player p
set INDEX=CreateEvent()
set DEINDEX=CreateEvent()
call TriggerRegisterEnterRegion(q,WorldBounds.worldRegion,bc2)
loop
set p=Player(i)
call TriggerRegisterPlayerUnitEvent(l,p,EVENT_PLAYER_UNIT_ISSUED_ORDER,bc)
call SetPlayerAbilityAvailable(p,ABILITIES_UNIT_INDEXER,false)
call GroupEnumUnitsOfPlayer(g,p,bc2)
exitwhen 0==i
set i=i-1
endloop
call DestroyGroup(g)
set bc=null
set g=null
set bc2=null
set p=null
call TimerStart(CreateTimer(),0,false,function PreLoader.run)
endmethod
endmodule
struct UnitIndex extends array
method lock takes nothing returns nothing
debug if (null!=e[this]) then
set lc[this]=lc[this]+1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO LOCK NULL INDEX")
debug endif
endmethod
method unlock takes nothing returns nothing
debug if (0<lc[this]) then
set lc[this]=lc[this]-1
if (0==lc[this] and null==e[this]) then
set n[this]=y
set y=this
endif
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO UNLOCK UNLOCKED INDEX")
debug endif
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
static method operator [] takes unit whichUnit returns thistype
return GetUnitUserData(whichUnit)
endmethod
endstruct
struct UnitIndexer extends array
readonly static Event INDEX
readonly static Event DEINDEX
static method operator enabled takes nothing returns boolean
return IsTriggerEnabled(q)
endmethod
static method operator enabled= takes boolean b returns nothing
if (b) then
call DisableTrigger(q)
call DisableTrigger(l)
else
call EnableTrigger(q)
call EnableTrigger(l)
endif
endmethod
private static method onEnter takes nothing returns boolean
local unit Q=GetFilterUnit()
local integer i
local integer d=o
if (Q!=e[GetUnitUserData(Q)] and 0==GetUnitUserData(Q)) then
if (0==y) then
set r=r+1
set i=r
else
set i=y
set y=n[y]
endif
call UnitAddAbility(Q,ABILITIES_UNIT_INDEXER)
call UnitMakeAbilityPermanent(Q,true,ABILITIES_UNIT_INDEXER)
call SetUnitUserData(Q,i)
set e[i]=Q
static if not LIBRARY_UnitList then
if (not a)then
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
endif
else
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
call GroupAddUnit(g,e[i])
endif
set o=i
call FireEvent(INDEX)
set o=d
endif
set Q=null
return false
endmethod
private static method onLeave takes nothing returns boolean
static if LIBRARY_UnitEvent then
implement optional UnitEventModule
else
local unit u=GetFilterUnit()
local integer i=GetUnitUserData(u)
local integer d=o
if (0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER) and u==e[i]) then
static if not LIBRARY_UnitList then
if (not a)then
set n[p[i]]=n[i]
set p[n[i]]=p[i]
endif
else
set n[p[i]]=n[i]
set p[n[i]]=p[i]
call GroupRemoveUnit(g,e[i])
endif
set o=i
call FireEvent(DEINDEX)
set o=d
if (0==lc[i]) then
set n[i]=y
set y=i
endif
set e[i]=null
endif
set u=null
endif
return false
endmethod
implement UnitIndexerInit
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO_2()
function RegisterUnitIndexEvent takes boolexpr c,integer ev returns nothing
call RegisterEvent(c, ev)
if (not a and ev==UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.evalb(c)
endif
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t,integer ev returns nothing
call TriggerRegisterEvent(t,ev)
if (not a and ev == UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.eval(t)
endif
endfunction
function GetUnitById takes integer W returns unit
return e[W]
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function IsUnitIndexed takes unit u returns boolean
return u==e[GetUnitUserData(u)]
endfunction
function IsUnitDeindexing takes unit u returns boolean
return IsUnitIndexed(u) and 0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER)
endfunction
module UnitIndexStructMethods
static method operator [] takes unit u returns thistype
return GetUnitUserData(u)
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
endmodule
module UnitIndexStruct
implement UnitIndexStructMethods
static if thistype.filter.exists then
static if thistype.index.exists then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
elseif (thistype.index.exists) then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
static if thistype.index.exists then
private static method onIndexEvent takes nothing returns boolean
static if thistype.filter.exists then
if (filter(e[o])) then
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
else
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
return false
endmethod
endif
static if thistype.deindex.exists then
private static method onDeindexEvent takes nothing returns boolean
static if thistype.filter.exists then
static if thistype.index.exists then
if (thistype(o).allocated) then
set thistype(o).allocated=false
call thistype(o).deindex()
endif
else
if (filter(e[o])) then
call thistype(o).deindex()
endif
endif
else
static if thistype.index.exists then
set thistype(o).allocated=false
endif
call thistype(o).deindex()
endif
return false
endmethod
endif
static if thistype.index.exists then
static if thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
else
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
endmethod
endif
elseif thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
endif
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library WorldBounds /* v2.0.0.0
************************************************************************************
*
* struct WorldBounds extends array
*
* Fields
* -------------------------
*
* readonly static integer maxX
* readonly static integer maxY
* readonly static integer minX
* readonly static integer minY
*
* readonly static integer centerX
* readonly static integer centerY
*
* readonly static rect world
* readonly static region worldRegion
*
************************************************************************************/
private module WorldBoundInit
private static method onInit takes nothing returns nothing
set world=GetWorldBounds()
set maxX = R2I(GetRectMaxX(world))
set maxY = R2I(GetRectMaxY(world))
set minX = R2I(GetRectMinX(world))
set minY = R2I(GetRectMinY(world))
set centerX = R2I((maxX + minX)/2)
set centerY = R2I((minY + maxY)/2)
set worldRegion = CreateRegion()
call RegionAddRect(worldRegion, world)
endmethod
endmodule
struct WorldBounds extends array
readonly static integer maxX
readonly static integer maxY
readonly static integer minX
readonly static integer minY
readonly static integer centerX
readonly static integer centerY
readonly static rect world
readonly static region worldRegion
implement WorldBoundInit
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ReviveEvent/*
**************************************************************************************************
*
* **********************************************************************************************
*
* */ uses /*
* */ TimerUtilsEx /* hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/
* */ WorldBounds /* github.com/nestharus/JASS/blob/master/jass/Systems/WorldBounds/script.j
* */ UnitIndexer /* old version (v4.0.2.8)
* */ optional ReTimerdialog /*
* */ optional ReLeaderboard /*
*
* **********************************************************************************************
*
* ReviveEvent
* ___________
* v2.1.2.2
* by Thelordmarshall
*
* You can:
* ________
*
* - Revive units.
* - Use custom fx on revived units.
* - See the cooldown in timerdialog or leaderboard.
* - Detect when hero/unit is revived.
*
* API:
* ____
*
* struct Revive extends array:
* - method execute takes nothing returns boolean
* - method getCooldown takes nothing returns real
*
* method operator:
* - method operator onX= takes real x returns nothing
* - method operator onY= takes real y returns nothing
* - method operator awakenFx= takes string fx returns nothing
* - method operator cooldown= takes real cooldown returns nothing
* - method operator select= takes boolean select returns nothing
* - instantly select unit on revive.
* - method operator showTd= takes boolean show returns nothing
* - show Timerdialog.
* - method operator showLd= takes boolean show returns nothing
* - show Leaderboard.
* - method operator simpleLd= takes boolean simple returns nothing
* - when is enabled only show the timer of player units in the leaderboard
* and not the timer of the other players units.
*
* Functions:
* __________
*
* - function ReviveUnit takes unit whichUnit, real x, real y, string fx returns nothing
* - function GetLastRevivedUnit takes nothing returns unit
* - function IsUnitDead takes unit whichUnit returns boolean
* - function ReviveGetCooldown takes unit whichUnit returns real
* - function SetReviveUnitAutomatic takes unit whichUnit, real x, real y, string fx, real cd, boolean upCd, boolean select returns nothing
* - function ReviveUnitReset takes unit whichUnit returns nothing
* - function RegisterReviveEvent takes code c returns nothing
*
* Credits:
* ________
*
* - Nestharus: UnitIndexer, WorldBounds.
* - Vexorian, Bribe & Magtheridon96: TimerUtils.
* - Special thanks to Bannar, IcemanBo and BPower.
**************************************************************************************************/
//CONFIGURATION
//=====================================================================================
globals
// Public awaken fx
constant string DEFAULT_AWAKEN_FX = "Abilities\\Spells\\Other\\Awaken\\Awaken.mdl"
endglobals
// Cooldown for each lvl
private function CooldownFactor takes real base, integer lvl returns real
return base/*cooldown base*/+ 4.00/*cooldown per lvl*/*I2R(lvl)/*lvl of unit*/
endfunction
//=====================================================================================
//ENDCONFIGURATION
globals
private trigger r=CreateTrigger()
private trigger t=CreateTrigger()
private trigger o=CreateTrigger()
private trigger p=CreateTrigger()
unit re_lastRevivedUnit=null
endglobals
//Core.
struct Revive extends array
private unit u
private real x
private real y
private real c
private real l
private string f
private boolean re_upCooldown
private boolean re_instSelect
implement optional re_Timerdialog
implement optional re_Leaderboard
static method operator [] takes unit u returns thistype
local thistype this=GetUnitId(u)
set .u=u
return this
endmethod
method getCooldown takes nothing returns real
return .l
endmethod
private static method hook_removeUnit takes unit u returns nothing
set thistype(GetUnitId(u)).u=null
endmethod
private method selectUnit takes nothing returns nothing
if(.re_instSelect and GetLocalPlayer()==GetOwningPlayer(.u))then
call PanCameraToTimed(.x,.y,0.)
call ClearSelection()
call SelectUnit(re_lastRevivedUnit,true)
endif
endmethod
private method addAwaken takes nothing returns nothing
if(.f!=null or .f!="")then
call DestroyEffect(AddSpecialEffectTarget(.f,.u,"origin"))
endif
endmethod
method execute takes nothing returns boolean
local player p=GetOwningPlayer(.u)
local thistype newId=GetUnitTypeId(.u)
local boolean done
if(IsUnitType(.u,UNIT_TYPE_DEAD) and not (newId==0))then
if(IsUnitType(.u,UNIT_TYPE_HERO))then
set done=ReviveHero(.u,.x,.y,false)
if(done)then
call .addAwaken()
call .selectUnit()
endif
return done
else
set re_lastRevivedUnit=CreateUnit(p,newId,0.,0.,0.)
set newId=GetUnitId(re_lastRevivedUnit)
set newId.u=re_lastRevivedUnit
set newId.f=.f
set newId.x=.x
set newId.y=.y
set newId.c=.c
set newId.re_upCooldown=.re_upCooldown
set newId.re_instSelect=.re_instSelect
static if(LIBRARY_ReTimerdialog)then
set newId.re_showDialog=.re_showDialog
endif
static if(LIBRARY_ReLeaderboard)then
set newId.re_showBoard=.re_showBoard
set newId.re_simpleBoard=.re_simpleBoard
endif
call RemoveUnit(.u)
call SetUnitX(re_lastRevivedUnit,newId.x)
call SetUnitY(re_lastRevivedUnit,newId.y)
call newId.addAwaken()
call newId.selectUnit()
call TriggerEvaluate(r)
set .u=null
return true
endif
endif
return false
endmethod
private static method onDeathLoop takes nothing returns nothing
local timer t=GetExpiredTimer()
local thistype this=GetTimerData(t)
set .l=.l-.03125
if(.l<=0. or not IsUnitType(.u,UNIT_TYPE_DEAD))then
call .execute()
call ReleaseTimer(t)
endif
set t=null
endmethod
private static method onDeath takes nothing returns boolean
local unit u=GetTriggerUnit()
local thistype this=GetUnitId(u)
if(.c>0.)then
if(.re_upCooldown and IsUnitType(u,UNIT_TYPE_HERO))then
set .l=CooldownFactor(.c,GetUnitLevel(u))
else
set .l=.c
endif
static if(LIBRARY_ReTimerdialog)then
if(.re_showDialog)then
call .startDialog(.l)
endif
endif
static if(LIBRARY_ReLeaderboard)then
if(.re_showBoard)then
call .startBoard(.l)
endif
endif
call TimerStart(NewTimerEx(this),.03125,true,function thistype.onDeathLoop)
endif
set u=null
return false
endmethod
private static method runEvent takes nothing returns boolean
set re_lastRevivedUnit=GetTriggerUnit()
return TriggerEvaluate(r)
endmethod
private static method onEnter takes nothing returns boolean
call TriggerRegisterUnitStateEvent(p,GetTriggerUnit(),UNIT_STATE_LIFE,GREATER_THAN,.405)
return false
endmethod
//! textmacro re_Operator takes NAME,VAR_TYPE,VAR_NAME
method operator $NAME$= takes $VAR_TYPE$ v returns nothing
set .$VAR_NAME$=v
endmethod
//! endtextmacro
//! runtextmacro re_Operator("onX","real","x")
//! runtextmacro re_Operator("onY","real","y")
//! runtextmacro re_Operator("awakenFx","string","f")
//! runtextmacro re_Operator("cooldown","real","c")
//! runtextmacro re_Operator("upCooldown","boolean","re_upCooldown")
//! runtextmacro re_Operator("select","boolean","re_instSelect")
//! runtextmacro optional re_td_Operator("showTd","boolean","re_showDialog")
//! runtextmacro optional re_lb_Operator("showLd","boolean","re_showBoard")
//! runtextmacro optional re_lb_Operator("simpleLd","boolean","re_simpleBoard")
private static method onInit takes nothing returns nothing
local group g=CreateGroup()
local unit u
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t,function thistype.onDeath)
call TriggerRegisterEnterRegion(o,WorldBounds.worldRegion,null)
call TriggerAddCondition(o,function thistype.onEnter)
call GroupEnumUnitsInRect(g,WorldBounds.world,null)
loop
set u=FirstOfGroup(g)
exitwhen(u==null)
call GroupRemoveUnit(g,u)
call TriggerRegisterUnitStateEvent(p,u,UNIT_STATE_LIFE,GREATER_THAN,.405)
endloop
call TriggerAddCondition(p,function thistype.runEvent)
call DestroyGroup(g)
set g=null
endmethod
endstruct
hook RemoveUnit Revive.hook_removeUnit
function ReviveUnit takes unit whichUnit, real x, real y, string fx returns boolean
set Revive[whichUnit].onX=x
set Revive[whichUnit].onY=y
set Revive[whichUnit].awakenFx=fx
return Revive[whichUnit].execute()
endfunction
function GetLastRevivedUnit takes nothing returns unit
return re_lastRevivedUnit
endfunction
function IsUnitDead takes unit whichUnit returns boolean
return IsUnitType(whichUnit,UNIT_TYPE_DEAD)
endfunction
function ReviveGetCooldown takes unit whichUnit returns real
return Revive[whichUnit].getCooldown()
endfunction
function SetReviveUnitAutomatic takes unit whichUnit, real x, real y, string fx, real cd, boolean upCd, boolean select returns nothing
set Revive[whichUnit].onX=x
set Revive[whichUnit].onY=y
set Revive[whichUnit].awakenFx=fx
set Revive[whichUnit].cooldown=cd
set Revive[whichUnit].upCooldown=upCd
set Revive[whichUnit].select=select
endfunction
function ReviveUnitReset takes unit whichUnit returns nothing
if(not(Revive[whichUnit].getCooldown()>0.))then
set Revive[whichUnit].onX=0.
set Revive[whichUnit].onY=0.
set Revive[whichUnit].awakenFx=DEFAULT_AWAKEN_FX
set Revive[whichUnit].cooldown=0.
static if LIBRARY_ReTimerdialog then
set Revive[whichUnit].showTd=false
endif
static if LIBRARY_ReLeaderboard then
set Revive[whichUnit].showLd=false
endif
endif
endfunction
function RegisterReviveEvent takes code c returns nothing
call TriggerAddCondition(r,Filter(c))
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ReTimerdialog
module re_Timerdialog
private static constant string TIMER_TITLE = "Respawn in"
private static constant integer TD_RED = 0 //Timerdialog red
private static constant integer TD_GREEN = 255 //Timerdialog green
private static constant integer TD_BLUE = 0 //Timerdialog blue
private timerdialog td
boolean re_showDialog
private static method endDialog takes nothing returns nothing
local timer t=GetExpiredTimer()
local thistype this=GetTimerData(t)
call DestroyTimerDialog(.td)
call ReleaseTimer(t)
endmethod
method startDialog takes real c returns nothing
local timer t=NewTimerEx(this)
set .td=CreateTimerDialog(t)
call TimerDialogDisplay(.td,GetLocalPlayer()==GetOwningPlayer(.u))
call TimerDialogSetTitle(.td,TIMER_TITLE)
call TimerDialogSetTitleColor(.td,TD_RED,TD_GREEN,TD_BLUE,0)
call TimerStart(t,c,false,function thistype.endDialog)
set t=null
endmethod
//! textmacro re_td_Operator takes NAME,VAR_TYPE,VAR_NAME
method operator $NAME$= takes $VAR_TYPE$ v returns nothing
set .$VAR_NAME$=v
endmethod
//! endtextmacro
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ReLeaderboard
module re_Leaderboard
private static constant string TITLE = "Respawn in"
private static constant string PLAYERS_TITLE = "Players respawn in:"
private static constant string TITLE_PREFIX = "seconds"
private static integer boardsInUse=0
private leaderboard ld
private real d
private thistype h
private boolean isShow
boolean re_showBoard
boolean re_simpleBoard
private method endBoard takes nothing returns nothing
local thistype i=0
local player p=Player(this)
set boardsInUse=boardsInUse-1
set .isShow=false
if not .h.re_simpleBoard then
loop
exitwhen i==bj_MAX_PLAYERS
call LeaderboardRemovePlayerItem(i.ld,p)
if boardsInUse==0 then
call LeaderboardSetLabel(i.ld,PLAYERS_TITLE)
call LeaderboardResizeBJ(i.ld)
call LeaderboardDisplay(i.ld,false)
else
call LeaderboardSetLabel(.ld,PLAYERS_TITLE)
call LeaderboardResizeBJ(i.ld)
endif
set i=i+1
endloop
else
call LeaderboardDisplay(.ld,false)
call LeaderboardSetLabel(.ld,TITLE)
call LeaderboardResizeBJ(.ld)
endif
endmethod
private static method updateBoard takes nothing returns nothing
local timer t=GetExpiredTimer()
local thistype this=GetTimerData(t)
local thistype i=0
set .d=.d-.03125
loop
exitwhen i==bj_MAX_PLAYERS
call LeaderboardSetItemValue(i.ld,LeaderboardGetPlayerIndex(i.ld,Player(this)),R2I(.d))
set i=i+1
endloop
call LeaderboardSetLabel(.ld,TITLE+" "+I2S(R2I(.d))+" "+TITLE_PREFIX)
if(.d<=0. or not IsUnitType(.h.u,UNIT_TYPE_DEAD))then
call .endBoard()
call ReleaseTimer(t)
endif
set t=null
endmethod
method startBoard takes real d returns nothing
local player p=GetOwningPlayer(.u)
local thistype id=GetPlayerId(p)
local thistype i=0
if not id.isShow then
set id.d=d
set id.h=this
set id.isShow=true
if not .re_simpleBoard then
loop
exitwhen i==bj_MAX_PLAYERS
if not LeaderboardHasPlayerItem(i.ld,p) then
call LeaderboardAddItem(i.ld,GetPlayerName(p),R2I(d),p)
endif
if boardsInUse==0 then
call LeaderboardSetLabel(i.ld,PLAYERS_TITLE)
endif
call LeaderboardResizeBJ(i.ld)
call LeaderboardDisplay(i.ld,true)
set i=i+1
endloop
else
call LeaderboardDisplay(id.ld,true)
endif
if LeaderboardHasPlayerItem(id.ld,p) then
call LeaderboardRemovePlayerItem(id.ld,p)
call LeaderboardResizeBJ(id.ld)
endif
set boardsInUse=boardsInUse+1
call TimerStart(NewTimerEx(id),.03125,true,function thistype.updateBoard)
endif
endmethod
private static method onInit takes nothing returns nothing
local thistype i=0
local player p
loop
exitwhen i==bj_MAX_PLAYERS
set p=Player(i)
if (GetPlayerController(p)==MAP_CONTROL_USER and GetPlayerSlotState(p)==PLAYER_SLOT_STATE_PLAYING) then
set i.ld=CreateLeaderboard()
call PlayerSetLeaderboard(p,i.ld)
call LeaderboardSetLabel(i.ld,TITLE)
call LeaderboardDisplay(i.ld,false)
endif
set i=i+1
endloop
endmethod
//! textmacro re_lb_Operator takes NAME,VAR_TYPE,VAR_NAME
method operator $NAME$= takes $VAR_TYPE$ v returns nothing
set .$VAR_NAME$=v
endmethod
//! endtextmacro
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ReviveEventTest initializer Init uses ReviveEvent
private function SetUpUnits takes nothing returns nothing
local unit u=GetEnumUnit()
set Revive[u].onX=GetUnitX(u)
set Revive[u].onY=GetUnitY(u)
if IsUnitType(u,UNIT_TYPE_HERO) then
set Revive[u].awakenFx=DEFAULT_AWAKEN_FX
set Revive[u].cooldown=10.00
set Revive[u].upCooldown=true
set Revive[u].select=true
set Revive[u].showTd=false
set Revive[u].showLd=true
set Revive[u].simpleLd=false
else
set Revive[u].awakenFx="Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl"
set Revive[u].cooldown=3.00
set Revive[u].select=false
set Revive[u].showTd=true
set Revive[u].showLd=false
endif
set u=null
endfunction
private function Init takes nothing returns nothing
call GroupEnumUnitsInRect(bj_lastCreatedGroup,bj_mapInitialPlayableArea,null)
call ForGroup(bj_lastCreatedGroup,function SetUpUnits)
call GroupClear(bj_lastCreatedGroup)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Killhim
globals
private constant integer SPELL_ID = 'A002'
private constant integer MISSILE_ID = 'h003'
private constant string SOUND = "Units\\NightElf\\HeroWarden\\WardenDeath1.wav"
endglobals
private struct Killhim
player p
unit c
unit dummy
unit u
real dist
real xSpeed
real ySpeed
location loc
private method destroy takes nothing returns nothing
local sound s = CreateSound(SOUND,false,false,true,12700,12700,"")
call SetUnitAnimation(this.c,"stand")
call RemoveUnit(this.dummy)
call KillUnit(this.u)
//call DestroyEffect(AddSpecialEffect("Units\\Undead\\Abomination\\AbominationExplosion.mdl",GetUnitX(this.u),GetUnitY(this.u)))
call StartSound(s)
call KillSoundWhenDone(s)
set this.p = null
set this.c = null
set this.u = null
set this.dummy = null
call RemoveLocation(this.loc)
//call this.stopPeriodic()
call this.deallocate()
endmethod
private static method periodic takes nothing returns nothing
local timer t=GetExpiredTimer()
local thistype this=GetTimerData(t)
local real x = GetUnitX(this.dummy)
local real y = GetUnitY(this.dummy)
local real dx
local real dy
local real d1
local real d2
set dx = GetUnitX(this.dummy)-GetLocationX(this.loc)
set dy = GetUnitY(this.dummy)-GetLocationY(this.loc)
set d1 = SquareRoot(dx*dx+dy*dy)
set dx = GetLocationX(this.loc)-GetUnitX(this.u)
set dy = GetLocationY(this.loc)-GetUnitY(this.u)
set d2 = SquareRoot(dx*dx+dy*dy)
call SetUnitPosition(this.dummy,x+this.xSpeed,y+this.ySpeed)
call DestroyEffect(AddSpecialEffect("Abilities\\Weapons\\SteamTank\\SteamTankImpact.mdl",x,y))
call DestroyEffect(AddSpecialEffect("abilities\\weapons\\DemolisherMissile\\DemolisherMissile.mdl",x,y))
if d1 >= d2 then
call this.destroy()
call ReleaseTimer(t)
endif
set t=null
endmethod
//implement T32xs
private static method onCast takes nothing returns boolean
local thistype this
local real a
if GetSpellAbilityId() == SPELL_ID then
set this = .allocate()
set this.p = GetTriggerPlayer()
set this.c = GetTriggerUnit()
set this.loc = GetUnitLoc(this.c)
set this.u = GetSpellTargetUnit()
set a = Atan2(GetUnitY(this.u)-GetUnitY(this.c),GetUnitX(this.u)-GetUnitX(this.c))
set this.dummy = CreateUnit(this.p,MISSILE_ID,GetUnitX(this.c),GetUnitY(this.c),a)
set this.xSpeed = 110*Cos(a)
set this.ySpeed = 110*Sin(a)
call SetUnitAnimation(this.c,"Attack")
//call this.startPeriodic()
call TimerStart(NewTimerEx(this),.03125,true,function thistype.periodic)
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t,Condition(function thistype.onCast))
endmethod
endstruct
endscope