Auto set to closest destination


#1

How would I go about making it so when someone inputs a destination like the 24/7 or LS customs that it would set it to the closest one to the player?


#2

Get the player coordinates then compare it to all the destinations then you can get the closest.
I can show you a sample when I get home.


#3

That would be great


#4

Sry, I forgot it.

listofshops = {
    {x = 100, y = 100, z = 100},
    {x = 100, y = 100, z = 100} -- random cords
}
closest = nil
closestshop = nil
for _, shop in pairs(listofshops) do
    cords = GetEntityCoords(PlayerPedId())
    distance = GetDistanceBetweenCoords(cords.x, cords.y, cords.z, shop.x, shop.y, shop, z, false)
    if closest == nil then
        closest = distance
        closestshop = shop
    else
        if distance < closest then
            closest = distance
            closestshop = shop
        end
    end
end

closestshop is the value you need
This should work however I didn’t tested it.


#5

Ok thank you so much