ctf_flash Remove player from team on leaveplayer

This commit is contained in:
rubenwardy 2015-07-14 14:43:52 +01:00
parent e536384f4e
commit 2328870dae
2 changed files with 41 additions and 1 deletions

View File

@ -23,8 +23,11 @@ function ctf.team(name)
return ctf.teams[name.name]
else
if not ctf.teams[name] then
if name then
ctf.warning("team", dump(name) .. " does not exist!")
end
return nil
end
return ctf.teams[name]
end
end
@ -97,6 +100,17 @@ function ctf.player_or_nil(name)
return ctf.players[name]
end
function ctf.remove_player(name)
local player = ctf.players[name]
if player then
local team = ctf.team(ctf.players.team)
if team then
team.players[name] = nil
end
ctf.players[name] = nil
end
end
-- Player joins team
-- Called by /join, /team join or auto allocate.
function ctf.join(name, team, force, by)

View File

@ -16,6 +16,32 @@ for i, flag in pairs(ctf_flag.claimed) do
end
ctf_flag.collect_claimed()
minetest.register_on_joinplayer(function(player)
if ctf.team(ctf.player(player:get_player_name()).team) then
return
end
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
if alloc_mode == 0 then
return
end
local name = player:get_player_name()
local team = ctf.autoalloc(name, alloc_mode)
if team then
ctf.log("autoalloc", name .. " was allocated to " .. team)
ctf.join(name, team)
local spawn = ctf.get_spawn(team)
if spawn then
player:moveto(spawn, false)
end
end
end)
minetest.register_on_leaveplayer(function(player)
ctf.remove_player(player:get_player_name())
end)
ctf.register_on_new_game(function()
ctf.log("flash", "Setting up new game!")