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

# Server

> Available server-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
```

## Exports

### DeleteVehicleEntity

Deletes the vehicle entity from the game world, but keeps its data in the database.

```lua theme={null}
exports['ts-persistence']:DeleteVehicleEntity(vehicleId)
```

| Argument    | Type     | Description                               |
| :---------- | :------- | :---------------------------------------- |
| `vehicleId` | `string` | The unique persistence ID of the vehicle. |

### GetAllVehicles

Get a list of all vehicles currently loaded by the persistence system.

```lua theme={null}
local vehicles = exports['ts-persistence']:GetAllVehicles()
```

**Returns:**

* `table`: A dictionary of all active vehicles.

### DoesVehicleExistInDb

Check if a vehicle exists in the database.

```lua theme={null}
local exists = exports['ts-persistence']:DoesVehicleExistInDb(vehicleId)
```

| Argument    | Type     | Description                        |
| :---------- | :------- | :--------------------------------- |
| `vehicleId` | `string` | The persistence ID of the vehicle. |

**Returns:**

* `boolean`: `true` if it exists, `false` otherwise.

### Reload

Reload all vehicles from the database and refresh the system.

```lua theme={null}
exports['ts-persistence']:Reload()
```

### UpdateVehiclePos

Update the position of a persistent vehicle in memory.

```lua theme={null}
exports['ts-persistence']:UpdateVehiclePos(vehicleId, coords, heading)
```

| Argument    | Type      | Description                        |
| :---------- | :-------- | :--------------------------------- |
| `vehicleId` | `string`  | The persistence ID of the vehicle. |
| `coords`    | `vector3` | The new coordinates.               |
| `heading`   | `number`  | The new heading.                   |

### UnloadAllVehicles

Deletes all persistent vehicle entities from the game world (does not remove their data from the database).

```lua theme={null}
exports['ts-persistence']:UnloadAllVehicles()
```

### SetVehicleDeleteAt

Set a Unix timestamp for when the vehicle should be automatically deleted from the database.

```lua theme={null}
exports['ts-persistence']:SetVehicleDeleteAt(vehicleId, timeTimestamp)
```

| Argument        | Type     | Description                        |
| :-------------- | :------- | :--------------------------------- |
| `vehicleId`     | `string` | The persistence ID of the vehicle. |
| `timeTimestamp` | `number` | The Unix timestamp for deletion.   |

### DeleteVehicleFromDB

Delete a vehicle from the persistence database using its ID.

```lua theme={null}
exports['ts-persistence']:DeleteVehicleFromDB(vehicleId)
```

| Argument    | Type     | Description                                  |
| :---------- | :------- | :------------------------------------------- |
| `vehicleId` | `string` | The persistence ID of the vehicle to delete. |

### DeleteVehicleFromDBByPlate

Delete a vehicle from the persistence database using its plate.

```lua theme={null}
exports['ts-persistence']:DeleteVehicleFromDBByPlate(plate)
```

| Argument | Type     | Description                                           |
| :------- | :------- | :---------------------------------------------------- |
| `plate`  | `string` | The plate of the vehicle to delete from the database. |

### 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, deleteEntity)
```

| 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).                                                        |
| `deleteEntity` | `boolean` \| `nil` | If `true` and the vehicle is currently spawned, its entity will also be deleted from the world. Defaults to `false`. |

**Returns:**

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