[SOLVED] Vehicle still despawn

Why my vehicle still despawn… after i script this code

		local myPed = GetPlayerPed(-1)
		local player = PlayerId()
		local vehicle = GetHashKey('police2')
		RequestModel(vehicle)
		while not HasModelLoaded(vehicle) do
			Wait(1)
		end
		local spawned_car = CreateVehicle(vehicle, 412.857696533203, -981.011474609375, 29.4276905059814, 181.814880371094, true, false)
		SetVehicleOnGroundProperly(spawned_car)
		SetModelAsNoLongerNeeded(vehicle)
		SetVehicleHasBeenOwnedByPlayer(spawned_car, true)
		local id = NetworkGetNetworkIdFromEntity(spawned_car)
		SetNetworkIdCanMigrate(id, true)
		Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(spawned_car))

the vehicle seem to despawn as the same… SetVehicleHasBeenOwnedByPlayer doen’t work?

2 Likes

Hey, I got the same problem, I tried all the stuffs like you tried, but nothing seems to work for me too :confused:
Let me know if you get this, I’ll do the same :slight_smile:

Ok sir… i also don’t know why it doen’t work… but i seen that people 're using this and the vehicle stay all the time… but this dosn’t work for me ;C

2 Likes

Your vehicle despawn because you call this function:

Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(spawned_car))

It’s real name is ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED

You tag this car as not needed, so the game remove it as soon as it can :wink:
Remove this line and it will stop despawning. But be careful, it won’t despawn even when exploded.

1 Like

i’ll try and will tell if it work… thank you so much

and can you explain… this line?

I have no idea what SetNetworkIdCanMigrate does. I don’t use it and as long as I tested, I can see the cars I spawn and my friend too without it.
I can only recommend you to try with and without, I don’t find a lot of informations on this function.

2 Likes

and what about this do Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(spawned_car))

0xB736A491E64A32CF <<< this one

is both the same… and work the same? so why people using the second instead of the one

1.SetVehicleAsNoLongerNeeded(spawned_car)

2.Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(spawned_car))

http://www.dev-c.com/nativedb/func/info/b736a491e64a32cf
It removes the entity as soon as the game can.

Use this site to translate hash to function name.

Edit: I personnaly use SetEntityAsNoLongerNeeded (0xB736A491E64A32CF) but I’ve never used SetVehicleAsNoLongerNeeded

1 Like

I would also try adding SetEntityAsMissionEntity if the other suggestions don’t work.

I very really ty…bob_74 it work… my veh doesn’t despawn anymore… ty so mych +10

solution is

delete this line

Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(spawned_car))

[SOLVED]

1 Like

Thanks guys you made my day

can someone help ?

i would spawn a bicycle to travel from spawn to city

Don’t ask in someone elses thread. Create a new one.

1 Like

Hello, i have the same problem and we dont find the line in our scripts. Do you have a solution for me pls ? Where i can find this line ?

Where do you write this?

where i can find this file to change it?

So, I have to put these lines to car spawn scripts (like eden garage etc.), @Synchro ?

Or do I create standalone script for this? This looks like something from already made car spawner/garage, am I right?