mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Display armor points properly
This commit is contained in:
parent
2e6610da42
commit
e3b68c4364
8 changed files with 18 additions and 37 deletions
|
@ -1,3 +0,0 @@
|
|||
hudbars
|
||||
3d_armor
|
||||
intllib?
|
|
@ -1,9 +1,4 @@
|
|||
local S
|
||||
if (minetest.get_modpath("intllib")) then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
local S = minetest.get_translator("hbarmor")
|
||||
|
||||
if (not armor) or (not armor.def) then
|
||||
minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
|
||||
|
@ -51,9 +46,12 @@ local function custom_hud(player)
|
|||
local ret = hbarmor.get_armor(player)
|
||||
if ret == false then
|
||||
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in custom_hud returned with false!")
|
||||
return
|
||||
end
|
||||
local arm = tonumber(hbarmor.armor[name])
|
||||
if not arm then arm = 0 end
|
||||
if not arm then
|
||||
arm = 0
|
||||
end
|
||||
local hide
|
||||
if hbarmor.autohide then
|
||||
hide = must_hide(name, arm)
|
||||
|
@ -65,35 +63,24 @@ local function custom_hud(player)
|
|||
end
|
||||
|
||||
--register and define armor HUD bar
|
||||
hb.register_hudbar("armor", 0xFFFFFF, S("Armor"), { icon = "hbarmor_icon.png", bgicon = "hbarmor_bgicon.png", bar = "hbarmor_bar.png" }, 0, 100, hbarmor.autohide, S("%s: %d%%"))
|
||||
hb.register_hudbar("armor", 0xFFFFFF, S("Armor"), { icon = "hbarmor_icon.png", bgicon = "hbarmor_bgicon.png", bar = "hbarmor_bar.png" }, 0, 20, hbarmor.autohide)
|
||||
|
||||
function hbarmor.get_armor(player)
|
||||
if not player or not armor.def then
|
||||
return false
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local def = armor.def[name] or nil
|
||||
if def and def.state and def.count then
|
||||
hbarmor.set_armor(name, def.state, def.count)
|
||||
else
|
||||
local pts = armor:get_armor_points(player)
|
||||
if not pts then
|
||||
return false
|
||||
else
|
||||
hbarmor.set_armor(name, pts)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function hbarmor.set_armor(player_name, ges_state, items)
|
||||
local max_items = 4
|
||||
if items == 5 then
|
||||
max_items = items
|
||||
end
|
||||
local max = max_items * 65535
|
||||
local lvl = max - ges_state
|
||||
lvl = lvl/max
|
||||
if ges_state == 0 and items == 0 then
|
||||
lvl = 0
|
||||
end
|
||||
|
||||
hbarmor.armor[player_name] = math.max(0, math.min(lvl* (items * (100 / max_items)), 100))
|
||||
function hbarmor.set_armor(player_name, pts)
|
||||
hbarmor.armor[player_name] = math.max(0, math.min(20, pts))
|
||||
end
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=Panzerung
|
||||
%s: %d%%=%s: %d%%
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=Armadura
|
||||
%s: %d%%=%s: %d%%
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=Armatura
|
||||
|
||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
||||
%s: %d%%=%s: %d%%
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=
|
||||
|
||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
||||
%s: %d%%=
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
name = hbarmor
|
||||
depends = hudbars, 3d_armor
|
||||
|
|
|
@ -205,7 +205,7 @@ armor.get_armor_points = function(self, player)
|
|||
for i=1, 6 do
|
||||
local stack = player_inv:get_stack("armor", i)
|
||||
if stack:get_count() > 0 then
|
||||
local p = stack:get_definition().groups.mcl_armor_points
|
||||
local p = minetest.get_item_group(stack:get_name(), "mcl_armor_points")
|
||||
if p then
|
||||
pts = pts + p
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue