forked from mtcontrib/minetest_hbarmor
More cleanup
This commit is contained in:
parent
0e18630d41
commit
2061c1bbf8
18
init.lua
18
init.lua
@ -3,6 +3,9 @@ hud = {}
|
|||||||
-- HUD statbar values
|
-- HUD statbar values
|
||||||
hud.armor = {}
|
hud.armor = {}
|
||||||
|
|
||||||
|
-- Stores if player's HUD bar has been initialized so far.
|
||||||
|
hud.player_active = {}
|
||||||
|
|
||||||
-- HUD item ids
|
-- HUD item ids
|
||||||
local armor_hud = {}
|
local armor_hud = {}
|
||||||
|
|
||||||
@ -49,20 +52,29 @@ local function update_hud(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
--armor
|
--armor
|
||||||
local arm = tonumber(hud.armor[name])
|
local arm = tonumber(hud.armor[name])
|
||||||
if not arm then arm = 0 end
|
if not arm then
|
||||||
|
arm = 0
|
||||||
|
hud.armor[name] = 0
|
||||||
|
end
|
||||||
-- hide armor bar completely when there is none
|
-- hide armor bar completely when there is none
|
||||||
if must_hide(name, arm) then
|
if must_hide(name, arm) then
|
||||||
hb.hide_hudbar(player, "armor")
|
hb.hide_hudbar(player, "armor")
|
||||||
else
|
else
|
||||||
|
hb.change_hudbar(player, "armor", arm_printable(arm))
|
||||||
hb.unhide_hudbar(player, "armor")
|
hb.unhide_hudbar(player, "armor")
|
||||||
end
|
end
|
||||||
hb.change_hudbar(player, "armor", arm_printable(arm))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
hud.armor[name] = 0
|
hud.armor[name] = 0
|
||||||
custom_hud(player)
|
custom_hud(player)
|
||||||
|
hud.player_active[name] = true
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
hud.player_active[name] = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
@ -80,6 +92,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
|
|
||||||
-- only proceed if damage is enabled
|
-- only proceed if damage is enabled
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
|
if hud.player_active[name] == true then
|
||||||
hud.get_armor(player)
|
hud.get_armor(player)
|
||||||
|
|
||||||
-- update all hud elements
|
-- update all hud elements
|
||||||
@ -87,5 +100,6 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if timer > 4 then timer = 0 end
|
if timer > 4 then timer = 0 end
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user