This is a simple script for FiveM to get rid off vehicles that people leave after they disconnect. There has always been an issue with leftover vehicles, so this script will automatically delete not used cars. It does not restrict number of vehicles that players are able to spawn, it just removes all of the vehicles spawned by player that disconnects.
To download go to releases tab and download latest zipped release. Unzip and place RemoveVehicles_2_0 folder in your resources folder, then start the resource in your server.cfg.
Feel free to comment or file an issue on github if something is not working as intended (it is tough for me to test this script alone in all possible scenarios, because it requires multiple people to test it out) or fork it and modify as you want.
Note: After hearing some feedback, it seems that vehicle removal is still not 100% reliable, I will be experimenting with it in my spare time and providing updates to hopefully fix this.
It got rid of the error, but when my buddy left it didn’t delete the vehicles he spawned before or after the script was started.
maybe it just needs a server restart, which I’m not able to do right now, but yes it got rid of the error.
Alright, let me know if there’s still problem with removing vehicles after you restart the server. Also the way it currently works is it only identifies vehicles to delete that player has used, did he possibly spawn them and did not enter them?
How the hell you guys get vehicles not to despawn them selfs? I’m fighting for vehicles despawning them selfs for months, lol. Here people fighting to get them to DESPAWN. What the hell…
My question would be HOW TO NOT DELETE VEHICLES RANDOMLY…
The way it works, is when player leaves, the engine marks the vehicle as no longer needed ( SetEntityAsNoLongerNeeded() or SetVehicleAsNoLongerNeeded()) and in theory it should get deleted automatically as the engine sees fit. That usually means that if there are no people nearby, vehicle should get deleted. However, it doesn’t always do it’s job that well and then there’s also problem when people are always nearby and it just does not get deleted. That is the problem that this script is trying to fix.
When it comes to your problem, the answet would probably be native SetEntityAsMissionEntity(), if you mark vehicle like that it should not get deleted automatically.
Please add config option to make a delay before deleting it, like 5-10 minutes, because someone’s game can crash and if they were in roleplay at the middle of nowhere it’s bad… It will be cool if the player join in before 5-10 minutes, the car to stay here, but if the player didn’t joined, to remove the car.