forked from LizzyFleckenstein03/Memeclone
Display armor points properly
This commit is contained in:
parent
2e6610da42
commit
e3b68c4364
|
@ -1,3 +0,0 @@
|
||||||
hudbars
|
|
||||||
3d_armor
|
|
||||||
intllib?
|
|
|
@ -1,9 +1,4 @@
|
||||||
local S
|
local S = minetest.get_translator("hbarmor")
|
||||||
if (minetest.get_modpath("intllib")) then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function ( s ) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
if (not armor) or (not armor.def) then
|
if (not armor) or (not armor.def) then
|
||||||
minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
|
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)
|
local ret = hbarmor.get_armor(player)
|
||||||
if ret == false then
|
if ret == false then
|
||||||
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in custom_hud returned with false!")
|
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in custom_hud returned with false!")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
local arm = tonumber(hbarmor.armor[name])
|
local arm = tonumber(hbarmor.armor[name])
|
||||||
if not arm then arm = 0 end
|
if not arm then
|
||||||
|
arm = 0
|
||||||
|
end
|
||||||
local hide
|
local hide
|
||||||
if hbarmor.autohide then
|
if hbarmor.autohide then
|
||||||
hide = must_hide(name, arm)
|
hide = must_hide(name, arm)
|
||||||
|
@ -65,35 +63,24 @@ local function custom_hud(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
--register and define armor HUD bar
|
--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)
|
function hbarmor.get_armor(player)
|
||||||
if not player or not armor.def then
|
if not player or not armor.def then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local def = armor.def[name] or nil
|
local pts = armor:get_armor_points(player)
|
||||||
if def and def.state and def.count then
|
if not pts then
|
||||||
hbarmor.set_armor(name, def.state, def.count)
|
|
||||||
else
|
|
||||||
return false
|
return false
|
||||||
|
else
|
||||||
|
hbarmor.set_armor(name, pts)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function hbarmor.set_armor(player_name, ges_state, items)
|
function hbarmor.set_armor(player_name, pts)
|
||||||
local max_items = 4
|
hbarmor.armor[player_name] = math.max(0, math.min(20, pts))
|
||||||
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))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update hud elemtens if value has changed
|
-- update hud elemtens if value has changed
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
# textdomain:hbarmor
|
||||||
Armor=Panzerung
|
Armor=Panzerung
|
||||||
%s: %d%%=%s: %d%%
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
# textdomain:hbarmor
|
||||||
Armor=Armadura
|
Armor=Armadura
|
||||||
%s: %d%%=%s: %d%%
|
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
|
# textdomain:hbarmor
|
||||||
Armor=Armatura
|
Armor=Armatura
|
||||||
|
|
||||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
|
||||||
%s: %d%%=%s: %d%%
|
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
|
# textdomain:hbarmor
|
||||||
Armor=
|
Armor=
|
||||||
|
|
||||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
|
||||||
%s: %d%%=
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
name = hbarmor
|
name = hbarmor
|
||||||
|
depends = hudbars, 3d_armor
|
||||||
|
|
|
@ -205,7 +205,7 @@ armor.get_armor_points = function(self, player)
|
||||||
for i=1, 6 do
|
for i=1, 6 do
|
||||||
local stack = player_inv:get_stack("armor", i)
|
local stack = player_inv:get_stack("armor", i)
|
||||||
if stack:get_count() > 0 then
|
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
|
if p then
|
||||||
pts = pts + p
|
pts = pts + p
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue