From 9fb42bd469d665cfab4f2e23cb14efe11c44b3f7 Mon Sep 17 00:00:00 2001 From: BlockMen Date: Mon, 14 Apr 2014 06:02:42 +0200 Subject: Abuse inv for hunger, no heal while drowning no file flood anymore 8) --- hunger.lua | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'hunger.lua') 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 -- cgit v1.2.3