- Joined
- Oct 19, 2014
- Messages
- 187
JASS:
scope UnitCustomData initializer init/*JC Helas*/
globals
private integer max=0
private integer rec=0
private integer array id[5000]
private unit array uni[5000]
endglobals
private function recycle takes nothing returns boolean
local unit u=GetTriggerUnit()
local boolean b=true
if rec!=0 then
set rec:id:uni=u
call SetUnitUserData(u,rec:id)
set rec:id=0
set rec=rec-1
set b=false
endif
return b
endfunction
private function remove takes unit u returns nothing
set rec=rec+1
set rec:id=GetUnitUserData(u)
endfunction
private function enter takes nothing returns nothing
local integer i=max
local unit u=GetTriggerUnit()
set i=i+1
set i:uni=u
call SetUnitUserData(u,i)
set max=i
set i=0
set u=null
endfunction
private function init takes nothing returns nothing
local region r=CreateRegion()
local trigger t=CreateTrigger()
call RegionAddRect(r,GetWorldBounds())
call TriggerRegisterEnterRegion(t,r,null)
call TriggerAddAction(t,function enter)
call TriggerAddCondition(t,Condition(function recycle))
set r=null
set t=null
endfunction
hook RemoveUnit remove
endscope