9 local armor_hud_bg
= {}
13 --load custom settings
14 local set
= io
.open(minetest
.get_modpath("hbarmor").."/hud.conf", "r")
16 dofile(minetest
.get_modpath("hbarmor").."/hud.conf")
20 local function custom_hud(player
)
21 local name
= player
:get_player_name()
23 if minetest
.setting_getbool("enable_damage") then
24 hb
.init_hudbar(player
, "armor")
28 --register and define armor HUD bar
29 hb
.register_hudbar("armor", 0xFFFFFF, "Armor", { icon
= "hbarmor_icon.png", bar
= "hbarmor_bar.png" }, 0, 100, true, "%s: %d%%")
31 --needs to be defined for older version of 3darmor
32 function hud
.set_armor()
36 dofile(minetest
.get_modpath("hbarmor").."/armor.lua")
38 -- update hud elemtens if value has changed
39 local function update_hud(player
)
40 local name
= player
:get_player_name()
42 local arm_out
= tonumber(hud
.armor_out
[name
])
43 if not arm_out
then arm_out
= 0 end
44 local arm
= tonumber(hud
.armor
[name
])
45 if not arm
then arm
= 0 end
46 if arm_out
~= arm
then
47 hud
.armor_out
[name
] = arm
48 local arm_displayed
= math
.ceil(math
.floor(arm
+0.5))
49 hb
.change_hudbar(player
, "armor", arm_displayed
)
50 -- hide armor bar completely when there is none
51 if (not armor
.def
[name
].count
or armor
.def
[name
].count
== 0) and arm
== 0 then
52 hb
.hide_hudbar(player
, "armor")
54 hb
.unhide_hudbar(player
, "armor")
59 minetest
.register_on_joinplayer(function(player
)
60 local name
= player
:get_player_name()
62 hud
.armor_out
[name
] = 0
66 minetest
.register_on_respawnplayer(function(player
)
71 minetest
.after(2.5, function()
72 minetest
.register_globalstep(function(dtime
)
73 main_timer
= main_timer
+ dtime
75 if main_timer
> HUD_TICK
or timer
> 4 then
76 if main_timer
> HUD_TICK
then main_timer
= 0 end
77 for _
,player
in ipairs(minetest
.get_connected_players()) do
78 local name
= player
:get_player_name()
80 -- only proceed if damage is enabled
81 if minetest
.setting_getbool("enable_damage") then
84 -- update all hud elements
91 if timer
> 4 then timer
= 0 end