ctf_flash Remove player from team on leaveplayer
This commit is contained in:
parent
e536384f4e
commit
2328870dae
@ -23,7 +23,10 @@ function ctf.team(name)
|
|||||||
return ctf.teams[name.name]
|
return ctf.teams[name.name]
|
||||||
else
|
else
|
||||||
if not ctf.teams[name] then
|
if not ctf.teams[name] then
|
||||||
ctf.warning("team", dump(name) .. " does not exist!")
|
if name then
|
||||||
|
ctf.warning("team", dump(name) .. " does not exist!")
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
return ctf.teams[name]
|
return ctf.teams[name]
|
||||||
end
|
end
|
||||||
@ -97,6 +100,17 @@ function ctf.player_or_nil(name)
|
|||||||
return ctf.players[name]
|
return ctf.players[name]
|
||||||
end
|
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
|
-- Player joins team
|
||||||
-- Called by /join, /team join or auto allocate.
|
-- Called by /join, /team join or auto allocate.
|
||||||
function ctf.join(name, team, force, by)
|
function ctf.join(name, team, force, by)
|
||||||
|
@ -16,6 +16,32 @@ for i, flag in pairs(ctf_flag.claimed) do
|
|||||||
end
|
end
|
||||||
ctf_flag.collect_claimed()
|
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.register_on_new_game(function()
|
||||||
ctf.log("flash", "Setting up new game!")
|
ctf.log("flash", "Setting up new game!")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user