Vehicle natives not working

Hey there!

First of all: Sorry for the previous topic with the same title, posted on a wrong account.

So today I faced a weird bug, where sometimes I couldn’t do anything with vehicles, such as setting the plate or even deleting it. Natives like DeleteVehicle or SetVehicleNumberPlateText just won’t work, with no error or whatsoever.

So after debugging the issue a bit, we figured out that this happens in the following scenario:
If I spawn a vehicle at coords X Y Z, and someone else but me stands closer to the spawn point than I do, the vehicle will be somehow bugged.
This results in my client being unable to do anything with the vehicle:
Setting the plate, warping into the vehicle, or doing anything else with the vehicle won’t work then.

Anybody?

This has been bothering us for days now. :-/

In my script, I had the player sit in the car first and then change the plate. That way I could use GetVehiclePedIsIn and then change the plate

The player closest to the vehicle tends to take “control” of it. That’s just something about the netcode I had to learn the hard way. It applies to spawned NPCs too (like bodyguards).

There’s a boolean in the vehicle spawn code to make it permanently belong to the player that spawns it, but I forget exactly what it was called, sorry. Set that to true and it might help. I’m sure there’s a better way to do it somewhere.

Huh. Thanks for your feedback, guys.

Will try to find something like that. Was hoping there was an easy “Well, that’s because … and you can solve it by …” solution, haha.

Alright, I think I kinda fixed it.

None of the suggested ideas worked.
But I then figured, that we’re using the QBCore callback, which creates the vehicle on the server side.

So I decided to spawn the vehicle on the client side - and it seems like that fixed it.

The callback from qbcore returns the netId of the vehicle that is created.
Just use the natives NetworkGetEntityFromNetworkId() or NetToVeh() to get the entity on the client.

Note that this isn’t a consistent ‘fix’, it just may happen to work in the scenario you tested.

Generally, one should execute commands on the client that has control of an entity - there’s various ways to do this, lately the preferred way would be using state bags and state bag change handlers.

Did exactly that on the client side, that’s not a fix but rather the necessary code to even show the vehicle then.

Yet, the issue persisted this way.

I’m a bit confused by your response tbh.

Note that this isn’t a consistent ‘fix’, it just may happen to work in the scenario you tested.

Sounds like doing it client-side is not the way to do it.
But then, in the next sentence, you suggest to do it on the client. :smile:

Will have a look for state bags and how they could be related to this issue. Thanks!

It seems as if you’re doing something wrong if so.
I just did a test, and it worked without any issues.

My recommendation is to try it on a fresh QB install to see if it’s on your side or not.

I’ve done a test completely outside of a QB resource. Just CreateVehicle with coords, where another player stands closer than I do.
Then tried to set a plate - nop. Then did the same with me being the closest player. Worked like it should.

Changing it to client-side, and it’s no longer an issue. Hm.