DaemonScripts

Projects / FiveM scripts · Vehicles

DPS Vehicle Persistence

Live

Owned cars stay where you left them, through logouts and server restarts, with mods, fuel and damage intact

Overview

Vehicle Persistence keeps player cars in the world the way real cars behave. Get out of your car and it stays there. Log off and it stays there. Restart the server and it comes back in the same spot, with its mods, colours, livery, fuel and damage as you left them.

It only tracks vehicles a player actually owns, and leaves out emergency fleets, work vehicles and job spawns, so the streets do not fill up with police cruisers and forklifts. Cars that sit untouched for too long are impounded or deleted automatically.

Other vehicle scripts (garages, tow jobs, mechanics, impound) can tell it when they take a car, lock a car while they work on it, or exclude a car for good, so nothing fights over the same vehicle.

Features

  • Vehicles stay in the world when their owner gets out or disconnects, even if they drop while driving.
  • Vehicles respawn after a server restart in the same place.
  • Saves mods, colours, liveries, fuel, engine and body damage.
  • Cars, bikes, boats, helicopters, planes, quad bikes and trailers, each respawned with the right physics type.
  • Only owned vehicles persist; a per-player cap (5 by default).
  • Model and job blacklists keep emergency, maritime, work and service vehicles out.
  • Vehicles spawned by job scripts are excluded automatically by listening for their spawn events.
  • Staff vehicles can be exempt, which helps with testing.
  • Storing a car in a supported garage removes it from the world list.
  • Orphaned cars from inactive players are impounded (with a daily fee, capped) or deleted.
  • Optional hard expiry for cars nobody has touched in a set time.
  • Exports to lock, exclude or report on vehicles, plus state bags so clients can see what is persisted.
  • Server-side ownership checks and input cleaning on every save and every client event.
  • Fuel script auto-detection, with a native fallback.

How it works

  1. A player gets out of a car they own. The client sends its position and properties, and the server checks ownership before saving.
  2. The car stays in the world, tagged with its owner through state bags.
  3. On restart, persisted cars respawn one by one with a short delay so the server is not flooded.
  4. When the car goes into a garage, is towed, impounded or destroyed, it is removed from the world list.
  5. A cleanup pass runs on an interval and handles cars whose owners have been away for a week (by default).

Requirements

  • ox_lib
  • oxmysql
  • One of qbx_core, qb-core or es_extended (detected automatically)

The README lists support for these garage scripts: qs-advancedgarages, jg-advancedgarages, qb-garages, cd_garage, loaf_garage, okokGarage and esx_advancedgarage. It also names integrations with dealership, tow (including dps-towjob), police, mechanic and admin menu resources.

Installation

  1. Copy dps-vehiclepersistence into your resources folder.
  2. Add ensure dps-vehiclepersistence to server.cfg.
  3. Restart the server. The dps_world_vehicles table is created on first start; install.sql is there if automatic creation fails.

Configuration

Everything lives in config.lua.

OptionDefaultWhat it does
Config.AdminExempttrueStaff vehicles do not persist
Config.StaffGroupsadmin, god, mod and othersGroups treated as staff
Config.VehicleTimeout0Minutes untouched before a car expires; 0 never expires
Config.PersistThroughRestarttrueRespawn cars after a restart
Config.MaxVehiclesPerPlayer5Cars per player kept in the world
Config.SpawnDelay500Milliseconds between respawns on restart
Config.GarageSpawnGracePeriod10000Milliseconds after a garage spawn before persistence starts
Config.PersistTypesall seven typesVehicle types that persist
Config.BlacklistedModelsemergency, boats, work, utilityModels that never persist
Config.BlacklistedJobsemergency and service jobsJobs whose vehicles never persist
Config.OrphanedVehicles7 days, impound, 100 per day, 1500 maxWhat happens to abandoned cars
Config.TowJobspolice jobs, tow, mechanicJobs allowed to tow persisted cars
Config.FuelResourceautoFuel script to read and write
Config.JobVehicleExclusiononJob spawn events that auto-exclude a vehicle

Commands

CommandWhoWhat it does
/clearworldvehiclesAdminsRemove all persisted vehicles
/listworldvehiclesAdminsList all persisted vehicles in the console

Credits

Written by DaemonAlex for Del Perro Sands. Uses ox_lib and oxmysql by Overextended. The licence note in the README allows modification for your own use.