From 6a0a9b30d4781fb697d4266b97b85f804477dc13 Mon Sep 17 00:00:00 2001 From: ElCeejo Date: Wed, 3 Aug 2022 23:36:23 -0700 Subject: [PATCH] Fix code --- api.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/api.lua b/api.lua index a016d49..0c286d1 100644 --- a/api.lua +++ b/api.lua @@ -439,12 +439,14 @@ end function creatura.basic_punch_func(self, puncher, tflp, tool_caps, dir) if not puncher then return end - local tool = "" + local tool + local tool_name = "" if puncher:is_player() then - tool = puncher:get_wielded_item():get_name() + tool = puncher:get_wielded_item() + tool_name = tool:get_name() end if (self.immune_to - and is_value_in_table(self.immune_to, tool)) then + and is_value_in_table(self.immune_to, tool_name)) then return end self:apply_knockback(dir, 8) @@ -459,10 +461,11 @@ function creatura.basic_punch_func(self, puncher, tflp, tool_caps, dir) } end self:hurt(tool_caps.damage_groups.fleshy) - local wear = floor((tool_caps.damage_groups.full_punch_interval / 75) * 9000) - local tool = puncher:get_wielded_item() - tool:add_wear(wear) - puncher:set_wielded_item(tool) + if tool then + local wear = floor((tool_caps.damage_groups.full_punch_interval / 75) * 9000) + tool:add_wear(wear) + puncher:set_wielded_item(tool) + end if random(4) < 2 then self:play_sound("hurt") end