TriggerHappy
...
- Reaction score
- 341
RemoveUnitEx
by TriggerHappy187
Introduction:
The script idea originally by Ammorth, though it did not work on units that have decayed and been removed.
This event registers when a unit is removed by the included RemoveUnitEx function. My script (hopefully) functions whether or not the unit has decayed.
I have tested it, though I could have been wrong, I set all the decay times in the gameplay constants to 0.50 then TSA'd 20 seconds and called RemoveUnitEx, and it still worked. Any other testing would be great
An example use of this would look like.
JASS:
function test takes nothing returns nothing
call BJDebugMsg("Unit Removed")
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterRemoveUnitEvent(t, gg_unit_hfoo_0001)
call TriggerAddAction(t, function test)
endfunction
The script
JASS:
library RemoveUnitEx
globals
private integer count = 0
private unit lastRemovedUnit = null
endglobals
private struct index
trigger t
unit u
static method create takes trigger t, unit u returns index
local index i = index.allocate()
set i.u = u
set i.t = t
return i
endmethod
endstruct
function TriggerRegisterRemoveUnitEvent takes trigger whichTrigger, unit whichUnit returns nothing
local index i = index.create(whichTrigger, whichUnit)
set count = count + 1
endfunction
function RemoveUnitEx takes unit u returns nothing
local integer i = count
local index d = i
loop
exitwhen i <= 0
if u == d.u then
call TriggerExecute(d.t)
call d.destroy()
endif
set i = i - 1
set d = i
endloop
set lastRemovedUnit = u
call RemoveUnit(u)
endfunction
function GetLastRemovedUnit takes nothing returns unit
return lastRemovedUnit
endfunction
endlibrary