From d10a36295ce34c6f2381bb3ca898826064e89672 Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Tue, 16 Apr 2024 16:52:38 -0400 Subject: [PATCH] mods - mobs - fix nil when stop mob attacking if player isnt seen when explote * the positionits not set cos the mobs is not attacking in such time seems there is a small amount of time that the actionis not true * the stop is only after double check , but must be after first also * backported from https://codeberg.org/minenux/minetest-mod-mobs_redo/commit/e82e0fa9cc4883f4fc31ea9bc2f08064185fec27 --- mods/mobs/api.lua | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua index 5a8a179..e46728c 100644 --- a/mods/mobs/api.lua +++ b/mods/mobs/api.lua @@ -2560,38 +2560,44 @@ function mob_class:do_states(dtime) if not self.attack:get_pos() or self.attack:get_hp() <= 0 and is_invisible(self, self.attack:get_player_name()) then --print(" ** stop attacking **", self.name, self.health, dist, self.view_range) self:stop_attack() + return + end + if not p then + self:stop_attack() + return end - self:stop_attack() - return end -- check enemy is in sight - local in_sight = self:line_of_sight( - {x = s.x, y = s.y + 0.5, z = s.z}, - {x = p.x, y = p.y + 0.5, z = p.z}) + local in_sight + if p then + in_sight = self:line_of_sight( + {x = s.x, y = s.y + 0.5, z = s.z}, + {x = p.x, y = p.y + 0.5, z = p.z}) - -- stop attacking when enemy not seen for 11 seconds - if not in_sight then + -- stop attacking when enemy not seen for 11 seconds + if not in_sight then - self.target_time_lost = (self.target_time_lost or 0) + dtime + self.target_time_lost = (self.target_time_lost or 0) + dtime - if self.target_time_lost > self.attack_patience then - self:stop_attack() + if self.target_time_lost > self.attack_patience then + self:stop_attack() + end + else + self.target_time_lost = 0 end - else - self.target_time_lost = 0 end if self.attack_type == "explode" then - self:yaw_to_pos(p) + if p then self:yaw_to_pos(p) end local node_break_radius = self.explosion_radius or 1 local entity_damage_radius = self.explosion_damage_radius or (node_break_radius * 2) -- look a little higher to fix raycast - s.y = s.y + 0.5 ; p.y = p.y + 0.5 + if p then s.y = s.y + 0.5 ; p.y = p.y + 0.5 end -- start timer when in reach and line of sight if not self.v_start