summaryrefslogtreecommitdiff
path: root/hunger.lua
diff options
context:
space:
mode:
Diffstat (limited to 'hunger.lua')
-rw-r--r--hunger.lua28
1 files changed, 9 insertions, 19 deletions
diff --git a/hunger.lua b/hunger.lua
index 756d4ad..238ba90 100644
--- a/hunger.lua
+++ b/hunger.lua
@@ -1,23 +1,12 @@
+-- Keep these for backwards compatibility
function hud.save_hunger(player)
- local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "w+")
- if file then
- file:write(hud.hunger[player:get_player_name()])
- file:close()
- end
+ hud.set_hunger(player)
end
-
function hud.load_hunger(player)
- local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "r")
- if file then
- hud.hunger[player:get_player_name()] = file:read("*all")
- file:close()
- return hud.hunger[player:get_player_name()]
- else
- return
- end
-
+ hud.get_hunger(player)
end
+-- Poison player
local function poisenp(tick, time, time_left, player)
time_left = time_left + tick
if time_left < time then
@@ -31,12 +20,13 @@ end
function hud.item_eat(hunger_change, replace_with_item, poisen)
return function(itemstack, user, pointed_thing)
- if itemstack:take_item() ~= nil then
- local h = tonumber(hud.hunger[user:get_player_name()])
+ if itemstack:take_item() ~= nil and user ~= nil then
+ local name = user:get_player_name()
+ local h = tonumber(hud.hunger[name])
h=h+hunger_change
if h>30 then h=30 end
- hud.hunger[user:get_player_name()]=h
- hud.save_hunger(user)
+ hud.hunger[name]=h
+ hud.set_hunger(user)
itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
--sound:eat
if poisen then