forked from Mineclonia/Mineclonia
Reduce food level when exhaust>=4 and satur.=0
This commit is contained in:
parent
8114ecf263
commit
5252409326
|
@ -141,16 +141,33 @@ minetest.register_on_respawnplayer(function(player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mcl_hunger.exhaust(playername, increase)
|
function mcl_hunger.exhaust(playername, increase)
|
||||||
mcl_hunger.exhaustion[playername] = math.min(mcl_hunger.exhaustion[playername] + increase, 4.0)
|
local player = minetest.get_player_by_name(playername)
|
||||||
hb.change_hudbar(minetest.get_player_by_name(playername), "exhaustion", mcl_hunger.exhaustion[playername])
|
mcl_hunger.exhaustion[playername] = mcl_hunger.exhaustion[playername] + increase
|
||||||
|
if mcl_hunger.exhaustion[playername] >= 4.0 then
|
||||||
|
mcl_hunger.exhaustion[playername] = 0.0
|
||||||
|
local h = nil
|
||||||
|
local satuchanged = false
|
||||||
|
if mcl_hunger.saturation[playername] > 0.0 then
|
||||||
|
mcl_hunger.saturation[playername] = math.max(mcl_hunger.saturation[playername] - 1.0, 0.0)
|
||||||
|
satuchanged = true
|
||||||
|
end
|
||||||
|
if mcl_hunger.saturation[playername] < 0.0001 then
|
||||||
|
h = mcl_hunger.get_hunger_raw(player)
|
||||||
|
h = h-1
|
||||||
|
mcl_hunger.hunger[playername] = h
|
||||||
|
mcl_hunger.set_hunger_raw(player)
|
||||||
|
satuchanged = true
|
||||||
|
end
|
||||||
|
if satuchanged then
|
||||||
|
hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], h)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
hb.change_hudbar(player, "exhaustion", mcl_hunger.exhaustion[playername])
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_hunger.saturate(playername, increase)
|
function mcl_hunger.saturate(playername, increase)
|
||||||
local player = minetest.get_player_by_name(playername)
|
local player = minetest.get_player_by_name(playername)
|
||||||
mcl_hunger.saturation[playername] = mcl_hunger.saturation[playername] + increase
|
mcl_hunger.saturation[playername] = math.min(mcl_hunger.saturation[playername] + increase, mcl_hunger.get_hunger(player))
|
||||||
if mcl_hunger.saturation[playername] > mcl_hunger.get_hunger(player) then
|
|
||||||
mcl_hunger.saturation[playername] = mcl_hunger.get_hunger(player)
|
|
||||||
end
|
|
||||||
hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], mcl_hunger.get_hunger(player))
|
hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], mcl_hunger.get_hunger(player))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -188,24 +205,6 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if h > 0 then
|
|
||||||
if mcl_hunger.exhaustion[name] >= 4.0 then
|
|
||||||
if mcl_hunger.saturation[name] > 0.0 then
|
|
||||||
mcl_hunger.saturation[name] = math.max(mcl_hunger.saturation[name] - 1.0, 0.0)
|
|
||||||
mcl_hunger.exhaustion[name] = 0.0
|
|
||||||
hb.change_hudbar(player, "exhaustion", mcl_hunger.exhaustion[name])
|
|
||||||
hb.change_hudbar(player, "saturation", mcl_hunger.saturation[name])
|
|
||||||
elseif timerMult == 0 then
|
|
||||||
h = h-1
|
|
||||||
mcl_hunger.hunger[name] = h
|
|
||||||
mcl_hunger.set_hunger_raw(player)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- update all hud elements
|
|
||||||
update_hud(player)
|
|
||||||
|
|
||||||
local controls = player:get_player_control()
|
local controls = player:get_player_control()
|
||||||
-- Determine if the player is moving
|
-- Determine if the player is moving
|
||||||
if controls.up or controls.down or controls.left or controls.right then
|
if controls.up or controls.down or controls.left or controls.right then
|
||||||
|
@ -216,6 +215,14 @@ minetest.register_globalstep(function(dtime)
|
||||||
if controls.jump then
|
if controls.jump then
|
||||||
mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_JUMP)
|
mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_JUMP)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Reduce hunter if 0 saturation
|
||||||
|
if timerMult == 0 and h > 0 and mcl_hunger.saturation[name] < 0.0001 then
|
||||||
|
end
|
||||||
|
|
||||||
|
-- update all hud elements
|
||||||
|
update_hud(player)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue