AI Core

ai-core server exports

Every server export of ai-core - signature and what it does, grouped by area.

Typed as AiCoreServerExports in @aicore-fivem/shared (exports.ts). In TypeScript take one handle per file; in Lua call exports['ai-core'] directly.

TypeScript
import { resourceExport } from "@aicore-fivem/lib/server";
const core = resourceExport("ai-core");

Types used below: CharacterInfo, AiPlayerData, JobMembership ({ job, grade }), GangMembership ({ gang, grade }), InventoryRef (a player's server id or another inventory's id: stash name, plate), KeyPurpose (purchase, garage, job, rental, temporary), all in @aicore-fivem/shared.

Characters and players

ExportWhat
GetPlayerData(src: number): AiPlayerData | nullEverything ai-core keeps for a loaded player: character, money, jobs, duty, gangs, metadata.
GetCharacter(src: number): CharacterInfo | nullThe loaded character (id, citizenid, names, birthdate, sex, nationality).
GetSourceByCharId(charId: number): number | nullServer id of the player playing that character.
GetSourceByCitizenId(citizenid: string): number | nullThe same by citizen id.
GetLoadedSources(): number[]Server ids of every player with a loaded character.
GetFivemId(src: number): string | nullThe player's FiveM identifier.
SwitchCharacter(src: number): booleanSends the player back to the character screen.
SetOfflinePosition(charId: number, position: { x, y, z, heading? }): booleanMoves a stored (not loaded) character's spawn point; false while it is loaded.
GetPlayersInScope(source: number): number[]Players in a player's OneSync scope (about 424 m).
TypeScript
const character = core.GetCharacter(source);
if (character) console.log(character.firstname, character.lastname);
Lua
local character = exports['ai-core']:GetCharacter(source)
if character then print(character.firstname, character.lastname) end

Money

Accounts are the ones in the panel's Accounts list (cash, bank by default). reason goes into the ledger.

ExportWhat
GetMoney(src: number, account: string): number | nullA player's balance.
AddMoney(src: number, account: string, amount: number, reason?: string): booleanAdds money.
RemoveMoney(src: number, account: string, amount: number, reason?: string): booleanTakes money; false when the account cannot pay.
SetMoney(src: number, account: string, amount: number, reason?: string): booleanSets a balance.
GetSharedMoney(ownerType: "job" | "gang", ownerId: string, account: string): number | nullA job's or gang's shared account.
AddSharedMoney(ownerType, ownerId, account, amount: number, reason?: string): booleanAdds to a shared account.
RemoveSharedMoney(ownerType, ownerId, account, amount: number, reason?: string): booleanTakes from a shared account.
TransferMoney(from: MoneyRef, to: MoneyRef, amount: number, reason?: string, fee?: number): booleanMoves money between two accounts in one transaction with both ledger rows; from also pays fee.
GetAccountTypes(): Record<string, AccountTypeDefinition>The account list (label, start, allowNegative).

MoneyRef is { source, account } for a loaded player or { owner: "job" \| "gang", id, account } for a shared account.

TypeScript
if (core.RemoveMoney(source, "bank", 500, "fine")) {
  core.AddSharedMoney("job", "police", "bank", 500, "fine");
}
Lua
if exports['ai-core']:RemoveMoney(source, 'bank', 500, 'fine') then
  exports['ai-core']:AddSharedMoney('job', 'police', 'bank', 500, 'fine')
end

Jobs and gangs

A character can hold several jobs and gangs, with at most one on-duty job and one active gang.

