From 600eb6187ffb27f6000c8168b16f34c2b6fd7eeb Mon Sep 17 00:00:00 2001 From: Le_Docteur Date: Sun, 21 Jun 2015 11:43:48 +0200 Subject: [PATCH] Full health restoration for the NPC. --- mods/mobs/npc.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/mobs/npc.lua b/mods/mobs/npc.lua index ce8f1b94..8a623fc8 100755 --- a/mods/mobs/npc.lua +++ b/mods/mobs/npc.lua @@ -73,14 +73,21 @@ mobs:register_mob("mobs:npc", { or item:get_name() == "farming:bread" then -- feed and add health local hp = self.object:get_hp() - if hp + 4 > self.hp_max then return end - self.object:set_hp(hp+4) + -- return if full health + if hp >= self.hp_max then + minetest.chat_send_player(name, "NPC at full health.") + return + end + hp = hp + 4 -- add restorative value + -- new health shouldn't exceed self.hp_max + if hp > self.hp_max then hp = self.hp_max end + self.object:set_hp(hp) -- take item if not minetest.setting_getbool("creative_mode") then item:take_item() clicker:set_wielded_item(item) end - self.object:set_hp(hp + 4) + -- right clicking with gold lump drops random item from mobs.npc_drops elseif item:get_name() == "default:gold_lump" then if not minetest.setting_getbool("creative_mode") then