struct CreepRespawn extends array
private static hashtable CreepHash = InitHashtable()
private static real TIMER = 120 //interval
//This will save units position on map initialization (make sure all your units are placed on the ground)
private static method CreepSetup takes nothing returns nothing
local unit u
call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u == null
call SaveReal(CreepHash, GetHandleId(u), 0, GetUnitX(u))
call SaveReal(CreepHash, GetHandleId(u), 1, GetUnitY(u))
call GroupRemoveUnit(bj_lastCreatedGroup, u)
endloop
endmethod
//This will simply respawn unit after some time at it's location set above
private static method CreepRespawn takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer index = GetHandleId(u)
local integer id = GetUnitTypeId(u)
local player p = GetOwningPlayer(u)
local real x = LoadReal(CreepHash, index, 0)
local real y = LoadReal(CreepHash, index, 1)
call FlushChildHashtable(CreepHash, index)
call TriggerSleepAction( TIMER )
set u = CreateUnit(p, id, x, y, GetRandomReal(-0.03, 0.03))
set index = GetHandleId(u)
call SaveReal(CreepHash, index, 0, x)
call SaveReal(CreepHash, index, 1, y)
call SetUnitCreepGuard( u , false )
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl", x, y))
set u = null
set p = null
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call CreepSetup()
call TriggerRegisterPlayerUnitEvent( t, Player(0), EVENT_PLAYER_UNIT_DEATH , null ) //Player red
call TriggerRegisterPlayerUnitEvent( t, Player(1), EVENT_PLAYER_UNIT_DEATH , null ) //Player blue
call TriggerRegisterPlayerUnitEvent( t, Player(2), EVENT_PLAYER_UNIT_DEATH , null ) //Player teal
call TriggerAddAction( t, function thistype.CreepRespawn )
set t = null
endmethod
endstruct