forked from MineClone5/MineClone5
minor changes, ipairs() replaced with pairs()
This commit is contained in:
parent
2f05388541
commit
e82d21040c
|
@ -139,15 +139,9 @@ end)
|
||||||
|
|
||||||
local food_tick_timers = {} --one food_tick_timer per player, keys are the player-objects
|
local food_tick_timers = {} --one food_tick_timer per player, keys are the player-objects
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
local food_tick_timer = food_tick_timers[player]
|
|
||||||
if food_tick_timer == nil then
|
|
||||||
food_tick_timer = 0
|
|
||||||
else
|
|
||||||
food_tick_timer = food_tick_timer + dtime
|
|
||||||
end
|
|
||||||
|
|
||||||
|
local food_tick_timer = food_tick_timers[player] and food_tick_timers[player] + dtime or 0
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local food_level = mcl_hunger.get_hunger(player)
|
local food_level = mcl_hunger.get_hunger(player)
|
||||||
local food_saturation_level = mcl_hunger.get_saturation(player)
|
local food_saturation_level = mcl_hunger.get_saturation(player)
|
||||||
|
@ -157,15 +151,14 @@ minetest.register_globalstep(function(dtime)
|
||||||
food_tick_timer = 0
|
food_tick_timer = 0
|
||||||
|
|
||||||
if food_level >= 18 and player_health < 20 then --slow regenration
|
if food_level >= 18 and player_health < 20 then --slow regenration
|
||||||
food_tick_timer = 0
|
|
||||||
player:set_hp(player_health+1)
|
player:set_hp(player_health+1)
|
||||||
mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN)
|
mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN)
|
||||||
mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player))
|
mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player))
|
||||||
|
|
||||||
elseif food_level == 0 then --starvation
|
elseif food_level == 0 then --starvation
|
||||||
maximumStarvation = 1 --the amount of health at which a player will stop to get harmed by starvation (10 for Easy, 1 for Normal, 0 for Hard)
|
local maximum_starvation = 1 --the amount of health at which a player will stop to get harmed by starvation (10 for Easy, 1 for Normal, 0 for Hard)
|
||||||
-- TODO: implement Minecraft-like difficulty modes and the update maximumStarvation here
|
-- TODO: implement Minecraft-like difficulty modes and the update maximumStarvation here
|
||||||
if player_health > maximumStarvation then
|
if player_health > maximum_starvation then
|
||||||
mcl_util.deal_damage(player, 1, {type = "starve"})
|
mcl_util.deal_damage(player, 1, {type = "starve"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue