Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Various fixes and mark as stable
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Sep 9, 2013
1 parent 030f30d commit 01e267e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
7 changes: 5 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Minetest mod "Better HUD"
=========================
version: 0.5 Beta
version: 1.0

License of source code: WTFPL
-----------------------------
Expand Down Expand Up @@ -35,8 +35,11 @@ Also it adds hunger to the game and and hunger bar to the HUD.

You can create a "hud.conf" to costumize the positions of health, hunger and breath bar. Take a look at "hud.conf.example" to get more infos.

!!NOTICE: Keep in mind if running a server with this mod, that the costum position should be displayed correct on every screen size!!


Hunger:
This mod adds hunger to the game. You can disable this by setting "HUD_HUNGER_ENABLE = false" in "hud.conf".
This mod adds hunger to the game. You can disable this by setting "HUD_HUNGER_ENABLE = false" in "hud.conf", or "hud_hunger_enable = false" in minetest.conf. In case of conflict hud.conf configuration is dominant.

Currently supported food:
- Apples (default)
Expand Down
10 changes: 9 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@
0.5 Beta
----------
- removed the fancy borders of hud inventory bar and moved to new native support
- moved crosshair to native support tooo
- moved crosshair to native support too

1.0
---
- hunger is reset after death
- health and hunger bar is shown correct on all screen resolutions now
- switched to changed native hotbar image support
- fixed revival of player when drown
- hunger bar is not shown anymore if hunger is disabled
- hunger can be disabled by minetest.conf ("hud_hunger_enable = false")
42 changes: 30 additions & 12 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ local inv_hud = {}
local SAVE_INTERVAL = 0.5*60--currently useless

--default settings
HUD_ENABLE_HUNGER = minetest.setting_getbool("enable_damage")
HUD_ENABLE_HUNGER = minetest.setting_getbool("hud_hunger_enable")
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=1}
HUD_HEALTH_OFFSET = {x=-175,y=-60}
HUD_HUNGER_POS = {x=0.5,y=1}
HUD_HUNGER_OFFSET = {x=15,y=-60}
HUD_AIR_POS = {x=0.5,y=1}
HUD_AIR_OFFSET = {x=15,y=-75}
HUD_HEALTH_POS = {x=0.5,y=0.9}
HUD_HEALTH_OFFSET = {x=-175, y=2}
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}

--load costum settings
local set = io.open(minetest.get_modpath("hud").."/hud.conf", "r")
if set then
dofile(minetest.get_modpath("hud").."/hud.conf")
set:close()
else
if not HUD_ENABLE_HUNGER then
HUD_AIR_OFFSET = {x=15,y=0}
end
end

--minetest.after(SAVE_INTERVAL, timer, SAVE_INTERVAL)
Expand All @@ -34,27 +39,33 @@ end

local function costum_hud(player)

--fancy hotbar
player:hud_set_hotbar_image("hud_hotbar.png")
player:hud_set_hotbar_selected_image("hud_hotbar_selected.png")

if minetest.setting_getbool("enable_damage") then
--hunger
player:hud_add({
if HUD_ENABLE_HUNGER then
player:hud_add({
hud_elem_type = "statbar",
position = HUD_HUNGER_POS,
scale = {x=1, y=1},
text = "hud_hunger_bg.png",
number = 20,
alignment = {x=-1,y=-1},
offset = HUD_HUNGER_OFFSET,
})
})

hunger_hud[player:get_player_name()] = player:hud_add({
hunger_hud[player:get_player_name()] = player:hud_add({
hud_elem_type = "statbar",
position = HUD_HUNGER_POS,
scale = {x=1, y=1},
text = "hud_hunger_fg.png",
number = 20,
alignment = {x=-1,y=-1},
offset = HUD_HUNGER_OFFSET,
})
})
end
--health
player:hud_add({
hud_elem_type = "statbar",
Expand Down Expand Up @@ -148,6 +159,13 @@ minetest.register_on_joinplayer(function(player)
end)
end)

minetest.register_on_respawnplayer(function(player)
hud.hunger[player:get_player_name()] = 20
minetest.after(0.5, function()
hud.save_hunger(player)
end)
end)

local timer = 0
local timer2 = 0
minetest.after(2.5, function()
Expand All @@ -159,7 +177,7 @@ minetest.after(2.5, function()
if minetest.setting_getbool("enable_damage") then
local h = tonumber(hud.hunger[player:get_player_name()])
if HUD_ENABLE_HUNGER and timer > 4 then
if h>=16 then
if h>=16 and player:get_hp() > 0 then
player:set_hp(player:get_hp()+1)
elseif h<=1 and minetest.setting_getbool("enable_damage") then
if player:get_hp()-1 >= 1 then player:set_hp(player:get_hp()-1) end
Expand Down
File renamed without changes
File renamed without changes

0 comments on commit 01e267e

Please sign in to comment.