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 and the @aicore8/lib helpers (each ai-* script's own exports are on its page under Scripts). Every signature on these pages comes from the source (@aicore8/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 | @aicore8/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 / vRP 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 "@aicore8/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@aicore8/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 you find there |
|---|---|
| ai-core server exports | Every server export of ai-core, one page per area: characters, money, jobs and gangs, items, keys, medical, phone, dispatch, prison, world, banking, billing, logs, admin panel. |
| ai-core client exports | Every client export: player data, HUD, key hints, world sync, items, radial menu, gestures, appearance, seat belt. |
| Events and state | Every event ai-core fires with its arguments, the state bags, and the ESX / QB / Qbox / vRP events the bridge fires. |
| Lib: server | @aicore8/lib/server and the server side of aiLib. |
| Lib: client | @aicore8/lib/client and the client side of aiLib. |
| Lib: shared and fivem | @aicore8/lib/shared and /fivem: exports, scheduling, state bags, input readers, text and numbers. |
| Lib for Lua | How a Lua resource uses aiLib, and the functions only Lua has. |
| Types | Every shared type the signatures use (Vec3, ActionResult, InventoryRef...), field by field. |
| Script pages | Each ai-* script's own exports and events are on its Developer page (for example ai-inventory, including the ox_inventory and qb-inventory APIs it answers). |