Thanks to @MarkViolla, I could improve this script alot, both in functionality and size. Now instead of having to enter a command in the console, the cars will automatically dissapear when the game thinks it doesn’t need it anymore. Also players can noclip into spawned cars to remove them too.
Installation is as usual, put it into the resources folder, then edit the AutoStartResources in your server-config.
client.lua
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
if car then
Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(car))
end
end
end)
The way he’s doing it adds any vehicle the player is in to a list and stores the vehicle ID, so it should work. The only issue as your talking about is keeping track of the vehicle IDs that have been spawned. The only issue that could arrise here is if two players get in the same vehicle, itll try to delete the vehicle from both clients and may cause errors
why are you not using SetEntityAsNoLongerNeeded after car spawn?
It is easy and simple instead this long script…Look at my Taxi Work script in release section for example.