forked from mtcontrib/minetest_hbarmor
Display armor level via HUD bar
This commit is contained in:
parent
31fa8317e8
commit
dcbcc1b1df
28
init.lua
28
init.lua
@ -21,27 +21,13 @@ local function custom_hud(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
armor_hud_bg[name] = player:hud_add({
|
hb.init_hudbar(player, "armor")
|
||||||
hud_elem_type = "statbar",
|
|
||||||
position = HUD_ARMOR_POS,
|
|
||||||
size = HUD_SIZE,
|
|
||||||
text = "hud_armor_bg.png",
|
|
||||||
number = 0,
|
|
||||||
alignment = {x=-1,y=-1},
|
|
||||||
offset = HUD_ARMOR_OFFSET,
|
|
||||||
})
|
|
||||||
armor_hud[name] = player:hud_add({
|
|
||||||
hud_elem_type = "statbar",
|
|
||||||
position = HUD_ARMOR_POS,
|
|
||||||
size = HUD_SIZE,
|
|
||||||
text = "hud_armor_fg.png",
|
|
||||||
number = 0,
|
|
||||||
alignment = {x=-1,y=-1},
|
|
||||||
offset = HUD_ARMOR_OFFSET,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--register and define armor HUD bar
|
||||||
|
hb.register_hudbar("armor", 0xFFFFFF, "Armor", { icon = "hbarmor_icon.png", bar = "hbarmor_bar.png" }, 0, 20, false, "%s: %d/%d")
|
||||||
|
|
||||||
--needs to be defined for older version of 3darmor
|
--needs to be defined for older version of 3darmor
|
||||||
function hud.set_armor()
|
function hud.set_armor()
|
||||||
end
|
end
|
||||||
@ -59,12 +45,12 @@ local function update_hud(player)
|
|||||||
if not arm then arm = 0 end
|
if not arm then arm = 0 end
|
||||||
if arm_out ~= arm then
|
if arm_out ~= arm then
|
||||||
hud.armor_out[name] = arm
|
hud.armor_out[name] = arm
|
||||||
player:hud_change(armor_hud[name], "number", arm)
|
hb.change_hudbar(player, "armor", arm)
|
||||||
-- hide armor bar completely when there is none
|
-- hide armor bar completely when there is none
|
||||||
if (not armor.def[name].count or armor.def[name].count == 0) and arm == 0 then
|
if (not armor.def[name].count or armor.def[name].count == 0) and arm == 0 then
|
||||||
player:hud_change(armor_hud_bg[name], "number", 0)
|
hb.hide_hudbar(player, "armor")
|
||||||
else
|
else
|
||||||
player:hud_change(armor_hud_bg[name], "number", 20)
|
hb.unhide_hudbar(player, "armor")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
BIN
textures/hbarmor_bar.png
Normal file
BIN
textures/hbarmor_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in New Issue
Block a user