forked from mtcontrib/minetest_hbarmor
Move all code to init.lua
This commit is contained in:
parent
a493641f02
commit
72aeb873d0
32
armor.lua
32
armor.lua
@ -1,32 +0,0 @@
|
||||
if (not armor) or (not armor.def) then
|
||||
minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
|
||||
end
|
||||
|
||||
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
|
||||
return false
|
||||
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.min(lvl* (items * (100 / max_items)), 100)
|
||||
end
|
34
init.lua
34
init.lua
@ -5,6 +5,10 @@ else
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
if (not armor) or (not armor.def) then
|
||||
minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
|
||||
end
|
||||
|
||||
local hbarmor = {}
|
||||
|
||||
-- HUD statbar values
|
||||
@ -63,13 +67,39 @@ 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%%"))
|
||||
|
||||
dofile(minetest.get_modpath("hbarmor").."/armor.lua")
|
||||
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
|
||||
return false
|
||||
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.min(lvl* (items * (100 / max_items)), 100)
|
||||
end
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
local function update_hud(player)
|
||||
local name = player:get_player_name()
|
||||
--armor
|
||||
--armor
|
||||
local arm = tonumber(hbarmor.armor[name])
|
||||
if not arm then
|
||||
arm = 0
|
||||
|
Loading…
Reference in New Issue
Block a user