Hi. I am trying to make a script to manually calculate the APM (Actions per Minute) of a player and store in a variable.
It's pretty simple to find the average APM of a player. I created a variable "Actions" as an integer with default value 0. Each time a unit is selected or a command is issued to a unit, I increase this variable by 1. The APM can then be calculated as "Actions / Mission Time * 60", in other words the number of actions divided by number of seconds that passed, multiplied by 60 (since there are 60 seconds in a minute)
In the observer / replay interface, each player has 2 types of APM - average APM and current APM.
I want to find the "current" APM of a player, but I actually have no idea how the game calculates it. So does anyone know how to calculate the "current" APM of a player?
The problem is that I can't use that score value, because all commands for that player is using the Issue Order command so it wont work. I have to manually calculate the APM. Does anyone know how to find the "current" APM?
Hey, you need to specify what you mean by "current" APM, i.e. need to tell us the period of time you want to count APM on. It will be something like 5 or 10 seconds probably.
Lets assume the "current" APM you want is over the last 5 seconds. Lets also assume you only need to update this information every second (like you update the display showing it every second). There are many ways to achieve what you want, here is one example.
For each player, you could have a record with 7 counters instead of 1. Lets call them C0, C1, C2, C3, C4, C5, CT.
In C0, you count all the actions of the player since the beginning of the current game second, lets call it second number n.
In C1 you have the number of actions of that player during the whole second number n-1.
Same for C2, C3, C4, C5 with number of actions in seconds n-2, n-3, n-4, n-5
In CT, you have all the actions of the player since the beginning of the game to the start of second n-5.
To implement that now, you only need 2 triggers and 2 functions. Initiate all counters at 0.
First trigger: Each time a unit is selected or a command is issued to a unit, increase C0 by 1 (C0 of the correct player if you count APM of several players). That, you already know how to do.
Second trigger: Every game second:
modify CT: add C5
set C5 equal to C4
set C4 equal to C3
set C3 equal to C2
set C2 equal to C1
set C1 equal to C0
set C0 equal to 0
First Function: getCurrentAPM()
return (C1+C2+C3+C4+C5) * 60 / 5
this is actually your average APM over the last 5 seconds
not accurate during the first 4 seconds of the game but I guess we don't care too much
Second Function: getAverageAPM()
return (C1+C2+C3+C4+C5+CT) * 60 / MissionTime
this is actually your average APM since the beginning of the game