From 254d147bb2f665ce7dfab688a9fbf04b3ef73df2 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 10 Oct 2017 22:40:20 +0100 Subject: [PATCH] Add team locking --- ctf/teams.lua | 13 ++++++++----- ctf_chat/init.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ctf/teams.lua b/ctf/teams.lua index 42aed59..4b093e4 100644 --- a/ctf/teams.lua +++ b/ctf/teams.lua @@ -196,7 +196,7 @@ function ctf.join(name, team, force, by) player.team = team team_data.players[player.name] = player - + ctf.needs_save = true minetest.log("action", name .. " joined team " .. team) @@ -219,7 +219,7 @@ function ctf.clean_player_lists() ctf.log("utils", " - Skipping player "..str.name) end end - + ctf.needs_save = true end @@ -281,7 +281,8 @@ function ctf.autoalloc(name, alloc_mode) local index = {} for key, team in pairs(ctf.teams) do - if max_players == -1 or ctf.count_players_in_team(key) < max_players then + if team.data.allow_joins ~= false and (max_players == -1 or + ctf.count_players_in_team(key) < max_players) then table.insert(index, key) end end @@ -298,7 +299,8 @@ function ctf.autoalloc(name, alloc_mode) local two_count = -1 for key, team in pairs(ctf.teams) do local count = ctf.count_players_in_team(key) - if (max_players == -1 or count < max_players) then + if team.data.allow_joins ~= false and + (max_players == -1 or count < max_players) then if count > one_count then two = one two_count = one_count @@ -333,7 +335,8 @@ function ctf.autoalloc(name, alloc_mode) local smallest_count = 1000 for key, team in pairs(ctf.teams) do local count = ctf.count_players_in_team(key) - if not smallest or count < smallest_count then + if team.data.allow_joins ~= false and + (not smallest or count < smallest_count) then smallest = key smallest_count = count end diff --git a/ctf_chat/init.lua b/ctf_chat/init.lua index 82a03ef..c4480a5 100644 --- a/ctf_chat/init.lua +++ b/ctf_chat/init.lua @@ -25,6 +25,9 @@ local function team_console_help(name) minetest.chat_send_player(name, "/team remove - add a team called name (ctf_admin only)") end if privs and privs.ctf_team_mgr == true then + minetest.chat_send_player(name, "/team lock - closes a team to new players (ctf_team_mgr only)") + minetest.chat_send_player(name, "/team unlock - opens a team to new players (ctf_team_mgr only)") + minetest.chat_send_player(name, "/team bjoin - Command is * for all players, playername for one, !playername to remove (ctf_team_mgr only)") minetest.chat_send_player(name, "/team join - add 'player' to team 'team' (ctf_team_mgr only)") minetest.chat_send_player(name, "/team removeply - add 'player' to team 'team' (ctf_team_mgr only)") end @@ -36,6 +39,8 @@ minetest.register_chatcommand("team", { local test = string.match(param, "^player ([%a%d_-]+)") local create = string.match(param, "^add ([%a%d_-]+)") local remove = string.match(param, "^remove ([%a%d_-]+)") + local lock = string.match(param, "^lock ([%a%d_-]+)") + local lock = string.match(param, "^unlock ([%a%d_-]+)") local j_name, j_tname = string.match(param, "^join ([%a%d_-]+) ([%a%d_]+)") local b_tname, b_pattern = string.match(param, "^bjoin ([%a%d_-]+) ([%a%d_-%*%! ]+)") local l_name = string.match(param, "^removeplr ([%a%d_-]+)") @@ -66,6 +71,32 @@ minetest.register_chatcommand("team", { else return false, "You are not a ctf_admin!" end + elseif lock then + local privs = minetest.get_player_privs(name) + if privs and privs.ctf_team_mgr then + local team = ctf.team(lock) + if team then + team.data.allow_joins = false + return true, "Locked team to new members" + else + return false, "Unable to find that team!" + end + else + return false, "You are not a ctf_team_mgr!" + end + elseif unlock then + local privs = minetest.get_player_privs(name) + if privs and privs.ctf_team_mgr then + local team = ctf.team(unlock) + if team then + team.data.allow_joins = true + return true, "Unlocked team to new members" + else + return false, "Unable to find that team!" + end + else + return false, "You are not a ctf_team_mgr!" + end elseif param == "all" then ctf.list_teams(name) elseif ctf.team(param) then