ExportWhat
GetJobs(src: number): JobMembership[] | nullEvery job membership.
GetCurrentJob(src: number): JobMembership | nullThe job other scripts see as "the" job: on duty, else last on duty, else the first.
GetDutyJob(src: number): string | nullThe job the player is on duty for.
SetDuty(src: number, job: string | null): booleanPuts the player on duty for a job, or off duty (null).
SetJob(src: number, job: string, grade: number): booleanAdds a job or changes its grade.
RemoveJob(src: number, job: string): booleanRemoves a job membership.
GetOnDutyCount(job: string): numberHow many players are on duty in a job.
IsPrimeTime(job?: string): booleanPrime time for a job (tgiann-policealert's hours while it runs, else the panel's hours).
GetGangs(src: number): GangMembership[] | nullEvery gang membership.
GetActiveGang(src: number): string | nullThe active gang.
SetGang(src: number, gang: string, grade: number): booleanAdds a gang or changes its grade.
RemoveGang(src: number, gang: string): booleanRemoves a gang membership.
SetActiveGang(src: number, gang: string | null): booleanPicks the active gang.
GetJobDefinitions(): Record<string, JobDefinition>Every job definition (a copy: for rare reads).
GetJobDefinition(job: string): JobDefinition | nullOne job: label, type, defaultDuty, listed?, grades (label, salary, boss).
GetGangDefinitions(): Record<string, GangDefinition>Every gang definition.
GetGangDefinition(gang: string): GangDefinition | nullOne gang: label, grades.
TypeScript
if (core.GetDutyJob(source) === "police") {
  const officers = core.GetOnDutyCount("police");
}
Lua
if exports['ai-core']:GetDutyJob(source) == 'police' then
  local officers = exports['ai-core']:GetOnDutyCount('police')
end

Metadata and server settings

ExportWhat
GetMeta(src: number, key: string): unknownOne value of the character's metadata bag.
SetMeta(src: number, key: string, value: unknown): booleanSets a metadata value.
GetBranding(): BrandingThe server's name, subtitle, taglines and background from the panel's General settings.
GetUpdates(): UpdateInfo[]Scripts with a newer GitHub release than the running version.

Items

ai-core's inventory layer: the active inventory answers (false, 0 or empty while none runs).

ExportWhat
AddItem(inv: InventoryRef, item: string, count?: number, metadata?: ItemMetadata, slot?: number): booleanAdds items.
RemoveItem(inv: InventoryRef, item: string, count?: number, metadata?: ItemMetadata, slot?: number): booleanRemoves items.
GetItemCount(inv: InventoryRef, item: string, metadata?: ItemMetadata): numberHow many of an item.
HasItem(inv: InventoryRef, item: string, count?: number): booleanWhether the inventory holds at least count.
CanCarryItem(inv: InventoryRef, item: string, count?: number, metadata?: ItemMetadata): booleanWhether the items fit.
GetItems(inv: InventoryRef): InventoryStack[]Every stack (name, label, count, slot, metadata).
ClearInventory(inv: InventoryRef): voidEmpties an inventory.
RegisterStash(name: string, label: string, slots: number, maxWeight: number, jobs?: string[]): voidA stash; kept and registered again with every inventory that becomes active.
OpenInventory(source: number, inv: InventoryRef): booleanOpens a stash or another inventory on the player's screen.
RegisterUsableItem(name: string, handler: UsableItemHandler): voidhandler(source, item) runs on use; returning false keeps the item. Kept across inventory restarts.
GetItemDefinition(name: string): ItemDefinition | nullOne item (name, label, weight, unique, close, description, image?).
GetItemDefinitions(): Record<string, ItemDefinition>Every item.
UseItem(source: number, name: string, item?: unknown): unknownRuns the registered handler (the bridge calls it).
IsUsableItem(name: string): booleanWhether a handler is registered.
TypeScript
core.RegisterUsableItem("bandage", (source, item) => {
  // heal, then let the inventory take the item
});
if (core.CanCarryItem(source, "water", 2)) core.AddItem(source, "water", 2);
Lua
exports['ai-core']:RegisterUsableItem('bandage', function(source, item)
  -- heal, then let the inventory take the item
end)
if exports['ai-core']:CanCarryItem(source, 'water', 2) then
  exports['ai-core']:AddItem(source, 'water', 2)
end

Vehicle keys

A vehicle is a server entity handle or a plate; purpose defaults to temporary.

ExportWhat
GiveVehicleKeys(source: number, vehicle: number | string, purpose?: KeyPurpose): voidGives keys through the active key system.
RemoveVehicleKeys(source: number, vehicle: number | string): voidTakes keys away.
HasVehicleKeys(source: number, vehicle: number | string): booleanWhether the player has the keys.
Lua
exports['ai-core']:GiveVehicleKeys(source, 'AB12CDE', 'rental')

Medical

ExportWhat
GetMedicalSystem(): string | nullThe death script ai-core forwards to.
RevivePlayer(source: number): booleanGets a downed player up where they lie; false when not down or no death script runs.
HealPlayer(source: number): booleanFull health for a player who is not down.
IsPlayerDead(source: number): booleanWhether the player is down.

Appearance

