Fix healing (death, drowning), pipeworks issue and HUD issues
This commit is contained in:
parent
30fea241d0
commit
63d6fe2370
@ -65,6 +65,10 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
if not name or not hunger[name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local exhaus = hunger[name].exhaus
|
local exhaus = hunger[name].exhaus
|
||||||
if not exhaus then
|
if not exhaus then
|
||||||
hunger[name].exhaus = 0
|
hunger[name].exhaus = 0
|
||||||
@ -96,12 +100,13 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
|
|||||||
hunger[name].exhaus = exhaus
|
hunger[name].exhaus = exhaus
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Time based hunger functions
|
-- Time based hunger functions
|
||||||
if minetest.setting_getbool("enable_damage") then
|
local hunger_timer = 0
|
||||||
local hunger_timer = 0
|
local health_timer = 0
|
||||||
local health_timer = 0
|
local action_timer = 0
|
||||||
local action_timer = 0
|
|
||||||
minetest.register_globalstep(function(dtime)
|
local function hunger_globaltimer(dtime)
|
||||||
hunger_timer = hunger_timer + dtime
|
hunger_timer = hunger_timer + dtime
|
||||||
health_timer = health_timer + dtime
|
health_timer = health_timer + dtime
|
||||||
action_timer = action_timer + dtime
|
action_timer = action_timer + dtime
|
||||||
@ -141,8 +146,8 @@ if minetest.setting_getbool("enable_damage") then
|
|||||||
local air = player:get_breath() or 0
|
local air = player:get_breath() or 0
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
|
|
||||||
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
-- 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 air > 0 then
|
if tonumber(tab.lvl) > HUNGER_HEAL_LVL and hp > 0 and air > 0 then
|
||||||
player:set_hp(hp + HUNGER_HEAL)
|
player:set_hp(hp + HUNGER_HEAL)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -155,7 +160,10 @@ if minetest.setting_getbool("enable_damage") then
|
|||||||
|
|
||||||
health_timer = 0
|
health_timer = 0
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
if minetest.setting_getbool("enable_damage") then
|
||||||
|
minetest.register_globalstep(hunger_globaltimer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -166,9 +174,9 @@ function hunger.register_food(name, hunger_change, replace_with_item, poisen, he
|
|||||||
food[name] = {}
|
food[name] = {}
|
||||||
food[name].saturation = hunger_change -- hunger points added
|
food[name].saturation = hunger_change -- hunger points added
|
||||||
food[name].replace = replace_with_item -- what item is given back after eating
|
food[name].replace = replace_with_item -- what item is given back after eating
|
||||||
food[name].poisen = poisen -- time its poisening
|
food[name].poisen = poisen -- time its poisening
|
||||||
food[name].healing = heal -- amount of HP
|
food[name].healing = heal -- amount of HP
|
||||||
food[name].sound = sound -- special sound that is played when eating
|
food[name].sound = sound -- special sound that is played when eating
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Poison player
|
-- Poison player
|
||||||
|
10
init.lua
10
init.lua
@ -1,7 +1,7 @@
|
|||||||
hunger = {}
|
hunger = {}
|
||||||
hunger.food = {}
|
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_HEALTH_TICK = 4 -- time in seconds after player gets healed/damaged
|
||||||
HUNGER_MOVE_TICK = 0.5 -- time in seconds after the movement is checked
|
HUNGER_MOVE_TICK = 0.5 -- time in seconds after the movement is checked
|
||||||
|
|
||||||
@ -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_MOVE = 1.5 -- exhaustion increased this value if player movement detected
|
||||||
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player saturation gets lowered
|
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_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_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")
|
local modpath = minetest.get_modpath("hunger")
|
||||||
@ -39,7 +39,7 @@ if minetest.setting_getbool("enable_damage") then
|
|||||||
lvl = 20
|
lvl = 20
|
||||||
end
|
end
|
||||||
minetest.after(0.8, function()
|
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})
|
hud.change_item(player, "hunger", {number = lvl, max = 20})
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user