> ## 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.

# Scripting API (for mod makers)

> Server calls and events that let other mods read a car's state, start and stop its engine, switch its lights, lock and unlock it and see its add-ons.

> [!NOTE]
>
> This page is for **mod makers** who write server mods such as convoys, traffic, missions or garages. Server owners don't need to do anything: the API does nothing for players on its own.

Server mods can read a car's state, start and stop it, switch its lights, lock and unlock it, and see its add-ons. It works on CZ Autoz cars and on vanilla and other mods' cars. Motorbikes and DayZ's boats are not covered. CZ Autoz helicopters have their own API (`CZAutoz_HeliAPI`); this one leaves them alone.

Everything runs on the **server**. On a player's game every call returns `false` or `0` and does nothing. It works only on a whitelisted server.

## Checking the mod is there

Add `Callatic_Vehicles_Core_Scripts` to your `requiredAddons`, then:

```c theme={null}
if (CZAutoz_CarAPI.GetApiVersion() >= 1) { /* safe to use version 1 calls */ }
```

The version only goes up when a call changes in a way that could break your mod. New calls are added without changing it.

## IsUsable

```c theme={null}
bool ok = CZAutoz_CarAPI.IsUsable(car);
```

`true` when `car` is a car, is not destroyed, and can be used on this server right now.
**Every other call returns `false` (and does nothing) when this is `false`.** Check it first.

## Reading state

Each call returns `true` and fills the value, or `false` (value `0`) if the car is not usable.

| Call | Value |
| - | - |
| `IsEngineOn(car)` | The engine is running |
| `GetEngineRpm(car, out float rpm)` | Engine RPM |
| `GetFuel01(car, out float v)` | Fuel, `0` to `1` of the tank |
| `GetSpeedKmh(car, out float v)` | Speed in km/h |
| `GetHeadingDeg(car, out float d)` | Compass heading: `0` north, `90` east, `0` to `360` clockwise |
| `GetHealth01(car, out float v)` | The car's overall health, `0` to `1` |
| `GetPartHealth01(car, string slot, out float v)` | Health of the part in a slot, `0` to `1` (for example `"CarBattery"`, `"SparkPlug"`, `"GlowPlug"`, `"CarRadiator"`); `false` if the slot is empty |
| `GetOdometerKm(car, out float km)` | Kilometres on the Vehicles Core [odometer](https://docs.czautoz.co.uk/vehicles/core/admin-panel.md#signals-and-odometer); `false` if the odometer is off for this car |
| `IsLocked(car)` | Locked with a car key (`false` while the server has car keys switched off) |
| `GetLightsState(car, out int s)` | `1` headlights on, `0` off |
| `GetInstalledAddons(car, out array<string> list)` | Class names of the Vehicles Core add-ons fitted to the car (spares in its cargo don't count) |
| `HasAddon(car, string className)` | That add-on is fitted |

## Controlling it

Each call follows the same rules as a player's action. It returns `true` if it was done.

The calls are made for server mods, so they need no driver and no key. They work on a car nobody is in and on a key-locked car, and `Unlock` needs no key. Starting and stopping the engine are refused while someone is in the driver's seat: that player's game runs the engine.

| Call | Does |
| - | - |
| `StartEngine(car)` | Refused while someone is in the driver's seat. Otherwise the driver's start: needs a charged battery, a spark or glow plug, fuel and a working engine. `true` means the start was made; the car's own checks can still refuse it, so use `IsEngineOn` or `OnEngineStarted` to know it is running |
| `StopEngine(car)` | Stops the engine (refused while someone is in the driver's seat) |
| `SetLights(car, bool on)` | The driver's light switch; switching on needs a charged battery |
| `Lock(car)` / `Unlock(car)` | Lock or unlock as a key holder would, without needing the key, while the server has [car keys](https://docs.czautoz.co.uk/vehicles/core/addons.md#car-keys) switched on. `Lock` needs a car that has keys, with the engine off, nobody inside and every door, the hood and the trunk fitted and shut. `Unlock` always works on a locked car. Like a key, they flash the indicators, and a fitted, powered alarm arms on `Lock` (while car alarms are on) and disarms on `Unlock` |

## Events

Server only. They fire only while the car is usable; `OnDestroyed` fires as the car is destroyed. `OnDamaged` gives the damage to the part of the car that was hit.

| Event | Arguments |
| - | - |
| `OnEngineStarted` / `OnEngineStopped` | `(EntityAI car)` |
| `OnDamaged` | `(EntityAI car, float damage)` |
| `OnDestroyed` | `(EntityAI car)` |
| `OnLocked` / `OnUnlocked` | `(EntityAI car)` |

```c theme={null}
void MyOnStarted(EntityAI car) { Print("started: " + car.GetType()); }
CZAutoz_CarAPI.OnEngineStarted.Insert(MyOnStarted);
```

Remove your handlers in your own teardown. Vehicles Core also clears every handler when the mission ends.

A handler must not lock, unlock or delete the car it is told about (the lock events run while the lock is changing); do that later, for example with `CallLater`.

## Example: a convoy mission starts its lead truck

```c theme={null}
if (CZAutoz_CarAPI.IsUsable(truck) && CZAutoz_CarAPI.StartEngine(truck))
{
    CZAutoz_CarAPI.SetLights(truck, true);
    Print("convoy rolling");
}
```


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