From 3b03af0ba1ddd15b9943d275c9d94206e1a0d1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D1=85=D0=B0=D1=80=D0=B4=20PICCORO=20Len?= =?UTF-8?q?z=20McKAY?= Date: Tue, 14 Jun 2022 13:05:05 -0400 Subject: [PATCH] better checks for nil on find method and player object * really closes https://notabug.org/TenPlus1/mobs_redo/issues/114 again * really closes #107 * nil checks * improve the previous commit f78202cf8e1d4ba59bbe57cf774d2ba26b69ffc3 --- api.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/api.lua b/api.lua index 947d4c8..1910237 100644 --- a/api.lua +++ b/api.lua @@ -272,17 +272,17 @@ local check_for = function(look_for, look_inside) if not str then goto continue end - if str == look_for then - return true + if str then + if str:find("group:") then + local group = str:split(":")[2] or "" + if minetest.get_item_group(look_for, group) ~= 0 then + return true + end + end end - if str and str:find("group:") then - - local group = str:split(":")[2] or "" - - if minetest.get_item_group(look_for, group) ~= 0 then - return true - end + if str == look_for then + return true end ::continue:: @@ -2120,12 +2120,12 @@ function mob_class:follow_flop() for n = 1, #players do - if players[n] and get_distance(players[n]:get_pos(), s) < self.view_range - and not is_invisible(self, players[n]:get_player_name()) then - - self.following = players[n] - - break + if players[n] then + if get_distance(players[n]:get_pos(), s) < self.view_range + and not is_invisible(self, players[n]:get_player_name()) then + self.following = players[n] + break + end end end end