Skip to content
Snippets Groups Projects
Commit b8df2d17 authored by Peter Nerlich's avatar Peter Nerlich
Browse files

add script to stop all trains x seconds after the last player left the server

parent ad912cb8
No related branches found
No related tags found
No related merge requests found
local DISABLE_TIMEOUT = tonumber(minetest.settings:get("kif_custom.advtrains.disable_timeout")) or 60 * 60
local trains_disabled = #minetest.get_connected_players == 0
local disable_job = nil
minetest.register_on_joinplayer(function(player, last_login)
-- activate trains
if disable_job ~= nil then
disable_job:cancel()
disable_job = nil
end
if trains_disabled then
trains_disabled = false
end
end)
minetest.register_on_leaveplayer(function(player, timed_out)
if #minetest.get_connected_players() == 0 then
-- deactivate trains
if disable_job == nil then
disable_job = minetest.after(DISABLE_TIMEOUT, function()
trains_disabled = true
disable_job = nil
end)
end
end
end)
-- overrides
assert(type(advtrains.train_ensure_init) == "function")
local old_train_ensure_init = advtrains.train_ensure_init
advtrains.train_ensure_init = function(k, v)
if trains_disabled then
return
else
return old_train_ensure_init(k, v)
end
end
assert(type(advtrains.train_step_b) == "function")
local old_train_step_b = advtrains.train_step_b
advtrains.train_step_b = function(k, v, dtime)
if trains_disabled then
return
else
return old_train_step_b(k, v, dtime)
end
end
assert(type(advtrains.train_step_c) == "function")
local old_train_step_c = advtrains.train_step_c
advtrains.train_step_c = function(k, v, dtime)
if trains_disabled then
return
else
return old_train_step_c(k, v, dtime)
end
end
......@@ -13,3 +13,8 @@ kif_custom.death.waypoint_expires_seconds_creative (Seconds in which waypoints e
# until it disappears, but also changes to a blue, green and finally red tint before disappearing.
# The saturation interpolates between the color and the grey shade of the same value.
kif_custom.death.waypoint_saturation (Color saturation) float 1 0 2
[advtrains]
# The amount of seconds until all trains are stopped after the last player has left.
kif_custom.advtrains.disable_timeout (Disable timeout) int 3600 0 604800
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment