function ReturnHarvest takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit u=LoadUnitHandle(udg_GameHashTable,GetHandleId(t),0)
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(udg_GameHashTable,GetHandleId(t))
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"Timer destroyed.")
if (u==null) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"No unit retrieved.")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,GetUnitName(u)+" @ index "+I2S(GetUnitUserData(u)))
call SetUnitColor(u,PLAYER_COLOR_BLUE)
endif
set t=null
set u=null
set udg_UDexTimer[GetUnitUserData(u)]=null
endfunction
function Trig_Harvest_Resource_Start_Actions takes nothing returns nothing
local integer u_id = GetUnitUserData(GetTriggerUnit())
call DisplayTextToForce( GetPlayersAll(), "INDEX" + I2S(u_id) )
if (GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_CAST) then
if (TimerGetElapsed(udg_UDexTimer[u_id]) == 0.00) then
set udg_UDexTimer[u_id] = CreateTimer()
call SaveUnitHandle(udg_GameHashTable,GetHandleId(udg_UDexTimer[u_id]),0,GetTriggerUnit())// attach the unit to the timer
call TimerStart(udg_UDexTimer[u_id], 10, false, function ReturnHarvest)
call DisplayTextToForce( GetPlayersAll(), "timer started at: " + R2S(TimerGetRemaining(udg_UDexTimer[u_id])) )
else
call ResumeTimer(udg_UDexTimer[u_id])
call DisplayTextToForce( GetPlayersAll(), "timer resumed at: " + R2S(TimerGetRemaining(udg_UDexTimer[u_id])) )
endif
elseif (GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_ENDCAST) then
call PauseTimer(udg_UDexTimer[u_id])
call DisplayTextToForce( GetPlayersAll(), "timer paused at: " + R2S(TimerGetRemaining(udg_UDexTimer[u_id])) )
endif
endfunction
//===========================================================================
function InitTrig_Harvest takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
call TriggerAddAction( t, function Trig_Harvest_Resource_Start_Actions )
set t = null
set udg_GameHashTable=InitHashtable()
endfunction