Vehicles path nodes

Well, i’m working right now on a simple vehicles decoration for me server so i want to spawn some vehicles in random positions near the player so i’m just getting a random position near the player in a radius and after that just getting the cosset vehicle done but the problem is that the node is in the middle of the road just like:

https://gyazo.com/2202450537c5d78a7ce68e6219dd4702

but in want to pace them in the road so where the vehicles drive not in the middle of both sides…

function getNextPositionOnRoad(x, y, z)
	local found = false
	local roadType = 1
	while not found do
		found, outPos, outHeading = GetClosestVehicleNodeWithHeading(x, y, z, roadTypes[roadType], 3, 0)
		roadType = roadType + 1
	end
	if found and not IsPointObscuredByAMissionEntity(outPos.x, outPos.y, outPos.z, 5.0, 5.0, 5.0, 0) then
		return outPos, outHeading;
	end
	return false
end

This is the code i’m using to get the node position is possible to get the position on one side of the road not on the middle like in screenshot

I don’t exactly know what you are trying to accomplish but try offsetting the coords to the side of the road you want it.

i would do that if i can get the road size but i dont know where the vehicle will be spawned so i mean in what road type as they can be spawned in a one directional road.

Basiclly i want to place the vehicle in a right direction for example:

This vehicle:
https://gyazo.com/1c2f22fd78e05a0c9147e4f2b72b6af3

I want to get it spawne in one of this positions: https://gyazo.com/8c63fe24d89c456d89003e59f09af6ea no on the middle of the whole road like is in the first screenshot

To my knowledge if you would want to do something like this you would have to get all the coords and heading of each spot you want the car.

Try this:

At first set the vehicle in the middle of the road, like you already do.
Afterwards use this:

local CorrectionX = 10.0
local coords = GetOffsetFromEntityInWorldCoords(YOUR_VEHICLE, CorrectionX, 0.0, 0.0)
while not IsPointOnRoad(coords.x, coords.y, coords.z, YOUR_VEHICLE) do
	CorrectionX = CorrectionX - 0.5
	coords = GetOffsetFromEntityInWorldCoords(YOUR_VEHICLE, CorrectionX, 0.0, 0.0)
end
SetEntityCoords(YOUR_VEHICLE, coords.x, coords.y, coords.z, false, false, false, true)

That is how I do it and it works pretty good. Just try it :slight_smile:

2 Likes