diff --git a/mods/ctf/ctf_map/maps_catalog.lua b/mods/ctf/ctf_map/maps_catalog.lua index 1004eb7..6bba7bb 100644 --- a/mods/ctf/ctf_map/maps_catalog.lua +++ b/mods/ctf/ctf_map/maps_catalog.lua @@ -100,12 +100,7 @@ minetest.register_chatcommand("maps", { -- If arg. supplied, set idx to index of the matching map name -- or path. Else, set to indices[name] or index of current map if param then - for i, map in pairs(ctf_map.available_maps) do - if map.name:find(param) or map.path:find(param) then - idx = i - break - end - end + idx = ctf_map.get_idx_and_map(param) else idx = indices[name] or ctf_map.map and ctf_map.map.idx or 1 end diff --git a/mods/ctf/ctf_map/schem_map.lua b/mods/ctf/ctf_map/schem_map.lua index ddc3d1c..8997106 100644 --- a/mods/ctf/ctf_map/schem_map.lua +++ b/mods/ctf/ctf_map/schem_map.lua @@ -55,19 +55,27 @@ function minetest.get_server_status(name, joined) end +function ctf_map.get_idx_and_map(param) + param = param:lower():trim() + for i, map in pairs(ctf_map.available_maps) do + if map.name:lower():find(param, 1, true) or + map.path:lower():find(param, 1, true) then + return i, map + end + end +end + local next_idx minetest.register_chatcommand("set_next", { privs = { ctf_admin = true }, func = function(name, param) - for i, map in pairs(ctf_map.available_maps) do - if map.name:lower():find(param, 1, true) or - map.path:lower():find(param, 1, true) then - next_idx = i - return true, "Selected " .. map.name - end + local idx, map = ctf_map.get_idx_and_map(param) + if idx then + next_idx = idx + return true, "Selected " .. map.name + else + return false, "Couldn't find any matches" end - - return false, "Couldn't find any matches" end, })