library APM initializer init
globals
private trigger APM_TRG
private integer array A_COUNT
private real array APM
private timer array APM_TMR
private timer ELAPSED_TIME
private hashtable ht
endglobals
private function registerAction takes nothing returns boolean
local player p = GetTriggerPlayer()
local integer id = GetPlayerId(p)
if TimerGetRemaining(APM_TMR[id]) == 0.0 then
set A_COUNT[id] = A_COUNT[id] + 1
set APM[id] = A_COUNT[id] / (TimerGetElapsed(ELAPSED_TIME) / 60)
call TimerStart(APM_TMR[id], 0.01, false, null)
call DisplayTimedTextToPlayer(Player(0), 0, 0, 5, "Player 1 APM: " + I2S(R2I(APM[id])))
endif
return false
endfunction
function startAPM takes nothing returns nothing
call EnableTrigger(APM_TRG)
call TimerStart(ELAPSED_TIME, 1000000, false, null)
endfunction
function pauseAPM takes nothing returns nothing
call DisableTrigger(APM_TRG)
call PauseTimer(ELAPSED_TIME)
endfunction
private function init takes nothing returns nothing
local integer i
set ht = InitHashtable()
set ELAPSED_TIME = CreateTimer()
set APM_TRG = CreateTrigger()
call TriggerAddCondition(APM_TRG, function registerAction)
set i = 0
loop
set APM[i] = 0
set APM_TMR[i] = CreateTimer()
call TriggerRegisterPlayerUnitEvent(APM_TRG, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
call TriggerRegisterPlayerUnitEvent(APM_TRG, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
call TriggerRegisterPlayerUnitEvent(APM_TRG, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
call TriggerRegisterPlayerUnitEvent(APM_TRG, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
exitwhen i == 11
set i = i + 1
endloop
call DisableTrigger(APM_TRG)
call startAPM()
call DisplayTimedTextToPlayer(Player(0), 0, 0, 5, "Init Finish")
endfunction
endlibrary