Add team locking

master
rubenwardy 2017-10-10 22:40:20 +01:00
parent 5769d446ab
commit 254d147bb2
2 changed files with 39 additions and 5 deletions

View File

@ -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

View File

@ -25,6 +25,9 @@ local function team_console_help(name)
minetest.chat_send_player(name, "/team remove <team> - 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 <team> - closes a team to new players (ctf_team_mgr only)")
minetest.chat_send_player(name, "/team unlock <team> - opens a team to new players (ctf_team_mgr only)")
minetest.chat_send_player(name, "/team bjoin <team> <commands> - Command is * for all players, playername for one, !playername to remove (ctf_team_mgr only)")
minetest.chat_send_player(name, "/team join <name> <team> - add 'player' to team 'team' (ctf_team_mgr only)")
minetest.chat_send_player(name, "/team removeply <name> - 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