ExportWhat
GetAppearanceSystem(): string | nullThe clothing script ai-core reads looks from.
GetCharacterAppearance(charId: number, done: (look: CharacterAppearance | null) => void): voidA character's stored look (loaded or not); done gets { model, data } or null.
Lua
exports['ai-core']:GetCharacterAppearance(charId, function(look)
  if look then TriggerClientEvent('myscript:dress', source, look) end
end)

Phone

Whatever phone script runs answers (none: null or false).

ExportWhat
GetPhoneNumber(source: number): string | nullThe player's number.
GetSourceByPhone(number: string): number | nullThe player with that number.
HasPhone(source: number): booleanWhether the player has a phone.
SendPhoneMail(to: number | string, mail: PhoneMail): booleanA mail (sender, subject, message) to a player or number.
SendPhoneMessage(from: string, to: number | string, text: string): booleanA text message.
PhoneNotify(source: number, notification: PhoneNotification): booleanA phone notification (title, message, app?).

Dispatch

ExportWhat
SendDispatchAlert(alert: DispatchAlert): booleanShows an alert to on-duty members of jobs through the active alert system; false when none runs.

DispatchAlert: title, and optional code, message, coords, jobs, source (the suspect), blip (sprite, color?, scale?), duration (seconds), icon, priority (normal or high). Texts are already translated.

TypeScript
core.SendDispatchAlert({
  code: "10-90",
  title: "Store robbery",
  jobs: ["police"],
  source,
  priority: "high",
});
Lua
exports['ai-core']:SendDispatchAlert({
  code = '10-90', title = 'Store robbery', jobs = { 'police' }, source = source, priority = 'high',
})

Prison

ExportWhat
JailPlayer(source: number, minutes: number, by?: number): booleanJails a player through the running prison script.
ReleasePlayer(source: number): booleanReleases a player.
GetJailTime(source: number): numberMinutes left.

Time and weather

The qb-weathersync contract of whatever weather script runs (null or false while none runs).

ExportWhat
GetWeather(): string | nullThe current weather type.
SetWeather(type: string): booleanSets the weather (EXTRASUNNY, RAIN...).
GetTime(): { hour, minute } | nullThe game time.
SetTime(hour: number, minute?: number): booleanSets the game time.
SetBlackout(on: boolean): booleanBlackout on or off.
FreezeTime(on: boolean): booleanFreezes or unfreezes the clock.

Routing buckets

ExportWhat
AcquireBucket(tag: string): numberA free routing bucket for the calling resource (no population, strict lockdown); freed when it stops.
ReleaseBucket(id: number): booleanGives a bucket back (only the resource that took it); move its players out first.

Logs

ExportWhat
Log(channel: string, message: string, options?: LogOptions): voidSends a log of the calling resource to every provider turned on (Discord, Fivemanage, FiveM Stats, console). options: level, source, target, metadata.
LogChannels(channels: Record<string, LogChannel>): voidDescribes the calling resource's channels (dataset, active); call once at start.
Lua
exports['ai-core']:Log('sales', 'Sold a car', { source = source, metadata = { price = 25000 } })

Connection

ExportWhat
AddConnectionCheck(id: string, check: (source, identifiers) => string | null | undefined): voidA check every connecting player passes: return a refusal text, or null to let them in.
RegisterReplacement(remove: string | string[], keep?: string): voidDeclares that keep (default: the caller) makes remove unneeded: a console warning, joins refused while both run.
GetConflicts(): { keep, remove, running, from }[]Scripts installed next to the one that replaces them.

Admin panel and commands

ExportWhat
RegisterAdminPanel(resource: string): voidA resource with a panel announces itself (the lib's AdminPanel does it).
AdminPanelChanged(delta: AdminDelta): voidA panel resource changed a record; ai-core forwards it to admins with the panel open.
RegisterCommands(resource: string, commands: CommandInfo[]): voidThe lib's addCommand lists a resource's commands in the Commands tab.
GetLookupValues(source: LookupSource): string[]Values of a lookup list (item, job, gang, account...) for panel validation.
RegisterExternalPanel(panel: { id?, label, icon?, description?, command?, url? }): voidLists another script's own settings screen on the dashboard (opened by command or embedded url).
Lua
exports['ai-core']:RegisterExternalPanel({
  label = 'My script', icon = 'gear', description = 'Its own settings', command = 'myscriptconfig',
})

On this page