> For the complete documentation index, see [llms.txt](https://zloma-scripts.gitbook.io/zloma-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zloma-scripts.gitbook.io/zloma-scripts/zloma_garages-paid/features/vehicle-tracking.md).

# Vehicle Tracking

zloma\_garages includes two vehicle tracking systems: **auto-impound on restart** and **session-persistent vehicles**.

***

## Auto-Impound on Restart

When the server restarts, vehicles that were "out" (spawned in the world) need to be recovered.

### Configuration

```lua
Config.VehicleTracking = {
    restartImpound = true,
    deleteFromWorld = true,
    orphanRecovery = false,
}
```

| Option            | Default | Description                                                                    |
| ----------------- | ------- | ------------------------------------------------------------------------------ |
| `restartImpound`  | `true`  | Move all vehicles with `stored = 0` (out) to impound (`stored = 2`) on restart |
| `deleteFromWorld` | `true`  | Delete vehicle entities from the world on restart                              |
| `orphanRecovery`  | `false` | Recover vehicles that have no `garage_id` assigned                             |

### How It Works

1. On resource start, the system queries for all vehicles with `stored = 0`
2. Sets them to `stored = 2` (personal impound)
3. Players retrieve their vehicles from the nearest personal impound
4. If `orphanRecovery` is enabled, vehicles without a `garage_id` are assigned to a default garage

***

## Session-Persistent Vehicles

{% hint style="warning" %}
This feature is **disabled by default**. Enable it only if your server needs vehicles to survive entity culling (e.g., parking lots, RP servers where vehicles should stay in the world).
{% endhint %}

When enabled, vehicles spawned from garages will automatically respawn if they get culled (deleted by the game engine when no players are nearby).

This solves a problem that many garage systems do not solve at all: the vehicle still exists logically, but the world entity disappears because nobody was close enough to keep it streamed. With persistent vehicles enabled, zloma\_garages can restore that vehicle during the same session instead of making it look like the car vanished.

### Configuration

```lua
Config.PersistentVehicles = {
    enabled = false,
    spawnDistance = 200.0,
    updateInterval = 3000,
    respawnDelay = 1500,
    maxRespawnAttempts = 3,
    impoundOnMaxAttempts = false,
}
```

| Option                 | Default | Description                                                         |
| ---------------------- | ------- | ------------------------------------------------------------------- |
| `enabled`              | `false` | Enable/disable the entire system                                    |
| `spawnDistance`        | `200.0` | Distance (meters) at which vehicles respawn when a player is nearby |
| `updateInterval`       | `3000`  | Main loop interval — how often to check positions (ms)              |
| `respawnDelay`         | `1500`  | Debounce delay to prevent ghost spawning (ms)                       |
| `maxRespawnAttempts`   | `3`     | Max times the system will try to respawn before giving up           |
| `impoundOnMaxAttempts` | `false` | If max attempts reached, move vehicle to impound                    |

### How It Works

1. When a vehicle is spawned from a garage, it's registered for tracking
2. A server-side loop runs every `updateInterval` ms
3. Checks if tracked vehicles still exist in the world
4. If a vehicle is missing and a player is within `spawnDistance`, respawn it
5. Applies saved properties, fake plates, and stance data on respawn
6. After `maxRespawnAttempts` failures, either gives up or impounds

### Important Notes

* Persistent vehicles are **session-only** — they do not survive server restarts
* Position and properties are regularly updated as players drive
* Fake plate info is preserved through respawn
* Deleting a vehicle via other scripts should call `NotifyVehicleDelete` export to prevent respawn attempts
* If another resource deletes owned vehicles, that resource should also load `@zloma_garages/zlDeleteHelper.lua` in `shared_scripts`
* Apply that requirement to garage cleanup, impound cleanup, parking cleanup, and any general owned-vehicle deletion resource

### External Integration

If your script deletes a garage vehicle, notify the persistent system:

```lua
-- Server-side
exports['zloma_garages']:NotifyVehicleDelete(entityOrNetId)
```

Or trigger the event:

```lua
TriggerServerEvent('zloma_garages:externalDeleteVehicle', netId)
```

If that external script manages owned vehicle deletion, also add:

```lua
shared_scripts {
    '@ox_lib/init.lua',
    '@zloma_garages/zlDeleteHelper.lua'
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zloma-scripts.gitbook.io/zloma-scripts/zloma_garages-paid/features/vehicle-tracking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
