forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tps.lua
50 lines (40 loc) · 1.08 KB
/
tps.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
TpsCache = {}
GlobalTps = {}
function HandleConsoleTps(Split)
LOG("Global TPS: " .. GetAverageNum(GlobalTps))
for WorldName, WorldTps in pairs(TpsCache) do
LOG("World \"" .. WorldName .. "\": " .. GetAverageNum(WorldTps) .. " TPS");
end
return true
end
function HandleTpsCommand(Split, Player)
Player:SendMessageInfo("Global TPS: " .. GetAverageNum(GlobalTps))
for WorldName, WorldTps in pairs(TpsCache) do
Player:SendMessageInfo("World \"" .. WorldName .. "\": " .. GetAverageNum(WorldTps) .. " TPS");
end
return true
end
function GetAverageNum(Table)
local Sum = 0
for i,Num in ipairs(Table) do
Sum = Sum + Num
end
return math.floor(Sum / #Table * 100) / 100
end
function OnWorldTick(World, TimeDelta)
local WorldTps = TpsCache[World:GetName()]
if (WorldTps == nil) then
WorldTps = {}
TpsCache[World:GetName()] = WorldTps
end
if (#WorldTps >= 10) then
table.remove(WorldTps, 1)
end
table.insert(WorldTps, 1000 / TimeDelta)
end
function OnTick(TimeDelta)
if (#GlobalTps >= 10) then
table.remove(GlobalTps, 1)
end
table.insert(GlobalTps, 1000 / TimeDelta)
end