2013-06-28 22:58:06 +02:00
|
|
|
hud = {}
|
|
|
|
|
2014-04-06 16:33:38 +02:00
|
|
|
-- HUD statbar values
|
|
|
|
hud.armor = {}
|
|
|
|
hud.armor_out = {}
|
|
|
|
|
|
|
|
-- HUD item ids
|
2013-09-13 20:18:16 +02:00
|
|
|
local armor_hud = {}
|
2014-04-06 18:31:56 +02:00
|
|
|
local armor_hud_bg = {}
|
2013-06-28 22:58:06 +02:00
|
|
|
|
2014-05-13 18:59:08 +02:00
|
|
|
HUD_TICK = 0.1
|
2014-10-03 08:12:55 +02:00
|
|
|
|
2014-04-14 06:02:42 +02:00
|
|
|
--load custom settings
|
2015-02-24 01:55:07 +01:00
|
|
|
local set = io.open(minetest.get_modpath("hbarmor").."/hud.conf", "r")
|
2013-07-20 22:07:24 +02:00
|
|
|
if set then
|
2015-02-24 01:55:07 +01:00
|
|
|
dofile(minetest.get_modpath("hbarmor").."/hud.conf")
|
2013-07-20 22:07:24 +02:00
|
|
|
set:close()
|
|
|
|
end
|
2013-06-28 22:58:06 +02:00
|
|
|
|
2014-04-14 06:02:42 +02:00
|
|
|
local function custom_hud(player)
|
2014-04-06 18:31:56 +02:00
|
|
|
local name = player:get_player_name()
|
2013-07-20 14:02:30 +02:00
|
|
|
|
2013-06-28 23:03:54 +02:00
|
|
|
if minetest.setting_getbool("enable_damage") then
|
2015-02-24 02:02:45 +01:00
|
|
|
hb.init_hudbar(player, "armor")
|
2013-06-28 23:03:54 +02:00
|
|
|
end
|
2013-06-28 22:58:06 +02:00
|
|
|
end
|
|
|
|
|
2015-02-24 02:02:45 +01:00
|
|
|
--register and define armor HUD bar
|
2015-02-24 02:52:26 +01:00
|
|
|
hb.register_hudbar("armor", 0xFFFFFF, "Armor", { icon = "hbarmor_icon.png", bar = "hbarmor_bar.png" }, 0, 100, true, "%s: %d%%")
|
2015-02-24 02:02:45 +01:00
|
|
|
|
2014-04-06 16:33:38 +02:00
|
|
|
--needs to be defined for older version of 3darmor
|
2013-09-13 20:18:16 +02:00
|
|
|
function hud.set_armor()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-02-24 01:55:07 +01:00
|
|
|
dofile(minetest.get_modpath("hbarmor").."/armor.lua")
|
2013-09-13 20:18:16 +02:00
|
|
|
|
2014-04-06 16:33:38 +02:00
|
|
|
-- update hud elemtens if value has changed
|
2013-06-28 22:58:06 +02:00
|
|
|
local function update_hud(player)
|
2014-04-06 16:33:38 +02:00
|
|
|
local name = player:get_player_name()
|
2013-09-13 20:18:16 +02:00
|
|
|
--armor
|
2014-04-06 16:33:38 +02:00
|
|
|
local arm_out = tonumber(hud.armor_out[name])
|
|
|
|
if not arm_out then arm_out = 0 end
|
|
|
|
local arm = tonumber(hud.armor[name])
|
2013-09-13 20:18:16 +02:00
|
|
|
if not arm then arm = 0 end
|
2014-04-06 16:33:38 +02:00
|
|
|
if arm_out ~= arm then
|
|
|
|
hud.armor_out[name] = arm
|
2015-02-24 02:52:26 +01:00
|
|
|
local arm_displayed = math.ceil(math.floor(arm+0.5))
|
|
|
|
hb.change_hudbar(player, "armor", arm_displayed)
|
2014-04-14 06:02:42 +02:00
|
|
|
-- hide armor bar completely when there is none
|
2014-04-06 18:31:56 +02:00
|
|
|
if (not armor.def[name].count or armor.def[name].count == 0) and arm == 0 then
|
2015-02-24 02:02:45 +01:00
|
|
|
hb.hide_hudbar(player, "armor")
|
2014-04-06 18:31:56 +02:00
|
|
|
else
|
2015-02-24 02:02:45 +01:00
|
|
|
hb.unhide_hudbar(player, "armor")
|
2014-04-06 18:31:56 +02:00
|
|
|
end
|
2014-04-06 16:33:38 +02:00
|
|
|
end
|
2013-06-28 22:58:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2014-04-06 16:33:38 +02:00
|
|
|
local name = player:get_player_name()
|
|
|
|
hud.armor[name] = 0
|
|
|
|
hud.armor_out[name] = 0
|
2015-02-24 01:55:07 +01:00
|
|
|
custom_hud(player)
|
2013-06-28 22:58:06 +02:00
|
|
|
end)
|
|
|
|
|
2013-09-09 03:16:18 +02:00
|
|
|
minetest.register_on_respawnplayer(function(player)
|
|
|
|
end)
|
|
|
|
|
2014-04-14 06:51:28 +02:00
|
|
|
local main_timer = 0
|
2013-06-28 22:58:06 +02:00
|
|
|
local timer = 0
|
|
|
|
minetest.after(2.5, function()
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2014-04-14 06:51:28 +02:00
|
|
|
main_timer = main_timer + dtime
|
2013-07-20 22:07:24 +02:00
|
|
|
timer = timer + dtime
|
2015-02-24 01:55:07 +01:00
|
|
|
if main_timer > HUD_TICK or timer > 4 then
|
2014-04-14 11:16:58 +02:00
|
|
|
if main_timer > HUD_TICK then main_timer = 0 end
|
2014-04-14 06:51:28 +02:00
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
2014-04-06 16:33:38 +02:00
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
-- only proceed if damage is enabled
|
2013-07-27 12:09:14 +02:00
|
|
|
if minetest.setting_getbool("enable_damage") then
|
2015-02-24 01:55:07 +01:00
|
|
|
hud.get_armor(player)
|
2014-04-06 16:33:38 +02:00
|
|
|
|
|
|
|
-- update all hud elements
|
2013-07-27 12:09:14 +02:00
|
|
|
update_hud(player)
|
2014-10-03 08:12:55 +02:00
|
|
|
|
2013-06-28 22:58:06 +02:00
|
|
|
end
|
2014-04-14 06:51:28 +02:00
|
|
|
end
|
2014-04-06 16:33:38 +02:00
|
|
|
|
2014-04-14 06:51:28 +02:00
|
|
|
end
|
2014-04-06 16:33:38 +02:00
|
|
|
if timer > 4 then timer = 0 end
|
2013-06-28 22:58:06 +02:00
|
|
|
end)
|
|
|
|
end)
|