add /advtrains_stats and /advtrains_cleanup
fixes https://github.com/pandorabox-io/pandorabox.io/issues/348
This commit is contained in:
parent
1468d674e4
commit
9a3840c0fb
58
advtrains.lua
Normal file
58
advtrains.lua
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
-- list of active trains
|
||||
local active_trains = {}
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
|
||||
-- every 10 seconds
|
||||
if timer < 10 then return end
|
||||
timer = 0
|
||||
|
||||
for _, train in pairs(advtrains.trains) do
|
||||
if train.velocity > 0 then
|
||||
-- train moved, mark as active
|
||||
active_trains[train.id] = true
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_chatcommand("advtrains_cleanup", {
|
||||
description = "cleans up all non-automated trains",
|
||||
privs = { server = true },
|
||||
func = function(name, param)
|
||||
for _, train in pairs(advtrains.trains) do
|
||||
if not active_trains[train.id] then
|
||||
advtrains.remove_train(train.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
minetest.register_chatcommand("advtrains_stats", {
|
||||
description = "show advtrains stats",
|
||||
func = function(name, param)
|
||||
local train_count = 0
|
||||
local wagon_count = 0
|
||||
local active_train_count = 0
|
||||
|
||||
for _ in ipairs(active_trains) do
|
||||
active_train_count = active_train_count + 1
|
||||
end
|
||||
|
||||
for _, train in pairs(advtrains.trains) do
|
||||
train_count = train_count + 1
|
||||
for _, part in pairs(train.trainparts) do
|
||||
local wagon = advtrains.wagons[part]
|
||||
if wagon ~= nil then
|
||||
wagon_count = wagon_count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true, "Trains: " .. train_count .. " Wagons: " .. wagon_count .. " Active trains: " .. active_train_count
|
||||
end
|
||||
})
|
@ -28,3 +28,4 @@ player_monoids?
|
||||
pipeworks?
|
||||
computer?
|
||||
fancy_vend?
|
||||
advtrains?
|
||||
|
5
init.lua
5
init.lua
@ -46,6 +46,11 @@ if minetest.get_modpath("farming") then
|
||||
dofile(MP.."/farming.lua")
|
||||
end
|
||||
|
||||
if minetest.get_modpath("advtrains") then
|
||||
-- advtrains stuff
|
||||
dofile(MP.."/advtrains.lua")
|
||||
end
|
||||
|
||||
if minetest.get_modpath("jumpdrive") then
|
||||
-- limit jumpdrive travel
|
||||
dofile(MP.."/travel/jumpdrive.lua")
|
||||
|
Loading…
x
Reference in New Issue
Block a user