I’ve resorted to posting this because I have no idea how to get around this, it seems that the natives surrounding this just don’t work. (I’ve tried the GetRandomPedAtCoord with a small radius too, that doesn’t work)
So as of now, this is my code:
function getAllPeds()
local peds = {}
local handle,ped = FindFirstPed()
if handle ~= -1 then
local handle, ped = FindFirstPed()
local success
repeat
table.insert(peds,#peds+1,ped)
print('adding '..ped..' to table')
success, ped = FindNextPed(handle)
until not success
EndFindPed(handle)
end
return peds
end
But the only output is “adding 258 to table”, it doesn’t actually get any other peds, so I’m presuming 258 is my ped, but I don’t want that - I want the AI.
function GetNearbyPeds(X, Y, Z, Radius)
local NearbyPeds = {}
if tonumber(X) and tonumber(Y) and tonumber(Z) then
if tonumber(Radius) then
for Ped in EnumeratePeds() do
if DoesEntityExist(Ped) then
local PedPosition = GetEntityCoords(Ped, false)
if Vdist(X, Y, Z, PedPosition.x, PedPosition.y, PedPosition.z) <= Radius then
table.insert(NearbyPeds, Ped)
end
end
end
else
Log.Warn("GetNearbyPeds was given an invalid radius!")
end
else
Log.Warn("GetNearbyPeds was given invalid coordinates!")
end
return NearbyPeds
end