Get coords of an trailer

Im trying to get the coords of an trailer by using GetClosestObjectOfType or GetClosestVehicle which are both not working, for GetClosestVehicle i have tried the hash of the trailer or 0 for any vehicle.


Solution:

Is it working when it’s not attached to something but failing when attached? If this is the issue, try this;
GetVehicleTrailerVehicle → GetVehicleTrailerVehicle - Natives @ Cfx.re Docs
Get the vehicle the ped is in, for example, then use this to get the attached trailer.

If the issue is that it never returns the trailer, even while not attached to a towing vehicle, then I am not sure why that isn’t working. I would be using GetClosestVehicle like you previously did, but with a larger radius and the coords unpacked (coords.x, coords.y, coords.z instead of just coords). Then I would try flag 127, instead of 70 to see if that is some quirky thing with trailers, like it is with police cars. Other than that, not sure.

Also as a side note, you should put tanker inside backticks for jenkins hashing, instead of using GetHashKey.
Replace;

GetHashKey('tanker')

With;

`tanker`

Using those backticks. It’s much faster than that GetHashKey function call.

2 Likes

Its Neither working if it is attached or not attached, GetVehicleTrailerVehicle only returns a bool, with which it seems to not get the coords from.

Tried it with a larger radius unpacked coords other flag but its still not working.

it returns 2 values, a bool if a trailer is attached or not, and the trailer entity. So try

local hasTrailer, trailer = GetVehicleTrailerVehicle(vehicle)
1 Like

Works!, Thanks

Yeah, I was going to say, make sure to read the documentation clearly (I even linked it xD).

image