From dbd4f2b515ce1c0ae8f4e787813b8278eb9bee4e Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 8 Aug 2021 02:21:21 +0200 Subject: [PATCH] Teach NPCs how to heal themselves --- mods/mobs/mob_npc.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/mobs/mob_npc.lua b/mods/mobs/mob_npc.lua index c9e5844..cb8dcd5 100644 --- a/mods/mobs/mob_npc.lua +++ b/mods/mobs/mob_npc.lua @@ -118,8 +118,20 @@ for _, npc_type_table in pairs(npc_types) do punch_start = 200, punch_end = 219, }, + do_custom = function(self) + -- Slowly heal NPC over time + self.healing_counter = self.healing_counter + 1 + if self.healing_counter >= 10 then + local hp = self.object:get_hp() + hp = math.min(20, hp + 1) + self.object:set_hp(hp) + local hp = self.object:get_hp() + self.healing_counter = 0 + end + end, on_spawn = function(self) self.npc_type = npc_type + self.healing_counter = 0 end, on_rightclick = function(self, clicker) local item = clicker:get_wielded_item()