> For the complete documentation index, see [llms.txt](https://docs.kojascripts.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kojascripts.eu/koja-lib/api-reference/server-api/vehicle.md).

# Vehicle

Server-side vehicle utilities for plate generation and garage saving.

***

## GeneratePlate

Generates a unique vehicle license plate that does not already exist in the database.

```lua
local plate = KOJA.Server.GeneratePlate()
```

Also available as an export:

```lua
local plate = exports['koja-lib']:GeneratePlate()
```

**Returns** `string` — unique plate string (e.g. `"ABCD1234"`)

The format is controlled by `Config.SaveVehicleConfig`:

```lua
Config.SaveVehicleConfig = {
    Charset       = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
    NumberCharset = "0123456789",
    Letters       = 4,
    Numbers       = 4,
    Separator     = "",
}
```

> The function queries the database to ensure uniqueness. It loops until it finds an unused plate, so it may take more than one tick for busy servers.

***

## GetRandomString

Generate a random string from a given character set.

```lua
local str = KOJA.Server.GetRandomString(length, charset)
```

| Parameter | Type     | Description                 |
| --------- | -------- | --------------------------- |
| `length`  | `number` | Length of the output string |
| `charset` | `string` | Characters to pick from     |

**Returns** `string`

**Example**

```lua
local code = KOJA.Server.GetRandomString(6, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
-- e.g. "K3X9TL"
```

***

## SaveVehicleToGarage

Save a vehicle to the player's garage in the database. Supports ESX (`owned_vehicles`) and QBCore (`player_vehicles`) table schemas.

```lua
KOJA.Server.SaveVehicleToGarage(data)
```

### data fields

| Field           | Type     | Description                                   |
| --------------- | -------- | --------------------------------------------- |
| `player`        | `table`  | Framework player object (for webhook logging) |
| `identifier`    | `string` | Player character identifier                   |
| `vehicle.name`  | `string` | Vehicle model name (e.g. `"adder"`)           |
| `vehicle.plate` | `string` | License plate (use `GeneratePlate()`)         |
| `vehicle.price` | `number` | Purchase price (logged only)                  |

**Example**

```lua
local plate = KOJA.Server.GeneratePlate()
local player = KOJA.Server.GetPlayerBySource(source)
local identifier = KOJA.Server.GetPlayerIdentifier(source)

KOJA.Server.SaveVehicleToGarage({
    player     = player,
    identifier = identifier,
    vehicle    = {
        name  = 'adder',
        plate = plate,
        price = 500000,
    },
})
```

> `SaveVehicleToGarage` also sends a Discord webhook log if a URL is configured for `'main'` in `KOJA.Server.Webhooks`.


---

# 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://docs.kojascripts.eu/koja-lib/api-reference/server-api/vehicle.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.
