[DISCONTINUED] [ALPHA] Stop vehicle despawning

[BETA] StopDespawn

No more vehicle despawning in FiveM thanks to this script!

This is a quick fix to the despawn problem we all hate. It’s not stable just yet, and I need help testing it, so I’d appreciate if you commented whether it works or not / what works and what doesn’t, after trying the script.
I hope it helps somebody out. :wink:

Features

- All the vehicles stay where you left them, by:

  • Preventing all the vehicles that any player has joined from despawning (Restores the despawned vehicles every given amount of time).
  • Saving their positions every set amount of time, on vehicle enter, and on vehicle exit if configured.
  • Loading all previously saved vehicles when the first player joins.

- Saving API for developers.
- Debug mode for nerds :nerd_face:

Installation

  • Were you expecting me to make a tutorial on how to install a resource for you? Nah, but don’t worry, I’ll give you the download link: StopDespawn.zip (2.6 KB) (Latest version) (Previous versions can be found in the GitHub repository)
  • Open the config.lua file and customize it if you want.

Known bugs

  • When many saved vehicles are close to each other and they all must be restored, it sometimes spawns some of them twice. If anyone knows how to fix that, please tell me. :pray:
  • Some may consider a bug the fact that the customization of the vehicles doesn’t save, but it’s not. Moreover, It will soon be implemented (check the To-Do section).

To-Do

  • Add DeleteVehicle support.
  • Save more vehicle information (paintjobs, customization, engine status, sirens, and any suggestions you may have :wink:).
  • Add more customization.
  • Add MySQL-async support in order to keep the cars saved even after server restarts.
  • Possibly add support for roleplay frameworks (this one is not likely at the moment though).

Notes

  • It’s my first script so don’t expect such a clean code (the events are kinda mindblowing :laughing:).
  • Here is the GitHub repository for any requests.
  • Again, this script is still in an early beta version and it needs testing, so again, please, comment the results if you try the script.
  • Please report any bugs after making sure they’re not already known.
  • Any suggestions are welcome.
  • This script will be updated actively during the rest of March 2018 (and will keep updating after March but probably less often).

Latest changes

  • Save on vehicle enter.
  • Save event for developers (check next section).

API

  • With the ‘sd:save’ event, you can save any vehicle by just giving its ID as the only argument. For example:
local vehicleId GetVehiclePedIsUsing(GetPlayerPed(-1))
TriggerEvent('sd:save', vehicleId)

And if you are calling it from a server script (not recommended), just trigger the event on any ID, like the 1st one:

TriggerClientEvent('sd:save, GetPlayers()[1], vehicleId)
11 Likes

Your GitHub is just a readme. Can you upload it there please?

1 Like

Forgot to do it, how dumb xD

1 Like

Done. Thanks for reminding me.

Cant wait to try it out on my server!!!

1 Like

Nice Resource! Keep up the good work. :slight_smile:

Thanks! Could you notice any bug?

Very nice script !

I’ve tested it and I have 4 minor issues :slight_smile:

1- I have to restart the script to make it works
2- After that, the vehicle is saved even if i’m driving it. So you can see cars spawning on my traces during my trip
3-The amount of cars is equal to the number of connected players. If you are 3, you will see 3 cars spawning.
4-You can’t delete or store your vehicle to the garage because it will respawn.

Its just my observation, doesn’t mean you will get these issues on your server.

BR and thanks for sharing your work!

1 Like

Thanks for your feedback. I only tested the script myself alone so I didn’t see those issues. It’s a lot actually. I’ll look into them. I guess there’s something wrong with the ids, because the cars shouldn’t spawn if they haven’t despawned.

And by the way, are you using any seperate garage script?

Well not only one xD
I combine
-esx_eden_garage
-esx_hangard
-esx_garage
Its also for “native” jobs vehicle deleter points

Oh, well if you check the To-Do section, you see that it will be compatible with RP frameworks in the future, which means that it isn’t yet compatible with ESX. So that is a known issue then.

1 Like

I also added that I will add support for deleting vehicles.

NEW UPDATE (Build 2):

  • Added toggleable save on vehicle enter.
  • Added save event for inter-resource use, which introduces the API section. This allows developers to use this script to keep a vehicle they spawn from despawning by just calling an event and giving the vehicle id as an argument (check API section for usage).
  • Bugfix: when a vehicle is entered, it is now saved, even if it’s instantly left, thanks to the save on vehicle enter feature.
2 Likes

You guys need mysql-async for this to work so remember to set up that plugin before anything else this won’t work.

Great job OP, I was really interested into doing something like this but never found time, I’ll give it a try later and see how it works.

1 Like

Of course it works without mysql-async. Although it clears all the saved vehicles after a server restart. And if you read the To-Do section you can see that I am planning on implementing restart support by using mysql-async.
Thanks for your reply though :smiley:

1 Like

vehicles still despawn for me.

1 Like

@kr1st0
For me it is, working very well!

Nice release!
But i think you dont need this in the __resource.lua?

server_scripts {
	'config.lua',
	'@mysql-async/lib/MySQL.lua', <<<<<<<<< THIS LINE
	'server.lua'
}

First of all I wanna say thank you for not using mission entitiy to make vehicle persist next please add netid stuff so u make the vehicle a networked vehicle other than that great work

1 Like

Oops, that’s right. I was just messing with mysql-async and forgot it there. I will take it off asap. Thanks for the feedback!