M MY Multiplayer: Wiki
Side
Kind

getClosestPathNode

Shared

Finds the road or footpath node closest to a point.

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

Parameters

NameTypeDescription
x, y, zfloatThe point to search from.
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 no node was found.

A node id joins the path area (750 m wide) and the node's index in it: area << 16 | node.

Example

local position = getElementPosition(localPlayer)
local node, nodePosition = getClosestPathNode(position.x, position.y, position.z)
if node then
    setElementPosition(localPlayer, nodePosition.x, nodePosition.y, nodePosition.z + 1)
end
NoteOnly nodes in loaded path areas count: those near the player, or requested with requestPathNodesInArea.

See also