diff options
Diffstat (limited to 'hunger.lua')
-rw-r--r-- | hunger.lua | 44 |
1 files changed, 39 insertions, 5 deletions
@@ -1,4 +1,35 @@ -function hud.item_eat(hunger_change, replace_with_item) +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 +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 + +end + +local function poisenp(tick, time, time_left, player) + time_left = time_left + tick + if time_left < time then + minetest.after(tick, poisenp, tick, time, time_left, player) + end + if player:get_hp()-1 > 0 then + player:set_hp(player:get_hp()-1) + end + +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()]) @@ -8,15 +39,18 @@ function hud.item_eat(hunger_change, replace_with_item) hud.save_hunger(user) itemstack:add_item(replace_with_item) -- note: replace_with_item is optional --sound:eat + if poisen then + poisenp(1.0, poisen, 0, user) + end end return itemstack end end -local function overwrite(name, hunger_change, replace_with_item) +local function overwrite(name, hunger_change, replace_with_item, poisen) local tab = minetest.registered_items[name] if tab == nil then return end - tab.on_use = hud.item_eat(hunger_change)--, replace_with_item) + tab.on_use = hud.item_eat(hunger_change, replace_with_item, poisen) minetest.registered_items[name] = tab end @@ -58,8 +92,8 @@ if minetest.get_modpath("animalmaterials") ~= nil then overwrite("animalmaterials:meat_chicken", 3) overwrite("animalmaterials:meat_lamb", 3) overwrite("animalmaterials:meat_venison", 3) - --overwrite("animalmaterials:meat_undead", 3)-- -3 damage - --overwrite("animalmaterials:meat_toxic", 3)-- -5 damage + overwrite("animalmaterials:meat_undead", 3, "", 3) + overwrite("animalmaterials:meat_toxic", 3, "", 5) overwrite("animalmaterials:meat_ostrich", 3) overwrite("animalmaterials:fish_bluewhite", 2) overwrite("animalmaterials:fish_clownfish", 2) |