forked from mtcontrib/minetest_hbarmor
Change global variable names
This commit is contained in:
parent
8941d98e38
commit
112f791291
@ -5,18 +5,18 @@ minetest.after(0, function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function hud.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
|
return
|
||||||
end
|
end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local def = armor.def[name] or nil
|
local def = armor.def[name] or nil
|
||||||
if def and def.state and def.count then
|
if def and def.state and def.count then
|
||||||
hud.set_armor(name, def.state, def.count)
|
hbarmor.set_armor(name, def.state, def.count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function hud.set_armor(player_name, ges_state, items)
|
function hbarmor.set_armor(player_name, ges_state, items)
|
||||||
local max_items = 4
|
local max_items = 4
|
||||||
if items == 5 then
|
if items == 5 then
|
||||||
max_items = items
|
max_items = items
|
||||||
@ -28,7 +28,7 @@ function hud.set_armor(player_name, ges_state, items)
|
|||||||
lvl = 0
|
lvl = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
hud.armor[player_name] = lvl* (items * (100 / max_items))
|
hbarmor.armor[player_name] = lvl* (items * (100 / max_items))
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
36
init.lua
36
init.lua
@ -1,20 +1,20 @@
|
|||||||
hud = {}
|
hbarmor = {}
|
||||||
|
|
||||||
-- HUD statbar values
|
-- HUD statbar values
|
||||||
hud.armor = {}
|
hbarmor.armor = {}
|
||||||
|
|
||||||
-- Stores if player's HUD bar has been initialized so far.
|
-- Stores if player's HUD bar has been initialized so far.
|
||||||
hud.player_active = {}
|
hbarmor.player_active = {}
|
||||||
|
|
||||||
-- HUD item ids
|
-- HUD item ids
|
||||||
local armor_hud = {}
|
local armor_hud = {}
|
||||||
|
|
||||||
HUD_TICK = 0.1
|
hbarmor.tick = 0.1
|
||||||
|
|
||||||
--load custom settings
|
--load custom settings
|
||||||
local set = io.open(minetest.get_modpath("hbarmor").."/hud.conf", "r")
|
local set = io.open(minetest.get_modpath("hbarmor").."/hbarmor.conf", "r")
|
||||||
if set then
|
if set then
|
||||||
dofile(minetest.get_modpath("hbarmor").."/hud.conf")
|
dofile(minetest.get_modpath("hbarmor").."/hbarmor.conf")
|
||||||
set:close()
|
set:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ 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
|
||||||
local arm = tonumber(hud.armor[name])
|
local arm = tonumber(hbarmor.armor[name])
|
||||||
if not arm then arm = 0 end
|
if not arm then arm = 0 end
|
||||||
local hide = must_hide(name, arm)
|
local hide = must_hide(name, arm)
|
||||||
hb.init_hudbar(player, "armor", arm_printable(arm), nil, hide)
|
hb.init_hudbar(player, "armor", arm_printable(arm), nil, hide)
|
||||||
@ -40,10 +40,6 @@ end
|
|||||||
--register and define armor HUD bar
|
--register and define armor HUD bar
|
||||||
hb.register_hudbar("armor", 0xFFFFFF, "Armor", { icon = "hbarmor_icon.png", bar = "hbarmor_bar.png" }, 0, 100, true, "%s: %d%%")
|
hb.register_hudbar("armor", 0xFFFFFF, "Armor", { icon = "hbarmor_icon.png", bar = "hbarmor_bar.png" }, 0, 100, true, "%s: %d%%")
|
||||||
|
|
||||||
--needs to be defined for older version of 3darmor
|
|
||||||
function hud.set_armor()
|
|
||||||
end
|
|
||||||
|
|
||||||
dofile(minetest.get_modpath("hbarmor").."/armor.lua")
|
dofile(minetest.get_modpath("hbarmor").."/armor.lua")
|
||||||
|
|
||||||
|
|
||||||
@ -51,10 +47,10 @@ dofile(minetest.get_modpath("hbarmor").."/armor.lua")
|
|||||||
local function update_hud(player)
|
local function update_hud(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
--armor
|
--armor
|
||||||
local arm = tonumber(hud.armor[name])
|
local arm = tonumber(hbarmor.armor[name])
|
||||||
if not arm then
|
if not arm then
|
||||||
arm = 0
|
arm = 0
|
||||||
hud.armor[name] = 0
|
hbarmor.armor[name] = 0
|
||||||
end
|
end
|
||||||
-- hide armor bar completely when there is none
|
-- hide armor bar completely when there is none
|
||||||
if must_hide(name, arm) then
|
if must_hide(name, arm) then
|
||||||
@ -67,14 +63,14 @@ end
|
|||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
hud.armor[name] = 0
|
hbarmor.armor[name] = 0
|
||||||
custom_hud(player)
|
custom_hud(player)
|
||||||
hud.player_active[name] = true
|
hbarmor.player_active[name] = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
hud.player_active[name] = false
|
hbarmor.player_active[name] = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local main_timer = 0
|
local main_timer = 0
|
||||||
@ -82,13 +78,13 @@ local timer = 0
|
|||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
main_timer = main_timer + dtime
|
main_timer = main_timer + dtime
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if main_timer > HUD_TICK or timer > 4 then
|
if main_timer > hbarmor.tick or timer > 4 then
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
if main_timer > HUD_TICK then main_timer = 0 end
|
if main_timer > hbarmor.tick then main_timer = 0 end
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if hud.player_active[name] == true then
|
if hbarmor.player_active[name] == true then
|
||||||
hud.get_armor(player)
|
hbarmor.get_armor(player)
|
||||||
|
|
||||||
-- update all hud elements
|
-- update all hud elements
|
||||||
update_hud(player)
|
update_hud(player)
|
||||||
|
Loading…
Reference in New Issue
Block a user