# calculatePathRoute (Shared)

> 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.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Roads and paths
- **URL**: https://wiki.mymp.gg/en/calculatePathRoute

## Syntax

```lua
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

```lua
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
```

### Note

The search only goes through loaded areas. For a long route, request the area with `requestPathNodesInArea` first.

## See also

- [getPathNodeNeighbours (Shared)](https://wiki.mymp.gg/en/getPathNodeNeighbours.md): Lists the nodes linked to a path node and what each link is like.
- [getPathNodePosition (Shared)](https://wiki.mymp.gg/en/getPathNodePosition.md): Returns a path node's position.
- [requestPathNodesInArea (Client)](https://wiki.mymp.gg/en/requestPathNodesInArea.md): Asks for the path nodes of an area to be loaded beyond those near the player. The area stays loaded until releasePathNodes.
