mirror of
git://repo.or.cz/minetest_hbhunger.git
synced 2025-06-29 21:31:01 +02:00
Version MFF.
This commit is contained in:
39
init.lua
Normal file → Executable file
39
init.lua
Normal file → Executable file
@ -9,12 +9,12 @@ hbhunger.hunger_out = {}
|
||||
-- HUD item ids
|
||||
local hunger_hud = {}
|
||||
|
||||
HUNGER_HUD_TICK = 0.1
|
||||
HUNGER_HUD_TICK = 1.0
|
||||
|
||||
--Some hunger settings
|
||||
hbhunger.exhaustion = {} -- Exhaustion is experimental!
|
||||
|
||||
HUNGER_HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
|
||||
HUNGER_HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
|
||||
HUNGER_EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
|
||||
HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
|
||||
HUNGER_EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
|
||||
@ -23,7 +23,7 @@ HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
|
||||
|
||||
--load custom settings
|
||||
local set = io.open(minetest.get_modpath("hbhunger").."/hbhunger.conf", "r")
|
||||
if set then
|
||||
if set then
|
||||
dofile(minetest.get_modpath("hbhunger").."/hbhunger.conf")
|
||||
set:close()
|
||||
end
|
||||
@ -69,7 +69,7 @@ hbhunger.set_hunger = function(player)
|
||||
if not inv or not value then return nil end
|
||||
if value > 30 then value = 30 end
|
||||
if value < 0 then value = 0 end
|
||||
|
||||
|
||||
inv:set_stack("hunger", 1, ItemStack({name=":", count=value+1}))
|
||||
|
||||
return true
|
||||
@ -94,21 +94,26 @@ minetest.register_on_respawnplayer(function(player)
|
||||
hbhunger.exhaustion[name] = 0
|
||||
end)
|
||||
|
||||
local main_timer = 0
|
||||
local timer = 0
|
||||
local timer2 = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
main_timer = main_timer + dtime
|
||||
timer = timer + dtime
|
||||
timer2 = timer2 + dtime
|
||||
if main_timer > HUNGER_HUD_TICK or timer > 4 or timer2 > HUNGER_HUNGER_TICK then
|
||||
if main_timer > HUNGER_HUD_TICK then main_timer = 0 end
|
||||
local function hunger_step()
|
||||
timer = timer + HUNGER_HUD_TICK
|
||||
timer2 = timer2 + HUNGER_HUD_TICK
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
local h = tonumber(hbhunger.hunger[name])
|
||||
local hp = player:get_hp()
|
||||
if timer > 4 then
|
||||
local timerquot = 1 -- By default regen 0.5 hearth every 10sec
|
||||
|
||||
if pclasses.api.get_player_class(name) == "warrior" then
|
||||
timerquot = 1.42 -- Black_Mithril armor = 0.5 hearth every 7.0sec
|
||||
elseif pclasses.api.util.does_wear_full_armor(name, "mithril", false) then
|
||||
timerquot = 1.17 -- Mithril armor = 0.5 hearth every 8.5sec
|
||||
end
|
||||
|
||||
|
||||
if timer > 10/timerquot then
|
||||
-- heal player by 1 hp if not dead and satiation is > 15 (of 30)
|
||||
if h > 15 and hp > 0 and player:get_breath() > 0 then
|
||||
player:set_hp(hp+1)
|
||||
@ -128,16 +133,18 @@ minetest.register_globalstep(function(dtime)
|
||||
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
|
||||
|
||||
local controls = player:get_player_control()
|
||||
-- Determine if the player is walking
|
||||
if controls.up or controls.down or controls.left or controls.right then
|
||||
hbhunger.handle_node_actions(nil, nil, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
if timer > 4 then timer = 0 end
|
||||
--end
|
||||
if timer > 10 then timer = 0 end
|
||||
if timer2 > HUNGER_HUNGER_TICK then timer2 = 0 end
|
||||
end)
|
||||
minetest.after(HUNGER_HUD_TICK, hunger_step)
|
||||
end
|
||||
minetest.after(0, hunger_step)
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user