[Help] Random Npc Spawn Locations

What’s up community. I’m looking for a way to spawn an npc in different spots. So I have the npc hash 2992445106 and I want to let’s say make him spawn in 3 different locations. So you see him in his first position, sell him items or drugs or whatever, then when you’re done, have him move to a different location and so on. Kind of like the mechanic job how it randomizes where the cars are located. If anyone can point me in the right direction it would be greatly appreciated. I’m not asking for someone to build me a script just point me in the direction where I need to be looking. Thanks in advance.

i was looking for the exact same thing so if anybody knows how to do this it would be very helpfull

You would need to create an array of the locations (coordinates) you wish for the NPC to be located in. Then after you do whatever you want in the script (E.G sell drugs) delete that ped then create a new one in a random area from the array.

Example:

local spawnLocations = {
    {x = 1111, y = 1111. z = 1111, h = 0.0}, -- Position 1
    {x = 1111, y = 1111. z = 1111, h = 0.0}, -- Position 2
    {x = 1111, y = 1111. z = 1111, h = 0.0}, -- Position 3
    {x = 1111, y = 1111. z = 1111, h = 0.0}, -- Position 4
}

RegisterNetEvent('updateLocations')
AddEventHandler('updateLocations', function()
    --Delete Previous ped here
    local location = math.random(1, #spawnLocations)
    --Create ped here
end)