mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-21 18:21:04 +01:00
Add defensive check (#4437)
This fixes #4436 and possible other unnoticed crashes by adding a defensive check. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4437 Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com> Co-authored-by: the-real-herowl <wiktor_t-i@proton.me> Co-committed-by: the-real-herowl <wiktor_t-i@proton.me>
This commit is contained in:
parent
35e14dd415
commit
72435933e4
1 changed files with 24 additions and 21 deletions
|
@ -802,34 +802,37 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- alert others to the attack
|
-- alert others to the attack
|
||||||
local objs = minetest.get_objects_inside_radius(hitter:get_pos(), self.view_range)
|
local alert_pos = hitter:get_pos()
|
||||||
local obj = nil
|
if alert_pos then
|
||||||
|
local objs = minetest.get_objects_inside_radius(alert_pos, self.view_range)
|
||||||
|
local obj = nil
|
||||||
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
obj = objs[n]:get_luaentity()
|
obj = objs[n]:get_luaentity()
|
||||||
|
|
||||||
if obj then
|
if obj then
|
||||||
-- only alert members of same mob or friends
|
-- only alert members of same mob or friends
|
||||||
if obj.group_attack
|
if obj.group_attack
|
||||||
and obj.state ~= "attack"
|
and obj.state ~= "attack"
|
||||||
and obj.owner ~= name then
|
and obj.owner ~= name then
|
||||||
if obj.name == self.name then
|
if obj.name == self.name then
|
||||||
obj:do_attack(hitter)
|
obj:do_attack(hitter)
|
||||||
elseif type(obj.group_attack) == "table" then
|
elseif type(obj.group_attack) == "table" then
|
||||||
for i=1, #obj.group_attack do
|
for i=1, #obj.group_attack do
|
||||||
if obj.group_attack[i] == self.name then
|
if obj.group_attack[i] == self.name then
|
||||||
obj._aggro = true
|
obj._aggro = true
|
||||||
obj:do_attack(hitter)
|
obj:do_attack(hitter)
|
||||||
break
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- have owned mobs attack player threat
|
-- have owned mobs attack player threat
|
||||||
if obj.owner == name and obj.owner_loyal then
|
if obj.owner == name and obj.owner_loyal then
|
||||||
obj:do_attack(self.object)
|
obj:do_attack(self.object)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue