Fix team spawn on new player

master
rubenwardy 2015-07-17 19:25:20 +01:00
parent 17e7a2b529
commit 9196eec940
2 changed files with 32 additions and 36 deletions

View File

@ -339,23 +339,25 @@ function ctf.get_spawn(team)
end
end
minetest.register_on_respawnplayer(function(player)
if not player then
return false
end
local name = player:get_player_name()
local team = ctf.player(name).team
if ctf.team(team) then
local spawn = ctf.get_spawn(team)
function ctf.move_to_spawn(name)
local player = minetest.get_player_by_name(name)
local tplayer = ctf.player(name)
if ctf.team(tplayer.team) then
local spawn = ctf.get_spawn(tplayer.team)
if spawn then
player:moveto(spawn, false)
return true
end
end
return false
end
minetest.register_on_respawnplayer(function(player)
if not player then
return false
end
return ctf.move_to_spawn(player:get_player_name())
end)
function ctf.get_territory_owner(pos)
@ -386,11 +388,7 @@ minetest.register_on_newplayer(function(player)
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
ctf.move_to_spawn(player:get_player_name())
end
end)
@ -400,20 +398,20 @@ minetest.register_on_joinplayer(function(player)
return
end
local name = player:get_player_name()
if ctf.team(ctf.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
ctf.move_to_spawn(player:get_player_name())
end
end)

View File

@ -186,20 +186,18 @@ ctf_flag = {
-- add flag
ctf_flag.add(team, pos)
if ctf.teams[team].spawn and minetest.get_node(ctf.teams[team].spawn).name == "ctf_flag:flag" then
if not ctf.setting("flag.allow_multiple") then
-- send message
minetest.chat_send_all(team.."'s flag has been moved")
minetest.set_node(ctf.team(team).spawn,{name="air"})
minetest.set_node({
x=ctf.team(team).spawn.x,
y=ctf.team(team).spawn.y+1,
z=ctf.team(team).spawn.z
},{name="air"})
ctf.team(team).spawn = pos
end
else
ctf.get_spawn(team)
if ctf.teams[team].spawn and not ctf.setting("flag.allow_multiple") and
minetest.get_node(ctf.teams[team].spawn).name ==
"ctf_flag:flag" then
-- send message
minetest.chat_send_all(team.."'s flag has been moved")
minetest.set_node(ctf.team(team).spawn,{name="air"})
minetest.set_node({
x=ctf.team(team).spawn.x,
y=ctf.team(team).spawn.y+1,
z=ctf.team(team).spawn.z
},{name="air"})
ctf.team(team).spawn = pos
end
ctf.needs_save = true