diff --git a/ctf/core.lua b/ctf/core.lua index fd26182..f898e9d 100644 --- a/ctf/core.lua +++ b/ctf/core.lua @@ -244,7 +244,6 @@ minetest.after(10, ctf.check_save) function ctf.save() local file = io.open(minetest.get_worldpath().."/ctf.txt", "w") - ctf.needs_save = false if file then local out = { teams = ctf.teams, @@ -263,6 +262,7 @@ function ctf.save() file:write(minetest.serialize(out)) file:close() + ctf.needs_save = false else ctf.error("io", "CTF file failed to save!") end diff --git a/ctf/hud.lua b/ctf/hud.lua index 09c17fb..32da7f9 100644 --- a/ctf/hud.lua +++ b/ctf/hud.lua @@ -8,6 +8,12 @@ minetest.register_on_leaveplayer(function(player) ctf.hud.players[player:get_player_name()] = nil end) +ctf.register_on_join_team(function(name, tname) + if ctf.setting("hud") then + ctf.hud.update(minetest.get_player_by_name(name)) + end +end) + function ctf.hud.update(player) if not player then return diff --git a/ctf/teams.lua b/ctf/teams.lua index 30a2903..96ac1f3 100644 --- a/ctf/teams.lua +++ b/ctf/teams.lua @@ -126,6 +126,14 @@ function ctf.remove_player(name) end end +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) @@ -184,10 +192,9 @@ function ctf.join(name, team, force, by) minetest.log("action", name .. " joined team " .. team) minetest.chat_send_all(name.." has joined team "..team) - if ctf.setting("hud") then - ctf.hud.update(minetest.get_player_by_name(name)) + for i = 1, #ctf.registered_on_join_team do + ctf.registered_on_join_team[i](name, team) end - return true end