Elimate buggy old ctf.add_user() and use ctf.join()
This commit is contained in:
parent
4f1763265f
commit
1aa85c35b8
@ -75,6 +75,10 @@ function ctf.count_players_in_team(team)
|
||||
end
|
||||
|
||||
function ctf.new_player(name)
|
||||
if not name then
|
||||
ctf.error("team", "Can't create a blank player")
|
||||
ctf.log("team", debug.traceback())
|
||||
end
|
||||
ctf.log("team", "Creating player " .. name)
|
||||
ctf.players[name] = {
|
||||
name = name
|
||||
@ -94,8 +98,7 @@ function ctf.player_or_nil(name)
|
||||
end
|
||||
|
||||
-- Player joins team
|
||||
-- Called by /join or auto allocate.
|
||||
-- /team join uses ctf.add_user()
|
||||
-- Called by /join, /team join or auto allocate.
|
||||
function ctf.join(name, team, force)
|
||||
if not name or name == "" or not team or team == "" then
|
||||
ctf.log("team", "Missing parameters to ctf.join")
|
||||
@ -111,14 +114,18 @@ function ctf.join(name, team, force)
|
||||
return false
|
||||
end
|
||||
|
||||
if not ctf.team(team) then
|
||||
|
||||
local team_data = ctf.team(team)
|
||||
if team_data then
|
||||
minetest.log("action", name .. " attempted to join " .. team .. ", which doesn't exist")
|
||||
minetest.chat_send_player(name, "No such team.")
|
||||
ctf.list_teams(name)
|
||||
return false
|
||||
end
|
||||
|
||||
if ctf.add_user(team, player) == true then
|
||||
player.team = team
|
||||
team_data.players[player.name] = player
|
||||
|
||||
minetest.log("action", name .. " joined team " .. team)
|
||||
minetest.chat_send_all(name.." has joined team "..team)
|
||||
|
||||
@ -127,30 +134,6 @@ function ctf.join(name, team, force)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- TODO: refactor ctf.add_user etc
|
||||
-- Add a player to a team in data structures
|
||||
function ctf.add_user(team, user)
|
||||
local _team = ctf.team(team)
|
||||
local _user = ctf.player(user.name)
|
||||
if _team and user and user.name then
|
||||
if _user.team and ctf.team(_user.team) then
|
||||
ctf.teams[_user.team].players[user.name] = nil
|
||||
end
|
||||
|
||||
user.team = team
|
||||
user.auth = false
|
||||
_team.players[user.name] = user
|
||||
ctf.players[user.name] = user
|
||||
ctf.needs_save = true
|
||||
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Cleans up the player lists
|
||||
|
@ -71,20 +71,17 @@ minetest.register_chatcommand("team", {
|
||||
end
|
||||
end
|
||||
elseif tplayer and tteam then
|
||||
minetest.chat_send_player(name,"joining '"..tplayer.."' to team '"..tteam.."'",false)
|
||||
minetest.chat_send_player(name, "joining '" .. tplayer ..
|
||||
"' to team '" .. tteam .. "'",false)
|
||||
local privs = minetest.get_player_privs(name)
|
||||
if privs and privs.team == true then
|
||||
local player = ctf.player(tplayer)
|
||||
|
||||
if not player then
|
||||
player = {name=tplayer}
|
||||
end
|
||||
|
||||
if ctf.add_user(tteam,tplayer) == true then
|
||||
if privs and privs.ctf_admin == true then
|
||||
if ctf.join(tplayer, tteam, true) then
|
||||
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
||||
else
|
||||
minetest.char_send_player(name, "Failed to add player to team.")
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, "You can not do this!")
|
||||
minetest.chat_send_player(name, "You do not have the required privileges!")
|
||||
end
|
||||
elseif param=="help" then
|
||||
team_console_help(name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user