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

# Client

> Available client-side exports for interacting with the persistence system.

You can verify if the script is running by checking for the resource state:

```lua theme={null}
if GetResourceState('ts-persistence') == 'started' then
    -- Script is running
end
```

## Warning

### Networked Vehicles

All vehicle entities must be networked in order to be persisted. If a non-networked vehicle is passed, the script will return `nil` or indicate failure.

## Exports

### IsVehiclePersistenceDisabled

Check if persistence is disabled for a vehicle.

```lua theme={null}
local isDisabled = exports['ts-persistence']:IsVehiclePersistenceDisabled(vehicle)
```

| Argument  | Type     | Description                  |
| :-------- | :------- | :--------------------------- |
| `vehicle` | `entity` | The vehicle entity to check. |

**Returns:**

* `boolean`: `true` if persistence is disabled, `false` otherwise.

### SetVehiclePersistenceDisabled

Enable or disable persistence for a vehicle.

```lua theme={null}
exports['ts-persistence']:SetVehiclePersistenceDisabled(vehicle, state)
```

| Argument  | Type      | Description                                          |
| :-------- | :-------- | :--------------------------------------------------- |
| `vehicle` | `entity`  | The vehicle entity to modify.                        |
| `state`   | `boolean` | `true` to disable persistence, `false` to enable it. |

### CreateVehicle

Manually create persistence data for a vehicle. This is usually handled automatically, but can be forced if needed.

```lua theme={null}
local id = exports['ts-persistence']:CreateVehicle(vehicle)
```

| Argument  | Type     | Description                    |
| :-------- | :------- | :----------------------------- |
| `vehicle` | `entity` | The vehicle entity to persist. |

**Returns:**

* `string` | `nil`: The persistence ID if successful, `nil` otherwise.

### UpdateVehicle

Manually update the persistence data for a vehicle.

```lua theme={null}
local success = exports['ts-persistence']:UpdateVehicle(vehicle)
```

| Argument  | Type     | Description                   |
| :-------- | :------- | :---------------------------- |
| `vehicle` | `entity` | The vehicle entity to update. |

**Returns:**

* `boolean` | `nil`: `true` if successful, `nil` otherwise.

### GetVehiclePersistenceId

Get the persistence ID of a vehicle.

```lua theme={null}
local id = exports['ts-persistence']:GetVehiclePersistenceId(vehicle)
```

| Argument  | Type     | Description         |
| :-------- | :------- | :------------------ |
| `vehicle` | `entity` | The vehicle entity. |

**Returns:**

* `string` | `nil`: The persistence ID if found, `nil` otherwise.

### GetVehiclePersistenceData

Get the full persistence data for a vehicle.

```lua theme={null}
local data = exports['ts-persistence']:GetVehiclePersistenceData(vehicle)
```

| Argument  | Type     | Description         |
| :-------- | :------- | :------------------ |
| `vehicle` | `entity` | The vehicle entity. |

**Returns:**

* `table` | `nil`: The vehicle data table if found, `nil` otherwise.

The returned table contains information such as:

* `netId`: Network ID
* `plate`: Vehicle plate
* `coords`: Position
* `hash`: Model hash
* `model`: Model name
* `props`: Vehicle properties (mods, colors)
* `trailer`: Trailer data
* `doorStatus`: Door locks
* `damageData`: Health and fuel
* `deformation`: Visual deformation (if plugin enabled)

<Info>
  You can find the detailed breakdown of the returned data structure in the [Data Structure](/scripts/persistance/data-structure) page.
</Info>

### ForgetVehicle

Forget the persistence entry for a vehicle, completely removing it from the persistent system and the database.

```lua theme={null}
local success = exports['ts-persistence']:ForgetVehicle(vehicleId, plate)
```

| Argument    | Type              | Description                                                        |
| :---------- | :---------------- | :----------------------------------------------------------------- |
| `vehicleId` | `string` \| `nil` | The persistence ID of the vehicle (optional if plate is provided). |
| `plate`     | `string` \| `nil` | The plate of the vehicle (optional if vehicleId is provided).      |

**Returns:**

* `boolean`: `true` if successful, `false` otherwise.
