Hey! I was thinking, how can I get coords of the nearest path in front/closer to the Player ped so I can park a vehicle or spawn it there? Tried GetNthClosestNode, GetClosestRoad.
Thanks in advance
Hey! I was thinking, how can I get coords of the nearest path in front/closer to the Player ped so I can park a vehicle or spawn it there? Tried GetNthClosestNode, GetClosestRoad.
Thanks in advance
Hi Yeagorn ! To get the closest road I personally use the native GetClosestRoad()
This is how I use it:
local formatedCoords = {x = GetEntityCoords(GetPlayerPed(-1)).x, y = GetEntityCoords(GetPlayerPed(-1)).y, z = GetEntityCoords(GetPlayerPed(-1)).z}
local _, closstRd, anotPos = GetClosestRoad(formatedCoords.x, formatedCoords.y, formatedCoords.z, 10, 1, true)
SetEntityCoords(GetPlayerPed(-1), closstRd)
Have a nice day !
Hi Cozy! I was using this method but it spawned the car in the middle of the road, here’s a picture of my idea getting the closest road
Have a nice day!
I see what you wan’t, like in GTA:O, idk how to do, sorry…
I hope you will find what you search.
Alright, thanks for your help anyways.
RegisterCommand('carSpawn', function()
local coords = GetEntityCoords(PlayerPedId())
local ret, coordsTemp, heading = GetClosestVehicleNodeWithHeading(coords.x, coords.y, coords.z, 1, 3.0, 0)
local retval, coordsSide = GetPointOnRoadSide(coordsTemp.x, coordsTemp.y, coordsTemp.z)
SetEntityCoords(PlayerPedId(), coordsSide.x, coordsSide.y, coordsSide.z, false, false, false, true)
SetEntityHeading(PlayerPedId(), heading)
end)
I think this is what you want. I first use GetClosestVehicleNodeWithHeading()
to get both road coords and an appropriate heading for coords.
Then I top it with GetPointOnRoadSide() which seems to do the logic for “parking”.
You can paste that command in a client script and check.
Thanks, that’s really what I’ve been searching for. Appreciated!