Vehicles
plateOf, normalizePlate, vehicleTypeOfClass, toVehicleProps and toVehicleSetup: plates as keys, spawn types, and vehicle looks from untrusted data.
import { plateOf } from "@aicore-fivem/lib/fivem"; // also on /client and /server
import { normalizePlate, vehicleTypeOfClass, toVehicleProps, toVehicleSetup } from "@aicore-fivem/lib/shared";Plates
GTA pads plates to 8 characters with spaces (" AI 1 "). Every script that keeps data per plate (keys, fuel, garages) uses the trimmed upper-case plate as the key, so the same vehicle matches everywhere.
plateOf
A vehicle's plate as keys use it: read from the entity, trimmed, upper case.
Side: Client and server · Waits: no
plateOf(vehicle: number): stringLua: no twin; use GetVehicleNumberPlateText(vehicle):match('^%s*(.-)%s*$'):upper().
Parameters
Prop
Type
Returns
string: the plate, trimmed and upper case.
Example
import { plateOf, vehicleOf } from "@aicore-fivem/lib/server";
function plateOfPlayerVehicle(source: number): string | null {
const vehicle = vehicleOf(source);
return vehicle === 0 ? null : plateOf(vehicle);
}normalizePlate
The same trim and upper case for a plate you already have as text (typed by a player, stored in a database, sent by another script).
Side: Client, server and NUI · Waits: no
normalizePlate(plate: string): stringLua: no twin; use plate:match('^%s*(.-)%s*$'):upper().
Parameters
Prop
Type
Returns
string: trimmed, upper case.
Example
import { normalizePlate } from "@aicore-fivem/lib/shared";
normalizePlate(" ai 123 "); // "AI 123"Spawning
vehicleTypeOfClass
Turns a GTA vehicle class (GetVehicleClassFromName) into the type CreateVehicleServerSetter needs: "bike", "boat", "heli", "plane", "train" or "automobile". Lib spawnVehicle does this for you; use it only when you call CreateVehicleServerSetter yourself.
Side: Client, server and NUI · Waits: no
vehicleTypeOfClass(vehicleClass: number): stringLua: no twin.
Parameters
Prop
Type
Returns
string: the spawn type. Every class not listed above is "automobile".
Example
import { vehicleTypeOfClass } from "@aicore-fivem/lib/shared";
const type = vehicleTypeOfClass(GetVehicleClassFromName("frogger")); // "heli"GetVehicleClassFromName is a client native. The server learns a model's type from a client (lib spawnVehicle asks ai-core's client for you).
Looks from untrusted data
toVehicleProps
Checks stored or received vehicle props and returns a clean VehicleProps object, or null when the data is not in that shape. Missing optional parts get defaults (stock mods, no livery, full health); unknown fields are dropped; the plate is cut to 8 characters.
Side: Client, server and NUI · Waits: no
toVehicleProps(value: unknown): VehicleProps | nullLua: no twin.
Parameters
Prop
Type
Returns
VehicleProps, or null when value is not an object, v is not 1, model or plate is missing, or one of colors, extraColors, neonColor, tyreSmoke, mods, extras, neon is missing or the wrong length.
Example
import { optionalExport } from "@aicore-fivem/lib/server";
import { toVehicleProps } from "@aicore-fivem/lib/shared";
function storedColors(vehicleId: number): [number, number] | null {
const vehicle = optionalExport("ai-vehicles")?.GetVehicle(vehicleId);
const props = toVehicleProps(vehicle?.props);
return props ? props.colors : null;
}toVehicleSetup
Checks a received VehicleSetup field by field: wrong fields are dropped, the right ones kept. Use it on a setup that comes from a client or another resource before you pass it to spawnVehicle.
Side: Client, server and NUI · Waits: no
toVehicleSetup(value: unknown): VehicleSetup | nullLua: no twin.
Parameters
Prop
Type
Returns
VehicleSetup with only the valid fields (colours 0-255, livery 0-100, windowTint 0-6, dirt 0-15; maxed and engineOn only when exactly true). null when value is not an object.
Example
import { toVehicleSetup } from "@aicore-fivem/lib/shared";
toVehicleSetup({ colors: [27, 27], windowTint: 9, maxed: "yes" });
// { colors: [27, 27], windowTint: undefined, maxed: undefined, ... }: the bad fields are droppedA client must never choose maxed: true or a free colour for a vehicle it pays for: check the price on the server for what the setup contains.