From f0f3f5c0b3accb34cdeb0f61636f0911eee6094c Mon Sep 17 00:00:00 2001 From: Elkien3 Date: Sun, 25 Jun 2017 20:48:02 -0500 Subject: [PATCH] Fixed player join/leave Fixed both saving new recruits, and also the /teamleave function --- ctf/teams.lua | 14 +++++++++++++- ctf_chat/init.lua | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ctf/teams.lua b/ctf/teams.lua index 22fa03d..670439b 100644 --- a/ctf/teams.lua +++ b/ctf/teams.lua @@ -125,6 +125,7 @@ function ctf.remove_player(name) team.players[name] = nil end ctf.players[name] = nil + ctf.needs_save = true return true else return false @@ -139,6 +140,16 @@ function ctf.register_on_join_team(func) table.insert(ctf.registered_on_join_team, func) end +-- Player joins team +-- Called by /join, /team join or auto allocate. +ctf.registered_on_join_team = {} +function ctf.register_on_join_team(func) + if ctf._mt_loaded then + error("You can't register callbacks at game time!") + end + table.insert(ctf.registered_on_join_team, func) +end + -- Player joins team -- Called by /join, /team join or auto allocate. function ctf.join(name, team, force, by) @@ -193,10 +204,11 @@ function ctf.join(name, team, force, by) player.team = team team_data.players[player.name] = player + + ctf.needs_save = true minetest.log("action", name .. " joined team " .. team) minetest.chat_send_all(name.." has joined team "..team) - minetest.get_player_privs(name).initial_team_join = false for i = 1, #ctf.registered_on_join_team do ctf.registered_on_join_team[i](name, team) diff --git a/ctf_chat/init.lua b/ctf_chat/init.lua index b3706e5..c94baa2 100644 --- a/ctf_chat/init.lua +++ b/ctf_chat/init.lua @@ -185,8 +185,8 @@ minetest.register_chatcommand("teamleave", { description = "Leave your team", func = function(name, param) local team = ctf.player(name).team - if ctf.player(param).team ~= nil then - if ctf.remove_player(param) then + if ctf.player(name).team ~= nil then + if ctf.remove_player(name) then return true, "You have left " .. team .. "!" else return false, "Failed to leave " .. team.. "!"