Getting peds near player

i’m trying to get all peds near player at a specific radius but i couldn’t find any native that can help, i found two natives that can be useful but it seems like they work only in C# i couldn’t figure out how to make them work in Lua ( GetPedNearbyPeds and GetAllPeds() )

For “within a specific radius” the easiest solution is to fetch the coords of each (relevant) player and do verctor3 maths on them and the center of your radius

i don’t know how to fetch coords of each ped in the world

Run GetEntityCoords on each player for themselves and do the check client-side

i’m confused, i just started developping fiveM plugins, what i’m trying to do is get all IA near a player

For that you use GetGamePool(CPed) on the client, then do vector3 maths (same idea lol) on each ped in a while true do loop; you can do additional checks via IsPedAPlayer if relevant in your case

yes i have tried that, and it gave me 16 peds in total only which didn’t make sense to me or GamePool gives nearest players by default?

image

It gives you all peds that exist locally on the client, both AI and players, when it’s called

yeah but the number of elements in that table is not constant it changes sometimes depends on the place i’m in, anyways i’m trying to alter the behaviour of IA in certain situations and idk if i should do it server side or client side

You should’ve started with that lol, not nearly all ways to do so would involve actually getting all peds near a player. What exactly are you trying to achieve here?

whenever a player shoots he doesn’t get ran over by vehicles around him, that’s why i’m trying to get peds around the player then i’m going to check if they are inside a vehicle

Alright yeah, for that you’ll need to loop through all AI peds near the player and play around with their config flags via SetPedConfigFlag, my first choices would be 229 and 294 - don’t overdo it, the config flags usually need to only be set once per entity

EDIT: If the flags work, a more optimal solution would be to find a way to hook into the entityCreating or something like that and set the flags then instead of doing it “hot”, but I wouldn’t know if that’s even possible or how to do so