Please ignore my code needing cleaning up - like rewriting CUnitType and preventing leaks. That is not my current concern.
I have a simple JASS code wherein a unit is created after the same unit type of the same owner dies after 5 seconds. Why is it not working?
If I use, say, SaveUnitHandle(udg_Hashtable, 1, 1, u) and LoadUnitHandle(udg_Hashtable, 1, 1), it works fine with the corresponding player. But then all the other players are excluded.
I have a simple JASS code wherein a unit is created after the same unit type of the same owner dies after 5 seconds. Why is it not working?
JASS:
function CUnitType takes nothing returns boolean
if ( not ( GetUnitTypeId(GetDyingUnit()) == 'hfoo' ) ) then
return false
endif
return true
endfunction
function ExpireTimer takes nothing returns nothing
local timer t=GetExpiredTimer()
local integer id=GetHandleId(t)
local unit u = LoadUnitHandle(udg_Hashtable, id, 2)
local player p=GetOwningPlayer(u)
//local location pos=GetRandomLocInRect(GetPlayableMapRect()) remove useless
local location loc
local integer intx=GetRandomInt(-512,512)
local integer inty=GetRandomInt(-512,512)
//call DisplayTextToForce( GetPlayersAll(), I2S(id) )
set loc=Location(intx,inty)
call DisplayTextToForce( GetPlayersAll(), "unit spawned" )
//call CreateNUnitsAtLoc( 1, 'hfoo', p, loc, bj_UNIT_FACING )
call CreateUnit(p,'hfoo',intx,inty,0)
call DestroyTimer(t)
set t=null
set u=null
endfunction
function CallTimer takes nothing returns nothing
local unit u=GetDyingUnit()
local timer t=CreateTimer()
local integer id=GetHandleId(t)
//call DisplayTextToForce( GetPlayersAll(), I2S(id) )
call SaveUnitHandle(udg_Hashtable, id, 2, u)
call TimerStart(t, 5,false,function ExpireTimer)
endfunction
//===========================================================================
function InitTrig_UnitDeath takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(t,Condition (function CUnitType))
call TriggerAddAction( t, function CallTimer)
endfunction
If I use, say, SaveUnitHandle(udg_Hashtable, 1, 1, u) and LoadUnitHandle(udg_Hashtable, 1, 1), it works fine with the corresponding player. But then all the other players are excluded.