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.
Installation
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.
Issues
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.
v2.1.2 - Made source local in server script, added NetworkConcealEntity, added additional logging, split into two releases (one for final use, one for debugging)
v2.1.1 - Updated manifest version to 44febabe-d386-4d18-afbe-5e627f4af937
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?
So you want to delay vehicle deletion by 15 minutes? There is currently no option to do that, I can add an option like that in the future if there is a need for feature like that.
Cool script, and cool idea. I love the fact that you’ve made a simple script that we’ve been needing in this community for such a long time now. This certainly will reduce the lag of some servers!
How this going on when people disconnect and came back in about 5 a 10 mins. Is the vehicle then already deleted or does the script have a timer for each player that disconnect? or a general timer?
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.