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.

Parameter
Type
Description

length

number

Length of the output string

charset

string

Characters to pick from

Returns string

Example


SaveVehicleToGarage

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

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

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

Last updated