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
| Name | Type | Description |
|---|---|---|
| fromX, fromY, fromZ | float | Where the route starts. |
| toX, toY, toZ | float | Where the route ends. |
| type | string | car for roads, ped for footpaths.default car |
| water | bool | true 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))
endNoteThe search only goes through loaded areas. For a long route, request the area with
requestPathNodesInArea first.