Make all spawned peds follow players


I’ve spawned some peds and players are able to see them. I’d like to know how I can get all spawned peds and move them (run or walk) to a player (closest player to peds if possible).

Is this even possible ? If so, how can I implement that please ? I’ve been searching for 2 days :frowning:

Can you share your code to spawn peds ? I would like to edit to make a script with PNJ for stores…

I’m using RottenV script. You can find it here.

1 Like

x, y, z = table.unpack(GetEntityCoords(ped, true))
TaskGoToEntity(ped, GetPlayerPed(-1), -1, 1.0, 10.0, 1073741824.0, 0)
SetPedKeepTask(ped, true)

Thanks OhMyM, your code works. It even works without “SetPedKeepTask(ped, true)” line.
Should I use that last line anyway?

And, will this piece of code work with other players ? e.g another player gets closer to ped so ped starts going to that player instead of me previously.


Do you know of a mod with which you can spawn npcs? To be able to put on the map to make clips etc?

I know one that works with the catching chicken job:

while not HasModelLoaded(GetHashKey(‘a_c_hen’)) do
chicken1 = CreatePed(26, a_c_hen, 2370.262, 5052.913, 46.437, 276.351, true, false)

Obvious, you can set the ped to any hash you want and change the locations you want