- Documentation
- Shared functions
- getVehicleRoute
Function
getVehicleRoute
Finds a car route along the game's roads between two points, respecting one-way streets and highway lanes. On the server it works immediately, with no players nearby. The client asks the server, so it only works inside async and waits up to 3 s.
Syntax
table, float getVehicleRoute(float x1, float y1, float z1, float x2, float y2, float z2 [, table options = nil])Arguments
x1float- Start X.
y1float- Start Y.
z1float- Start Z.
x2float- Destination X.
y2float- Destination Y.
z2float- Destination Z.
optionstable, optional = nilavoidHighways,boat(boat route),emergency(emergency-only roads),ignoreOneWay.
Returns
A list of points { {x, y, z}, ... } and the length in metres; false and a reason if there is no road.
Example
local points, length = getVehicleRoute(2495, -1667, 13, 1544, -1675, 13)
if points then print(#points .. " punktów, " .. math.floor(length) .. " m") end
async(function()
local x, y, z = getElementPosition(localPlayer)
local points = getVehicleRoute(x, y, z, 1544, -1675, 13)
if points then setPlayerRouteLine(points) end
end)
See also
getNearestVehicleNodeReturns the nearest car road point to a given place. On the client it only works insideasync.setPlayerRouteLineDraws a custom route line on the player's ESC map instead of the game's GPS route, e.g. fromgetVehicleRouteor a walking route. It does not change the GPS target or blips. The line disappears afterclearPlayerRouteLineand when the resource stops.