From 3eb7d27761006ecd1615be52f0a5aab2ec4cd1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Thu, 14 Sep 2017 21:16:56 +0200 Subject: [PATCH] Fix crash when searching npc --- client/main.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/main.lua b/client/main.lua index 09877334..861b4eaf 100644 --- a/client/main.lua +++ b/client/main.lua @@ -71,16 +71,20 @@ function GetRandomWalkingNPC() print('Using fallback code to find walking ped') - while true do + for i=1, 250, 1 do local ped = GetRandomPedAtCoord(0.0, 0.0, 0.0, math.huge + 0.0, math.huge + 0.0, math.huge + 0.0, 26) if DoesEntityExist(ped) and IsPedHuman(ped) and IsPedWalking(ped) and not IsPedAPlayer(ped) then - return ped + table.insert(search, ped) end end + if #search > 0 then + return search[GetRandomIntInRange(1, #search)] + end + end function ClearCurrentMission()