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

Commit

Permalink
Fix healing (death, drowning), pipeworks issue and HUD issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Jul 14, 2015
1 parent 30fea24 commit 63d6fe2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
30 changes: 19 additions & 11 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
return
end
local name = player:get_player_name()
if not name or not hunger[name] then
return
end

local exhaus = hunger[name].exhaus
if not exhaus then
hunger[name].exhaus = 0
Expand Down Expand Up @@ -96,12 +100,13 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
hunger[name].exhaus = exhaus
end


-- Time based hunger functions
if minetest.setting_getbool("enable_damage") then
local hunger_timer = 0
local health_timer = 0
local action_timer = 0
minetest.register_globalstep(function(dtime)
local hunger_timer = 0
local health_timer = 0
local action_timer = 0

local function hunger_globaltimer(dtime)
hunger_timer = hunger_timer + dtime
health_timer = health_timer + dtime
action_timer = action_timer + dtime
Expand Down Expand Up @@ -141,8 +146,8 @@ if minetest.setting_getbool("enable_damage") then
local air = player:get_breath() or 0
local hp = player:get_hp()

-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
if tonumber(tab.lvl) > HUNGER_HEAL_LVL and air > 0 then
-- heal player by 1 hp if not dead and saturation is > 15 (of 30) player is not drowning
if tonumber(tab.lvl) > HUNGER_HEAL_LVL and hp > 0 and air > 0 then
player:set_hp(hp + HUNGER_HEAL)
end

Expand All @@ -155,7 +160,10 @@ if minetest.setting_getbool("enable_damage") then

health_timer = 0
end
end)
end

if minetest.setting_getbool("enable_damage") then
minetest.register_globalstep(hunger_globaltimer)
end


Expand All @@ -166,9 +174,9 @@ function hunger.register_food(name, hunger_change, replace_with_item, poisen, he
food[name] = {}
food[name].saturation = hunger_change -- hunger points added
food[name].replace = replace_with_item -- what item is given back after eating
food[name].poisen = poisen -- time its poisening
food[name].healing = heal -- amount of HP
food[name].sound = sound -- special sound that is played when eating
food[name].poisen = poisen -- time its poisening
food[name].healing = heal -- amount of HP
food[name].sound = sound -- special sound that is played when eating
end

-- Poison player
Expand Down
10 changes: 5 additions & 5 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
hunger = {}
hunger.food = {}

HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
HUNGER_HEALTH_TICK = 4 -- time in seconds after player gets healed/damaged
HUNGER_MOVE_TICK = 0.5 -- time in seconds after the movement is checked

Expand All @@ -10,12 +10,12 @@ HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
HUNGER_EXHAUST_MOVE = 1.5 -- exhaustion increased this value if player movement detected
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player saturation gets lowered

HUNGER_HEAL = 1 -- number of HP player gets healed after HUNGER_HEALTH_TICK
HUNGER_HEAL = 1 -- number of HP player gets healed after HUNGER_HEALTH_TICK
HUNGER_HEAL_LVL = 15 -- lower level of saturation needed to get healed
HUNGER_STARVE = 1 -- number of HP player gets damaged by hunger after HUNGER_HEALTH_TICK
HUNGER_STARVE = 1 -- number of HP player gets damaged by hunger after HUNGER_HEALTH_TICK
HUNGER_STARVE_LVL = 3 -- level of staturation that causes starving

HUNGER_MAX = 30 -- maximum level of saturation
HUNGER_MAX = 30 -- maximum level of saturation


local modpath = minetest.get_modpath("hunger")
Expand All @@ -39,7 +39,7 @@ if minetest.setting_getbool("enable_damage") then
lvl = 20
end
minetest.after(0.8, function()
hud.change_item(player, "hunger", {offset = "item", item_name = "air"})
hud.swap_statbar(player, "hunger", "air")
hud.change_item(player, "hunger", {number = lvl, max = 20})
end)
end)
Expand Down

0 comments on commit 63d6fe2

Please sign in to comment.