mirror of
git://repo.or.cz/minetest_hbhunger.git
synced 2024-12-23 08:20:20 +01:00
Add global vars for satiation config
This commit is contained in:
parent
2aa0470907
commit
d408a67cdb
@ -89,9 +89,9 @@ function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound
|
|||||||
)
|
)
|
||||||
|
|
||||||
-- Saturation
|
-- Saturation
|
||||||
if h < 30 and hunger_change then
|
if h < hbhunger.SAT_MAX and hunger_change then
|
||||||
h = h + hunger_change
|
h = h + hunger_change
|
||||||
if h > 30 then h = 30 end
|
if h > hbhunger.SAT_MAX then h = hbhunger.SAT_MAX end
|
||||||
hbhunger.hunger[name] = h
|
hbhunger.hunger[name] = h
|
||||||
hbhunger.set_hunger_raw(user)
|
hbhunger.set_hunger_raw(user)
|
||||||
end
|
end
|
||||||
|
15
init.lua
15
init.lua
@ -25,6 +25,9 @@ hbhunger.EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
|
|||||||
hbhunger.EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
|
hbhunger.EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
|
||||||
hbhunger.EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
|
hbhunger.EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
|
||||||
hbhunger.EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
|
hbhunger.EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
|
||||||
|
hbhunger.SAT_MAX = 30 -- maximum satiation points
|
||||||
|
hbhunger.SAT_INIT = 20 -- initial satiation points
|
||||||
|
hbhunger.SAT_HEAL = 15 -- required satiation points to start healing
|
||||||
|
|
||||||
|
|
||||||
--load custom settings
|
--load custom settings
|
||||||
@ -42,7 +45,7 @@ dofile(minetest.get_modpath("hbhunger").."/hunger.lua")
|
|||||||
dofile(minetest.get_modpath("hbhunger").."/register_foods.lua")
|
dofile(minetest.get_modpath("hbhunger").."/register_foods.lua")
|
||||||
|
|
||||||
-- register satiation hudbar
|
-- register satiation hudbar
|
||||||
hb.register_hudbar("satiation", 0xFFFFFF, S("Satiation"), { icon = "hbhunger_icon.png", bgicon = "hbhunger_bgicon.png", bar = "hbhunger_bar.png" }, 20, 30, false, nil, { format_value = "%.1f", format_max_value = "%d" })
|
hb.register_hudbar("satiation", 0xFFFFFF, S("Satiation"), { icon = "hbhunger_icon.png", bgicon = "hbhunger_bgicon.png", bar = "hbhunger_bar.png" }, hbhunger.SAT_INIT, hbhunger.SAT_MAX, false, nil, { format_value = "%.1f", format_max_value = "%d" })
|
||||||
|
|
||||||
-- update hud elemtens if value has changed
|
-- update hud elemtens if value has changed
|
||||||
local function update_hud(player)
|
local function update_hud(player)
|
||||||
@ -74,7 +77,7 @@ hbhunger.set_hunger_raw = function(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local value = hbhunger.hunger[name]
|
local value = hbhunger.hunger[name]
|
||||||
if not inv or not value then return nil end
|
if not inv or not value then return nil end
|
||||||
if value > 30 then value = 30 end
|
if value > hbhunger.SAT_MAX then value = hbhunger.SAT_MAX end
|
||||||
if value < 0 then value = 0 end
|
if value < 0 then value = 0 end
|
||||||
|
|
||||||
inv:set_stack("hunger", 1, ItemStack({name=":", count=value+1}))
|
inv:set_stack("hunger", 1, ItemStack({name=":", count=value+1}))
|
||||||
@ -97,7 +100,7 @@ end)
|
|||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
-- reset hunger (and save)
|
-- reset hunger (and save)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
hbhunger.hunger[name] = 20
|
hbhunger.hunger[name] = hbhunger.SAT_INIT
|
||||||
hbhunger.set_hunger_raw(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
hbhunger.exhaustion[name] = 0
|
hbhunger.exhaustion[name] = 0
|
||||||
end)
|
end)
|
||||||
@ -117,10 +120,10 @@ minetest.register_globalstep(function(dtime)
|
|||||||
local h = tonumber(hbhunger.hunger[name])
|
local h = tonumber(hbhunger.hunger[name])
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
if timer > 4 then
|
if timer > 4 then
|
||||||
-- heal player by 1 hp if not dead and satiation is > 15 (of 30)
|
-- heal player by 1 hp if not dead and satiation is > hbhunger.SAT_HEAL
|
||||||
if h > 15 and hp > 0 and player:get_breath() > 0 then
|
if h > hbhunger.SAT_HEAL and hp > 0 and player:get_breath() > 0 then
|
||||||
player:set_hp(hp+1)
|
player:set_hp(hp+1)
|
||||||
-- or damage player by 1 hp if satiation is < 2 (of 30)
|
-- or damage player by 1 hp if satiation is < 2
|
||||||
elseif h <= 1 then
|
elseif h <= 1 then
|
||||||
if hp-1 >= 0 then player:set_hp(hp-1) end
|
if hp-1 >= 0 then player:set_hp(hp-1) end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user