Garages
Impound and store vehicles, open a garage menu and list a player's garaged vehicles through whichever garage script the server runs.
Garage calls go through ai-core, never through a garage script's own exports or events (ai-garages included). ai-core forwards each call to the active garage script: the one the panel's Garage script setting picks, or the first one running (ai-garages, jg-advancedgarages, tgiann-realparking and the others in the compatibility list). Each script answers only the actions it really has, so any action can answer false or null with one script and work with another.
A vehicle is a server entity handle.
GetGarageSystem
The resource name of the garage script ai-core forwards to.
Side: Server · Waits: no · Lib: garages.provider()
GetGarageSystem(): string | nulllocal system = exports['ai-core']:GetGarageSystem() -- string or nilParameters
None.
Returns
string | null: the garage script's resource name. null when none runs.
Example
import { addCommand, resourceExport } from "@aicore-fivem/lib/server";
const core = resourceExport("ai-core");
addCommand("garagesystem", { help: "Shows the garage script in use", restricted: true }, () => {
console.log(core.GetGarageSystem() ?? "none");
});ImpoundVehicle
Sends a vehicle in the world to the impound. With garage scripts that only have an impound form on the player's screen, it opens that form for the player in by instead.
Side: Server · Waits: no · Lib: garages.impound
ImpoundVehicle(vehicle: number, by?: number): booleanlocal taken = exports['ai-core']:ImpoundVehicle(vehicle, source)Parameters
Prop
Type
Returns
boolean: true when the garage script took the vehicle over (or opened its form). false when nothing took it: no garage script runs, it has no impound, the vehicle is not one it knows, or vehicle is not an existing vehicle. On false the vehicle is still in the world: delete it yourself if it must go.
Example
import { onClientCallback, resourceExport, vehicleNearPlayer } from "@aicore-fivem/lib/server";
import { fail, oneArg, readId } from "@aicore-fivem/lib/shared";
const core = resourceExport("ai-core");
onClientCallback("myscript:impound", { args: oneArg(readId) }, (source, netId) => {
if (core.GetDutyJob(source) !== "police") return fail("NOT_POLICE");
const vehicle = vehicleNearPlayer(source, netId, { metres: 5 });
if (!vehicle) return fail("TOO_FAR");
if (!core.ImpoundVehicle(vehicle, source)) DeleteEntity(vehicle);
return { ok: true };
});StoreVehicleInGarage
Puts a vehicle in the world into a garage, with its condition.
Side: Server · Waits: no · Lib: garages.store
StoreVehicleInGarage(vehicle: number, garage?: string | null, by?: number): booleanlocal stored = exports['ai-core']:StoreVehicleInGarage(vehicle, 'legion', source)Parameters
Prop
Type
Returns
boolean: true when the garage script took the vehicle. false when nothing took it (no garage script, no store action, unknown garage, a vehicle the script does not own) or vehicle is not an existing vehicle.
Example
import { onClientCallback, resourceExport, vehicleOf } from "@aicore-fivem/lib/server";
import { fail } from "@aicore-fivem/lib/shared";
const core = resourceExport("ai-core");
// A valet stores the car the player is driving into the nearest garage.
onClientCallback("myscript:valetStore", (source) => {
const vehicle = vehicleOf(source, { driver: true });
if (!vehicle) return fail("NOT_DRIVING");
return core.StoreVehicleInGarage(vehicle, null, source) ? { ok: true } : fail("STORE_FAILED");
});OpenGarage
Opens the active garage script's garage menu for a player.
Side: Server · Waits: no · Lib: garages.open
OpenGarage(source: number, garage?: string | null): booleanlocal opened = exports['ai-core']:OpenGarage(source, 'legion')Parameters
Prop
Type
Returns
boolean: true when the menu opened. false when the player is not online, no garage script runs or it has no menu that can be opened from outside.
Example
import { onClientCallback, resourceExport, near } from "@aicore-fivem/lib/server";
import { fail } from "@aicore-fivem/lib/shared";
const core = resourceExport("ai-core");
const MOTEL_GARAGE = { x: 273.1, y: -343.9, z: 44.9 };
onClientCallback("myscript:motelGarage", { guards: [near(MOTEL_GARAGE, 3)] }, (source) =>
core.OpenGarage(source, "motel") ? { ok: true } : fail("GARAGE_FAILED"),
);GetGaragedVehicles
A player's vehicles kept by the garage script: in a garage or in the impound.
Side: Server · Waits: no (answers through done) · Lib: garages.stored(source) returns a Promise
GetGaragedVehicles(source: number, done: (vehicles: GaragedVehicle[] | null) => void): voidexports['ai-core']:GetGaragedVehicles(source, function(vehicles) end) -- list or nilParameters
Prop
Type
Returns
Nothing. done gets one entry per vehicle with plate, model (or null), garage (or null) and impounded (GaragedVehicle), or null when the player is not online, no garage script runs, it cannot list vehicles or it failed. Without a function as done the call does nothing.
Example
import { onClientCallback, resourceExport } from "@aicore-fivem/lib/server";
import { fail } from "@aicore-fivem/lib/shared";
import type { GaragedVehicle } from "@aicore-fivem/shared";
const core = resourceExport("ai-core");
// The impound desk lists the player's impounded cars.
onClientCallback("myscript:impoundList", async (source) => {
const list = await new Promise<GaragedVehicle[] | null>((resolve) => core.GetGaragedVehicles(source, resolve));
if (!list) return fail("GARAGE_UNKNOWN");
return { ok: true, plates: list.filter((v) => v.impounded).map((v) => v.plate) };
});