M MY Multiplayer: Wiki
Side
Kind

getNthClosestPathNode

Client

Finds the nth road or footpath node closest to a point.

int, vec3|false getNthClosestPathNode(float x, y, z, int n [, string type = car, bool water = false])

Parameters

NameTypeDescription
x, y, zfloatThe point to search from.
nintWhich node: 1 is the closest, 2 the next one, and so on. Below 1 raises an error.
typestringcar for roads, ped for footpaths.default car
waterbooltrue searches only the boat paths on water; false, only on land.default false

Returns

The node's id and its position, or false if there are not that many nodes.

Example

local position = getElementPosition(localPlayer)
for n = 1, 5 do
    local node = getNthClosestPathNode(position.x, position.y, position.z, n)
    if not node then
        break
    end
    outputDebugString(("node %d: %d"):format(n, node))
end
NoteOnly nodes in loaded path areas count: those near the player, or requested with requestPathNodesInArea.

See also