M MY Multiplayer: Wiki
Side
Kind

getClosestStraightRoad

Shared

Finds the stretch of road closest to a point: two linked car nodes and the heading between them. Switched-off nodes are left out.

vec3, vec3, float|false getClosestStraightRoad(float x, y, z [, float minLength = 0, float maxDistance = 999999.875])

Parameters

NameTypeDescription
x, y, zfloatThe point to search from.
minLengthfloatThe least distance in metres between the two nodes.default 0
maxDistancefloatHow far from the point the stretch may be.default 999999.875

Returns

The two nodes' positions, beside the median as getPathNodePosition with lane gives them, and the heading from the second to the first in degrees. false if no stretch was found.

Example

local vehicle = getPedOccupiedVehicle(localPlayer)
if vehicle then
    local position = getElementPosition(vehicle)
    local first, second, heading = getClosestStraightRoad(position.x, position.y, position.z, 10, 200)
    if first then
        setElementPosition(vehicle, first.x, first.y, first.z + 1)
        setElementRotation(vehicle, 0, 0, heading)
    end
end
NoteOnly nodes in loaded path areas count: those near the player, or requested with requestPathNodesInArea.

See also