Add /set_next command, cycle rather than random

This commit is contained in:
rubenwardy 2018-06-24 21:17:23 +01:00
parent b4be27e4a5
commit d3c8f39372
No known key found for this signature in database
GPG key ID: A1E29D52FF81513C

View file

@ -27,6 +27,20 @@ local mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
ctf_map.map = nil ctf_map.map = nil
local next_idx
minetest.register_chatcommand("set_next", {
privs = { ctf_admin = true },
func = function(name, param)
for i, mname in pairs(ctf_map.available_maps) do
if mname:lower():find(param, 1, true) then
next_idx = i
return true, "Selected " .. mname
end
end
end,
})
do do
local files_hash = {} local files_hash = {}
@ -184,7 +198,9 @@ ctf_match.register_on_new_match(function()
-- Choose next map index, but don't select the same one again -- Choose next map index, but don't select the same one again
local idx local idx
if ctf_map.map then if next_idx then
idx = next_idx
elseif ctf_map.map then
idx = math.random(#ctf_map.available_maps - 1) idx = math.random(#ctf_map.available_maps - 1)
if idx >= ctf_map.map.idx then if idx >= ctf_map.map.idx then
idx = idx + 1 idx = idx + 1
@ -192,6 +208,7 @@ ctf_match.register_on_new_match(function()
else else
idx = math.random(#ctf_map.available_maps) idx = math.random(#ctf_map.available_maps)
end end
next_idx = (idx % #ctf_map.available_maps) + 1
-- Load meta data -- Load meta data
local name = ctf_map.available_maps[idx] local name = ctf_map.available_maps[idx]