From 9196eec940eb25ea55b9b95dee729dd66f5ae61b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 17 Jul 2015 19:25:20 +0100 Subject: [PATCH] Fix team spawn on new player --- ctf/teams.lua | 42 ++++++++++++++++++++---------------------- ctf_flag/flag_func.lua | 26 ++++++++++++-------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/ctf/teams.lua b/ctf/teams.lua index 16759e4..88f3e3e 100644 --- a/ctf/teams.lua +++ b/ctf/teams.lua @@ -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) diff --git a/ctf_flag/flag_func.lua b/ctf_flag/flag_func.lua index 497b874..f13c519 100644 --- a/ctf_flag/flag_func.lua +++ b/ctf_flag/flag_func.lua @@ -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