summaryrefslogtreecommitdiff
path: root/hunger.lua
diff options
context:
space:
mode:
authorBlockMen <nmuelll@web.de>2014-04-14 06:02:42 +0200
committerBlockMen <nmuelll@web.de>2014-04-14 06:17:26 +0200
commit9fb42bd469d665cfab4f2e23cb14efe11c44b3f7 (patch)
tree6b0861790a40d95b609fab4ff3e47ca18e159435 /hunger.lua
parentd47b065d68cf9e7bd63bd4587668df3c75d2e3a9 (diff)
Abuse inv for hunger, no heal while drowning
no file flood anymore 8)
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