- Joined
- Nov 7, 2005
- Messages
- 78
I have the following code to respawn creeps. However, occasionally a creep fails to respawn. Can anyone see any issues with this?
JASS:
globals
private hashtable htGlobal = InitHashtable()
private trigger tDeath = CreateTrigger()
endglobals
private interface we_Entity
public unit u
public unit uTarget
method onDeath takes nothing returns nothing defaults nothing
endinterface
struct we_AI extends we_Entity
public real x = 0.00
public real y = 0.00
public real fFacing = 270.00
private real fRespawnTime = 60.00
public method setRespawnTime takes real time returns nothing
if (time < 0.00) then
set this.fRespawnTime = 0.00
else
set this.fRespawnTime = time
endif
endmethod
static method create takes unit u returns we_AI
local we_AI this = we_AI.allocate()
set this.u = u
call SaveInteger( htGlobal, GetHandleId(this.u), S2I("WE_ENTITY"), this )
call TriggerRegisterUnitEvent( tDeath, this.u, EVENT_UNIT_DEATH )
return this
endmethod
method onDestroy takes nothing returns nothing
set this.u = null
set this.uTarget = null
endmethod
static method respawn takes nothing returns nothing
local timer t = GetExpiredTimer()
local we_AI this = LoadInteger( htGlobal, GetHandleId(t), 0 )
local unit u = CreateUnit( GetOwningPlayer(this.u), GetUnitTypeId(this.u), this.x, this.y, this.fFacing )
call SetHeroLevel( u, GetHeroLevel(this.u), false )
call RemoveSavedInteger( htGlobal, GetHandleId(this.u), S2I("WE_ENTITY") )
call RemoveUnit(this.u)
set this.u = u
call SaveInteger( htGlobal, GetHandleId(u), S2I("WE_ENTITY"), this )
call TriggerRegisterUnitEvent( tDeath, this.u, EVENT_UNIT_DEATH )
call RemoveSavedInteger( htGlobal, GetHandleId(t), 0 )
call DestroyTimer(t)
set u = null
set t = null
endmethod
method onDeath takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart( t, this.fRespawnTime, false, function we_AI.respawn )
call SaveInteger( htGlobal, GetHandleId(t), 0, this )
set t = null
endmethod
endstruct
function we_CreateEntityAI takes unit u returns we_AI
local we_AI e = we_AI.create(u)
set e.x = GetUnitX(u)
set e.y = GetUnitY(u)
set e.fFacing = GetUnitFacing(u)
return e
endfunction
function we_GetUnitEntity takes unit u returns we_Entity
return LoadInteger( htGlobal, GetHandleId(u), S2I("WE_ENTITY") )
endfunction
private function entOnDeath takes nothing returns nothing
local we_Entity e = we_GetUnitEntity(GetTriggerUnit())
call e.onDeath()
endfunction
private function initSys takes nothing returns nothing
call TriggerAddAction( tDeath, function entOnDeath )
endfunction