M MY Multiplayer: Wiki
Side
Kind

calculatePathRoute

Client

Works out the shortest route along the path nodes between two points, starting from the node closest to each. For cars, it respects one-way streets.

table, float|false calculatePathRoute(float fromX, fromY, fromZ, float toX, toY, toZ [, string type = car, bool water = false])

Parameters

NameTypeDescription
fromX, fromY, fromZfloatWhere the route starts.
toX, toY, toZfloatWhere the route ends.
typestringcar for roads, ped for footpaths.default car
waterbooltrue searches only the boat paths on water; false, only on land.default false

Returns

The list of node ids from start to end and the route's length in metres. false if there is no route.

When both points have the same closest node, the list is empty and the length is 0.

Example

local position = getElementPosition(localPlayer)
local route, length = calculatePathRoute(position.x, position.y, position.z, 1481.0, -1740.0, 13.5)
if route then
    outputDebugString(("%d nodes, %.0f m"):format(#route, length))
end
NoteThe search only goes through loaded areas. For a long route, request the area with requestPathNodesInArea first.

See also