diff options
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 94 |
1 files changed, 54 insertions, 40 deletions
@@ -4,12 +4,15 @@ local health_hud = {} hud.hunger = {} local hunger_hud = {} local air_hud = {} -local inv_hud = {} +hud.armor = {} +local armor_hud = {} local SAVE_INTERVAL = 0.5*60--currently useless --default settings HUD_ENABLE_HUNGER = minetest.setting_getbool("hud_hunger_enable") +HUD_SHOW_ARMOR = false +if minetest.get_modpath("3d_armor") ~= nil then HUD_SHOW_ARMOR = true end if HUD_ENABLE_HUNGER == nil then HUD_ENABLE_HUNGER = minetest.setting_getbool("enable_damage") end HUD_HUNGER_TICK = 300 HUD_HEALTH_POS = {x=0.5,y=0.9} @@ -18,6 +21,8 @@ HUD_HUNGER_POS = {x=0.5,y=0.9} HUD_HUNGER_OFFSET = {x=15, y=2} HUD_AIR_POS = {x=0.5,y=0.9} HUD_AIR_OFFSET = {x=15,y=-15} +HUD_ARMOR_POS = {x=0.5,y=0.9} +HUD_ARMOR_OFFSET = {x=-175, y=-15} --load costum settings local set = io.open(minetest.get_modpath("hud").."/hud.conf", "r") @@ -93,40 +98,63 @@ local function costum_hud(player) position = HUD_AIR_POS, scale = {x=1, y=1}, text = "hud_air_fg.png", - number = 20, + number = 0, alignment = {x=-1,y=-1}, offset = HUD_AIR_OFFSET, }) + + --armor + if HUD_SHOW_ARMOR then + player:hud_add({ + hud_elem_type = "statbar", + position = HUD_ARMOR_POS, + scale = {x=1, y=1}, + text = "hud_armor_bg.png", + number = 20, + alignment = {x=-1,y=-1}, + offset = HUD_ARMOR_OFFSET, + }) + + armor_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = HUD_ARMOR_POS, + scale = {x=1, y=1}, + text = "hud_armor_fg.png", + number = 0, + alignment = {x=-1,y=-1}, + offset = HUD_ARMOR_OFFSET, + }) + end end end +--needs to be set always(for 3darmor) +function hud.set_armor() +end + + +if HUD_ENABLE_HUNGER then dofile(minetest.get_modpath("hud").."/hunger.lua") end +if HUD_SHOW_ARMOR then dofile(minetest.get_modpath("hud").."/armor.lua") end + local function update_hud(player) ---health + --air + local air = player:get_breath()*2 + if player:get_breath() > 10 then air = 0 end + player:hud_change(air_hud[player:get_player_name()], "number", air) + --health player:hud_change(health_hud[player:get_player_name()], "number", player:get_hp()) ---hunger + --armor + local arm = tonumber(hud.armor[player:get_player_name()]) + if not arm then arm = 0 end + player:hud_change(armor_hud[player:get_player_name()], "number", arm) + --hunger local h = tonumber(hud.hunger[player:get_player_name()]) if h>20 then h=20 end player:hud_change(hunger_hud[player:get_player_name()], "number", h) end -local function update_fast(player) ---air - local air = player:get_breath()*2 - if player:get_breath() >= 11 then air = 0 end - player:hud_change(air_hud[player:get_player_name()], "number", air) -end - - -function hud.save_hunger(player) - local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "w+") - if file then - file:write(hud.hunger[player:get_player_name()]) - file:close() - end -end - local function timer(interval, player) if interval > 0 then hud.save_hunger(player) @@ -134,35 +162,23 @@ local function timer(interval, player) end end -local function load_hunger(player) - local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "r") - if file then - hud.hunger[player:get_player_name()] = file:read("*all") - file:close() - return hud.hunger[player:get_player_name()] - else - return - end - -end - - minetest.register_on_joinplayer(function(player) - hud.hunger[player:get_player_name()] = load_hunger(player) - if hud.hunger[player:get_player_name()] == nil then + hud.armor[player:get_player_name()] = 0 + if HUD_ENABLE_HUNGER then hud.hunger[player:get_player_name()] = hud.load_hunger(player) end + if not hud.hunger[player:get_player_name()] then hud.hunger[player:get_player_name()] = 20 end minetest.after(0.5, function() - hud.save_hunger(player) hide_builtin(player) costum_hud(player) + if HUD_ENABLE_HUNGER then hud.save_hunger(player) end end) end) minetest.register_on_respawnplayer(function(player) hud.hunger[player:get_player_name()] = 20 minetest.after(0.5, function() - hud.save_hunger(player) + if HUD_ENABLE_HUNGER then hud.save_hunger(player) end end) end) @@ -173,7 +189,6 @@ minetest.after(2.5, function() timer = timer + dtime timer2 = timer2 + dtime for _,player in ipairs(minetest.get_connected_players()) do - update_fast(player) if minetest.setting_getbool("enable_damage") then local h = tonumber(hud.hunger[player:get_player_name()]) if HUD_ENABLE_HUNGER and timer > 4 then @@ -190,6 +205,7 @@ minetest.after(2.5, function() hud.save_hunger(player) end end + if HUD_SHOW_ARMOR then hud.get_armor(player) end update_hud(player) end end @@ -197,5 +213,3 @@ minetest.after(2.5, function() if timer2>HUD_HUNGER_TICK then timer2=0 end end) end) - -if HUD_ENABLE_HUNGER then dofile(minetest.get_modpath("hud").."/hunger.lua") end |