API overview
How to call AI Core from another script - exports, events and the lib, in TypeScript and Lua.
Everything another script can call: ai-core's exports, the events it fires, the exports of each ai-* script and the @aicore-fivem/lib helpers. Every signature on these pages comes from the source (@aicore-fivem/shared exports.ts, the lib's JSDoc, each script's export calls).
Pick the right door
| You write | Use |
|---|---|
| An ai-* script or any TypeScript resource | @aicore-fivem/lib: inventory, vehicleKeys, online, medical... The lib calls ai-core for you. |
| A Lua resource | aiLib from ai-lib (shared_script '@ai-lib/init.lua'), or ai-core's exports directly. |
| An ESX / QB / Qbox script | Nothing new: the bridge answers the framework's own API. See Layers and the bridge. |
Items, vehicle keys, alerts, phone, weather, prison, clothing and deaths always go through ai-core, never a specific script's exports: ai-core forwards to whatever script the server runs for that job.
Calling an export
import { resourceExport } from "@aicore-fivem/lib/server";
// One typed handle per resource, at the top of the file.
const core = resourceExport("ai-core");
const cash = core.GetMoney(source, "cash");local cash = exports['ai-core']:GetMoney(source, 'cash')- Types:
resourceExportreads them fromCitizenExportsin@aicore-fivem/shared. A resource that may not run usesoptionalExport("x")(null while stopped). - Names: every export also answers with the first letter's case swapped (
GetMoneyandgetMoney). - Exports are synchronous and return small values. Where a value needs time (a stored look), the export takes a callback: no promise crosses a resource boundary.
- Hot paths follow ai-core's events instead of calling exports in a loop (the lib's
onlinemirror does this).
Pages
| Page | What |
|---|---|
| ai-core server exports | Characters, money, jobs, gangs, items, keys, medical, phone, dispatch, prison, world, buckets, logs, connection, admin panel. |
| ai-core client exports | Player data, HUD, key hints, world sync, items, radial, gestures, looks, dialogs. |
| Events and state | CORE.* events with payloads, state bags, framework events the bridge fires. |
| Script exports | Exports of each ai-* script, including the ox_inventory, pma-voice and qb-weathersync APIs they stand in for. |
| Lib: client | @aicore-fivem/lib/client. |
| Lib: server | @aicore-fivem/lib/server. |
| Lib: shared and fivem | @aicore-fivem/lib/shared and /fivem. |
| Lib for Lua | aiLib in Lua resources. |