diff --git a/mods/capturetheflag/ctf/hud.lua b/mods/capturetheflag/ctf/hud.lua index a94f599..c80faad 100644 --- a/mods/capturetheflag/ctf/hud.lua +++ b/mods/capturetheflag/ctf/hud.lua @@ -15,6 +15,20 @@ function hudkit() return true end, + exists = function(self, player, id) + if not player then + return false + end + + local name = player:get_player_name() + local elements = self.players[name] + + if not elements or not elements[id] then + return false + end + return true + end, + change = function(self, player, id, stat, value) if not player then return false @@ -55,12 +69,12 @@ function ctf.hud.update(player) return end + -- Team Identifier local color = ctf.flag_colors[ctf.team(player_data.team).data.color] if not color then color = "0x000000" end - - if not ctf.hud:change(player, "ctf:hud_team", "text", player_data.team) then + if not ctf.hud:exists(player, "ctf:hud_team") then return ctf.hud:add(player, "ctf:hud_team", { hud_elem_type = "text", position = {x = 1, y = 0}, @@ -70,23 +84,29 @@ function ctf.hud.update(player) offset = {x=-100, y = 20} }) else + ctf.hud:change(player, "ctf:hud_team", "text", player_data.team) ctf.hud:change(player, "ctf:hud_team", "number", color) end end local count = 0 +function ctf.hud.updateAll() + count = 0 + + if not ctf.setting_bool("hud") then + return + end + + local players = minetest.get_connected_players() + + for i = 1, #players do + ctf.hud.update(players[i]) + end +end minetest.register_globalstep(function(delta) count = count + delta if count > 10 then - if not ctf.setting_bool("hud") then - return - end - count = 0 - local players = minetest.get_connected_players() - - for i = 1, #players do - ctf.hud.update(players[i]) - end + ctf.hud.updateAll() end end)