Name | Type | is_array | initial_value |
DeathEvent | real | No | |
DeathUnit | unit | No | |
UDex | integer | No | |
UDexGen | integer | No | |
UDexNext | integer | Yes | |
UDexPrev | integer | Yes | |
UDexRecycle | integer | No | |
UDexUnits | unit | Yes | |
UDexWasted | integer | No | |
UnitIndexerEnabled | boolean | No | |
UnitIndexEvent | real | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
//Empty line
// Resource name
// Author name
//Empty line
// Description(3 tabs distance from comment
//Empty line
// FunctionName1(parameter1,parameter2,parameter3) -> return type
// |
// Explanation1
//Empty line
// FunctionName2(parameter1,parameter2...) -> return type
// |
// Explanation2
//Empty line
//+ Start of a block
//BLOCK OF CODE
//- End of a block (may be be left out if obvious)
//Parameters are unnamed, unless naming is necessary for understanding what they do.
//TESH.scrollpos=64
//TESH.alwaysfold=0
//
// CustomDeath
// by Xonok
//
// This system makes it possible to "kill" units
// while still keeping them targetable. The system
// requires any kind of unit indexer or it won't
// work properly.
// Currently this system only contains API functions.
//
// KillUnitCustom(unit)
// |
// Adds a unit into the system by playing its
// death animation and making it paused and
// invulnerable.
//
// ReviveUnitCustom(unit) -> return boolean
// |
// Removes a unit from this system. Plays the birth
// animation if unit has one.
//
// IsUnitDeadCustom(unit) -> return boolean
// |
// A relatively fast check to see whether the unit
// is in the system.
//
library CustomDeath
globals
private boolean array UnitDead
endglobals
//+ API
function IsUnitDeadCustom takes unit un returns boolean
debug if UnitDead[GetUnitUserData(un)] then
debug call DisplayTextToPlayer(GetLocalPlayer(),0,0,"CustomDeath: Checked unit" + GetUnitName(un) + "is dead")
debug else
debug call DisplayTextToPlayer(GetLocalPlayer(),0,0,"CustomDeath: Checked unit" + GetUnitName(un) + "is not dead")
debug endif
return UnitDead[GetUnitUserData(un)]
endfunction
function KillUnitCustom takes unit un returns nothing
local unit backup = udg_DeathUnit
local integer ID = GetUnitUserData(un)
debug if UnitDead[GetUnitUserData(un)] then
debug call DisplayTextToPlayer(GetLocalPlayer(),0,0,"CustomDeath: Tried to kill a dead unit: "+GetUnitName(un))
debug else
call SetUnitInvulnerable(un,true)
call UnitRemoveBuffs(un,true,true)
call PauseUnit(un,true)
call SetUnitAnimation(un,"death")
call SetUnitUseFood(un,false)
set UnitDead[ID] = true
set udg_DeathUnit = un
set udg_DeathEvent = 1
set udg_DeathEvent = 0
debug endif
set udg_DeathUnit = backup
set backup = null
endfunction
function ReviveUnitCustom takes unit un returns boolean
local integer i = 1
local unit backup = udg_DeathUnit
local integer ID = GetUnitUserData(un)
debug if not(UnitDead[GetUnitUserData(un)]) then
debug call DisplayTextToPlayer(GetLocalPlayer(),0,0,"CustomDeath: Tried to revive a living unit: "+GetUnitName(un))
debug else
call SetUnitInvulnerable(un,false)
call PauseUnit(un,false)
set UnitDead[ID] = false
call SetUnitAnimation(un,"birth")
call QueueUnitAnimation(un,"stand")
call SetUnitUseFood(un,true)
set udg_DeathUnit = un
set udg_DeathEvent = 2
set udg_DeathEvent = 0
set udg_DeathUnit = backup
set backup = null
return true
debug endif
set udg_DeathUnit = backup
set backup = null
return false
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_JASS_How_to_use_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call KillUnitCustom(u)//Kills the unit
call ReviveUnitCustom(u)//Brings the unit back to life. Also returns a boolean (false if the unit wasn't dead in the first place)
call IsUnitDeadCustom(u)//Tells whether a unit is dead.
endfunction
//===========================================================================
function InitTrig_JASS_How_to_use takes nothing returns nothing
set gg_trg_JASS_How_to_use = CreateTrigger( )
call TriggerRegisterVariableEvent( gg_trg_GUI_How_to_use, "udg_DeathEvent", EQUAL, 1.00 )//Tells when a unit dies
call TriggerRegisterVariableEvent( gg_trg_GUI_How_to_use, "udg_DeathEvent", EQUAL, 2.00 )//Tells when a unit is revived
call TriggerAddAction( gg_trg_JASS_How_to_use, function Trig_JASS_How_to_use_Actions )
endfunction