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.
local plate = KOJA.Server.GeneratePlate()
Also available as an export:
local plate = exports['koja-lib']:GeneratePlate()
Returns string — unique plate string (e.g. "ABCD1234")
The format is controlled by Config.SaveVehicleConfig:
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.
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
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.
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
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,
},
})
SaveVehicleToGaragealso sends a Discord webhook log if a URL is configured for'main'inKOJA.Server.Webhooks.
Related pages
- Police — Functions for checking how many police officers are online.
- Callbacks — The callback system allows server scripts to handle requests from clients and vice versa.
- Licenses — Check whether a player holds a specific driving or skill license.
- Money — Functions for reading and modifying a player's money on the server.
- Inventory — Server-side inventory functions.
- Notifications — Send notifications to a player from the server side.
- Server API — back to the section overview