> ## Documentation Index
> Fetch the complete documentation index at: https://docs.czautoz.co.uk/llms.txt
> Use this file to discover all available pages before exploring further.

# Garage Hook (for mod makers)

> Four server calls that let a garage or storage mod keep a vehicle's odometer, last driver, lock, keys and dirt when it stores a vehicle and spawns it again with a new ID.

> [!NOTE]
>
> This page is for **mod makers** who write garage, storage or trader mods. Server owners don't need to do anything: if your garage mod doesn't use these calls, Core still works and the data of stored vehicles simply expires (see [What happens without the hook](#what-happens-without-the-hook)).

## Why it exists

Vehicles Core keeps a few things for each vehicle in `profiles/CZAutoz/Cars/Data`, keyed by the vehicle's **persistent ID**:

| File | What it holds |
| - | - |
| `Odometer.json` | Distance driven and the engine service counter |
| `LastDrivers.json` | Who drove it last (the tracker receiver pairs with it) |
| `CarLocks.json` | Locked or not, its paired keys, the key owner |
| `Dirt.json` | How dirty it is |

Many garage mods **delete** a vehicle when a player stores it and **spawn a new one** when they take it out. The new vehicle gets a new persistent ID, so without help its odometer starts at zero, its keys stop fitting and the old entries wait in the files for the clean-up.

## The four calls

All are static, server-only and safe to call more than once.

| Call | When | What Core does |
| - | - | - |
| `string CZCoreGarage.czam_KeyOf(EntityAI vehicle)` | Before you store the vehicle | Returns the key Core keeps its data under (`""` if the vehicle has no persistent ID yet). Save it with the stored vehicle |
| `bool CZCoreGarage.czam_Parked(string key)` | After the vehicle is stored and deleted | Keeps its entries while it is parked, for **ParkedKeepDays** (default 90), whatever the other clean-up limits say |
| `bool CZCoreGarage.czam_Restored(string key, EntityAI newVehicle)` | Right after you spawn it again | Moves its odometer, last driver, lock and keys, and dirt to the new vehicle at once (the new vehicle answers to its old lock, so every key still fits) |
| `bool CZCoreGarage.czam_Forget(string key)` | The stored vehicle will never come back (sold, scrapped) | Removes its entries (only for a vehicle that was parked with `czam_Parked`) |

## Example

Guard the calls so your mod still loads on servers without Vehicles Core:

```c theme={null}
// when the player stores the vehicle (server)
string czKey;
#ifdef Callatic_Vehicles_Core_Scripts
czKey = CZCoreGarage.czam_KeyOf(vehicle);
#endif
// ... save czKey with your stored-vehicle record, then delete the vehicle ...
#ifdef Callatic_Vehicles_Core_Scripts
if (czKey != "") CZCoreGarage.czam_Parked(czKey);
#endif

// when the player takes it out (server)
// ... spawn newVehicle from your record ...
#ifdef Callatic_Vehicles_Core_Scripts
if (storedKey != "") CZCoreGarage.czam_Restored(storedKey, newVehicle);
#endif
```

Call `czam_Restored` after the new vehicle exists and has its persistent ID (after it is created on the server; if your mod spawns it and sets it up in the same frame, a `CallLater` of a few hundred milliseconds is enough).

## Rules and limits

* **`false` means not done and nothing changed. Call it again** (for example a moment later): a call can be refused when more than 100 arrive in one second, such as a restore-all after a restart.
* **Server only.** On a player's game the calls do nothing and write one warning line.
* **The key** is what `czam_KeyOf` returns: four whole numbers joined by `_`. Anything else is refused (`false`, one warning line at most every 10 seconds).
* **A vehicle in the world is never overwritten.** `czam_Restored` refuses a key that belongs to a vehicle still in the world, so it can't copy a lock or keys onto another vehicle.
* **The new vehicle's own data wins where it is newer:** a last driver already recorded for it stays, and a key already paired to it stays. Its odometer reading is added to the stored one.
* **No file is written inside a call.** Each file is saved by Core's own schedule (within 5 minutes, and at server shutdown).
* **Limits:** at most 2,000 parked vehicles (the oldest drop first), each kept for **ParkedKeepDays**; at most 100 calls a second. Core writes a log line at most once a minute when vehicles come back with a new ID.
* **Cost:** each call is a few map lookups. Checking that a key is not a vehicle in the world uses a list of the world's vehicles rebuilt at most once a second, so a burst of take-outs stays cheap.
* If the garage keeps the vehicle's persistent ID, `czam_Restored` just clears the parked mark.

## What happens without the hook

Nothing breaks. A stored vehicle's entries stay until the clean-up removes them: after **DataKeepDays** (default 30) days out of the world, or when a file holds more than **DataKeepMax** (default 1000) vehicles that are not in the world (newest kept). Odometer entries of vehicles that were never driven go after a day. On servers whose garage mod makes a new ID for every take-out, set **DataKeepDays** low (1 to 3) in the admin panel (Records).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.