-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset.lua
More file actions
executable file
·71 lines (61 loc) · 1.44 KB
/
reset.lua
File metadata and controls
executable file
·71 lines (61 loc) · 1.44 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---@type Plugin
local mode = ...
local server = server
local osRealClock = os.realClock
local EVENT_LIMIT = 30000
local EVENT_LIMIT_WARN = math.floor(EVENT_LIMIT * 0.9)
local eventLimitWarned
local currentTickTime
local numLongTicks
mode:addEnableHandler(function ()
currentTickTime = osRealClock()
numLongTicks = 0
end)
mode:addDisableHandler(function ()
currentTickTime = nil
eventLimitWarned = nil
end)
mode:addHook(
'ResetGame',
function ()
server.type = 20
server.levelToLoad = 'round'
end
)
mode:addHook(
'PostResetGame',
function ()
eventLimitWarned = false
numLongTicks = 0
server.state = STATE_GAME
server.time = server.TPS * 60
server.sunTime = 11 * 60 * 60 * server.TPS
end
)
mode:addHook(
'Logic',
function ()
local lastTickTime = currentTickTime
currentTickTime = osRealClock()
if currentTickTime - lastTickTime > (1 / 40) then
numLongTicks = numLongTicks + 1
if numLongTicks > 5 then
server:reset()
chat.announce(string.format('The game was reset - too much lag (%.2fmspf)', (currentTickTime - lastTickTime) * 1000))
return
end
else
numLongTicks = 0
end
local numEvents = #events
if numEvents >= EVENT_LIMIT_WARN then
if numEvents >= EVENT_LIMIT then
server:reset()
chat.announce('The game was reset - too many events')
elseif not eventLimitWarned then
eventLimitWarned = true
chat.announce('There are too many events, the game may reset soon')
end
end
end
)