HudKit: add exists()
This commit is contained in:
parent
70f1dddbbb
commit
00cfdc5109
@ -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
|
||||
minetest.register_globalstep(function(delta)
|
||||
count = count + delta
|
||||
function ctf.hud.updateAll()
|
||||
count = 0
|
||||
|
||||
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
|
||||
end
|
||||
minetest.register_globalstep(function(delta)
|
||||
count = count + delta
|
||||
|
||||
if count > 10 then
|
||||
ctf.hud.updateAll()
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user