-
Notifications
You must be signed in to change notification settings - Fork 5
/
Apm_widget.lua
30 lines (29 loc) · 994 Bytes
/
Apm_widget.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function widget:GetInfo()
return {
name = "APM Counter",
desc = "Live apm",
author = "Bootlegged Floris Code",
date = "Dec 30, 2022",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
local updateTimer = 0
function widget:Update()
if not Spring.GetSpectatingState() then
updateTimer = updateTimer + Spring.GetLastUpdateSeconds()
if updateTimer > 1 then
local _, mc, kp, _, _ = Spring.GetPlayerStatistics(Spring.GetMyPlayerID())
Spring.Echo("kp: " .. kp)
Spring.Echo("mc: " .. mc)
if mc and kp then
local apm = math.ceil((mc + kp * 60) / (math.max(Spring.GetGameSeconds(), 60)) - 0.5)
if apm and Spring.GetGameSeconds() > 0 then
Spring.Echo("Your APM: " .. apm)
end
updateTimer = 0
end
end
end
end