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
| Name | Type | Description |
|---|---|---|
| x, y, z | float | The point to search from. |
| minLength | float | The least distance in metres between the two nodes.default 0 |
| maxDistance | float | How 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
endNoteOnly nodes in loaded path areas count: those near the player, or requested with
requestPathNodesInArea.