Fix crash caused by lack of luaentity nil check and minetest 5.6
This commit is contained in:
parent
c8ecf77255
commit
d4d89c5cc4
41
mummy.lua
41
mummy.lua
@ -284,20 +284,23 @@ MUMMY_DEF.on_step = function(self, dtime)
|
|||||||
if self.state == 1 then
|
if self.state == 1 then
|
||||||
self.yawwer = true
|
self.yawwer = true
|
||||||
self.attacker = ""
|
self.attacker = ""
|
||||||
for _,object in ipairs(minetest.get_objects_inside_radius(self.object:get_pos(), 4)) do
|
local pos_obj = self.object:get_pos()
|
||||||
if object:is_player() then
|
if pos_obj then
|
||||||
self.yawwer = false
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos_obj, 4)) do
|
||||||
local NPC = self.object:get_pos()
|
if object:is_player() then
|
||||||
local PLAYER = object:get_pos()
|
self.yawwer = false
|
||||||
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
|
local NPC = self.object:get_pos()
|
||||||
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
local PLAYER = object:get_pos()
|
||||||
if PLAYER.x > NPC.x then
|
self.vec = {x=PLAYER.x-NPC.x, y=PLAYER.y-NPC.y, z=PLAYER.z-NPC.z}
|
||||||
self.yaw = self.yaw + math.pi
|
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
||||||
end
|
if PLAYER.x > NPC.x then
|
||||||
self.yaw = self.yaw - 2
|
self.yaw = self.yaw + math.pi
|
||||||
self.object:set_yaw(self.yaw)
|
end
|
||||||
self.attacker = object
|
self.yaw = self.yaw - 2
|
||||||
end
|
self.object:set_yaw(self.yaw)
|
||||||
|
self.attacker = object
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.attacker == "" and self.turn_timer > math.random(1,4) then
|
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.turn_timer = 0
|
||||||
self.direction = {x = math.sin(self.yaw)*-1, y = -20, z = math.cos(self.yaw)}
|
self.direction = {x = math.sin(self.yaw)*-1, y = -20, z = math.cos(self.yaw)}
|
||||||
end
|
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
|
if self.npc_anim ~= ANIM_STAND then
|
||||||
self.anim = get_animations()
|
self.anim = get_animations()
|
||||||
self.object:set_animation({x=self.anim.stand_START,y=self.anim.stand_END}, mummy_animation_speed, mummy_animation_blend)
|
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.state == 2 then
|
||||||
|
|
||||||
if self.direction ~= nil 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
|
end
|
||||||
if self.turn_timer > math.random(1,4) and not self.attacker then
|
if self.turn_timer > math.random(1,4) and not self.attacker then
|
||||||
self.yaw = 360 * math.random()
|
self.yaw = 360 * math.random()
|
||||||
|
Loading…
Reference in New Issue
Block a user