Koja Scripts
KOJA-LIB

Vehicle

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

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)
ParameterTypeDescription
lengthnumberLength of the output string
charsetstringCharacters 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

FieldTypeDescription
playertableFramework player object (for webhook logging)
identifierstringPlayer character identifier
vehicle.namestringVehicle model name (e.g. "adder")
vehicle.platestringLicense plate (use GeneratePlate())
vehicle.pricenumberPurchase 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,
    },
})

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

  • 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