Server exports
How to call ai-core's server exports from Lua and TypeScript, and the list of every export group.
ai-core is the framework resource. Other resources ask it for a player's character, money, jobs and items, and send it work such as "give this player a key" or "send a police alert". They do that through exports: functions ai-core makes callable from any other resource on the server.
These pages list every server export ai-core registers, grouped by topic. Each entry shows what the export does, its exact signature, every parameter, what it returns in every case, and a working example in TypeScript and Lua.
Calling an export
An export is called by the name of the resource that owns it (ai-core) and the export's name.
import { resourceExport } from "@aicore8/lib/server";
// One typed handle per file, at the top. It is safe here: FiveM looks each
// export up on first use and forgets it when ai-core restarts.
const core = resourceExport("ai-core");
export function cashOf(source: number): number {
return core.GetMoney(source, "cash") ?? 0;
}What to know before you start:
- TypeScript types.
resourceExport("ai-core")is typed fromAiCoreServerExportsin@aicore8/shared, so your editor knows every name, parameter and return type. Never writeresourceExport("ai-core").GetMoney(...)inside a function: keep the one handle at the top of the file. - Lua uses a colon. Write
exports['ai-core']:GetMoney(source, 'cash'), not a dot. Anullanswer arrives in Lua asnil, an array as a Lua list (index 1 first), an object as a table. - Two spellings. Every export also answers with the first letter's case swapped:
GetMoneyandgetMoneyare the same function. - Exports never wait. Every export answers at once with a small value. When the answer needs the database (a stored look, a list of bills), the export takes a
donecallback instead of returning a Promise, because a Promise cannot cross from one resource to another. - Not in hot paths. An export call copies its arguments and its answer. Do not call exports every frame or for every player in a loop. For "who is on duty", a character's name or jobs across many players, use the lib's
onlinemirror, which follows ai-core's events (Lib: server). - ai-core must run first. Put
dependency 'ai-core'in yourfxmanifest.lua(an ai-* resource lists it inpackage.jsonfxDependencies), so your resource starts after ai-core. sourceis the player's server id. It is the number FiveM gives a connected player. A character id (charId) is a different number: the id of the character row in the database.
The lib or the export?
Most exports have a wrapper in @aicore8/lib/server (and many in Lua's aiLib). The wrapper calls the same export, so the behaviour is identical; it only reads nicer (inventory.addItem(source, "water") instead of core.AddItem(source, "water")) and turns callbacks into Promises where that is safe. Each entry names its wrapper on the Lib line. Use whichever you like; a Lua resource without ai-lib calls the export directly.
Examples on these pages
The examples are complete server files. TypeScript examples use the lib's addCommand and onClientCallback; Lua examples use ai-lib's aiLib.addCommand and aiLib.onClientCallback, which need these lines in your fxmanifest.lua:
shared_script '@ai-lib/init.lua'
dependency 'ai-lib'
dependency 'ai-core'Waiting Lua calls (aiLib.progressFor, Wait) only work inside a thread; command and callback handlers already run in one.
Types
Types that appear on several pages (CharacterInfo, InventoryRef, DispatchAlert...) are documented once with every field on the Types page and linked from each entry that uses them.
Export groups
Characters and players
Player data, characters, server id lookups, switching character, offline positions, players in scope.
Stored characters
Any character, loaded or not: find it, read it, its money, jobs, gangs, metadata, name, play time, save, delete.
Money and accounts
Balances, adding and removing money, job and gang accounts, transfers, account types.
Jobs and gangs
Memberships, duty, grades, on-duty counts, prime time, job and gang definitions.
Metadata and settings
A character's metadata bag, the server's branding, outdated scripts.
Items
Add, remove, count and check items, stashes, script shops, usable items, item definitions.
Vehicle keys
Give, remove and check vehicle keys through whichever key script runs.
Fuel
Read and set a vehicle's fuel through whichever fuel script runs.
Door locks
Lock, unlock and read doors through whichever door lock script runs.
Garages
Impound, store, open a garage menu, list a player's garaged vehicles.
Medical
Revive, heal and check whether a player is down.
EMS
How many medics are free, distress calls.
Appearance
A character's stored look from whichever clothing script runs.
Phone
Phone numbers, mails, text messages and phone notifications.
Dispatch
Police and job alerts through whichever alert system runs.
MDT
Fines, warrants, arrests and jail records in the police MDT.
Prison
Jail, release and time left.
Banking
Open a bank screen, a job's society balance.
Billing
Send bills, list and pay a player's open bills.
Stress and needs
Add or relieve stress, refill hunger and thirst.
Time and weather
Weather, game time, blackout and frozen time.
Routing buckets
Take and give back a free routing bucket for a separate world.
Logs
Send logs to Discord, Fivemanage, FiveM Stats and the console.
Connection checks
Checks every connecting player passes, scripts that replace others.
Admin panel and commands
Panel registration, the Commands tab, lookup lists, external settings screens.
vRP bridge
Exports ai-core's built-in vRP bridge uses.
Related pages
- Client exports: what ai-core answers on the player's own game.
- Events and state: the events ai-core fires (
ai-core:playerLoaded,ai-core:moneyChanged...), which let your resource follow changes instead of asking again. - Lib: server: the wrappers named on each entry.