Fix crash caused by lack of luaentity nil check and minetest 5.6

This commit is contained in:
bri cassa 2022-09-04 19:00:44 +02:00
parent c8ecf77255
commit d4d89c5cc4

View File

@ -284,20 +284,23 @@ MUMMY_DEF.on_step = function(self, dtime)
if self.state == 1 then
self.yawwer = true
self.attacker = ""
for _,object in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 4)) do
if object:is_player() then
self.yawwer = false
local NPC = self.object:get_pos()
local PLAYER = object:get_pos()
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if PLAYER.x > NPC.x then
self.yaw = self.yaw + math.pi
end
self.yaw = self.yaw - 2
self.object:set_yaw(self.yaw)
self.attacker = object
end
local pos_obj = self.object:get_pos()
if pos_obj then
for _,object in ipairs(minetest.get_objects_inside_radius(pos_obj, 4)) do
if object:is_player() then
self.yawwer = false
local NPC = self.object:get_pos()
local PLAYER = object:get_pos()
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if PLAYER.x > NPC.x then
self.yaw = self.yaw + math.pi
end
self.yaw = self.yaw - 2
self.object:set_yaw(self.yaw)
self.attacker = object
end
end
end
if self.attacker == "" and self.turn_timer > math.random(1,4) then
@ -306,7 +309,8 @@ MUMMY_DEF.on_step = function(self, dtime)
self.turn_timer = 0
self.direction = {x = math.sin(self.yaw)*-1, y = -20, z = math.cos(self.yaw)}
end
self.object:set_velocity({x=0,y=self.object:get_velocity().y,z=0})
local old_vel = self.object:get_velocity()
self.object:set_velocity({x=0,y=old_vel and old_vel.y or 0,z=0})
if self.npc_anim ~= ANIM_STAND then
self.anim = get_animations()
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, mummy_animation_speed, mummy_animation_blend)
@ -321,7 +325,12 @@ MUMMY_DEF.on_step = function(self, dtime)
if self.state == 2 then
if self.direction ~= nil then
self.object:set_velocity({x=self.direction.x*mummy_chillaxin_speed,y=self.object:get_velocity().y,z=self.direction.z*mummy_chillaxin_speed})
local old_vel = self.object:get_velocity()
self.object:set_velocity({
x=self.direction.x*mummy_chillaxin_speed,
y=old_vel and old_vel.y or 0,
z=self.direction.z*mummy_chillaxin_speed,
})
end
if self.turn_timer > math.random(1,4) and not self.attacker then
self.yaw = 360 * math.random()