HudKit: add exists()
This commit is contained in:
parent
70f1dddbbb
commit
00cfdc5109
@ -15,6 +15,20 @@ function hudkit()
|
|||||||
return true
|
return true
|
||||||
end,
|
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)
|
change = function(self, player, id, stat, value)
|
||||||
if not player then
|
if not player then
|
||||||
return false
|
return false
|
||||||
@ -55,12 +69,12 @@ function ctf.hud.update(player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Team Identifier
|
||||||
local color = ctf.flag_colors[ctf.team(player_data.team).data.color]
|
local color = ctf.flag_colors[ctf.team(player_data.team).data.color]
|
||||||
if not color then
|
if not color then
|
||||||
color = "0x000000"
|
color = "0x000000"
|
||||||
end
|
end
|
||||||
|
if not ctf.hud:exists(player, "ctf:hud_team") then
|
||||||
if not ctf.hud:change(player, "ctf:hud_team", "text", player_data.team) then
|
|
||||||
return ctf.hud:add(player, "ctf:hud_team", {
|
return ctf.hud:add(player, "ctf:hud_team", {
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
position = {x = 1, y = 0},
|
position = {x = 1, y = 0},
|
||||||
@ -70,23 +84,29 @@ function ctf.hud.update(player)
|
|||||||
offset = {x=-100, y = 20}
|
offset = {x=-100, y = 20}
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
|
ctf.hud:change(player, "ctf:hud_team", "text", player_data.team)
|
||||||
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = 0
|
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)
|
minetest.register_globalstep(function(delta)
|
||||||
count = count + delta
|
count = count + delta
|
||||||
|
|
||||||
if count > 10 then
|
if count > 10 then
|
||||||
if not ctf.setting_bool("hud") then
|
ctf.hud.updateAll()
|
||||||
return
|
|
||||||
end
|
|
||||||
count = 0
|
|
||||||
local players = minetest.get_connected_players()
|
|
||||||
|
|
||||||
for i = 1, #players do
|
|
||||||
ctf.hud.update(players[i])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user