AI Core

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 writeUse
An ai-* script or any TypeScript resource@aicore-fivem/lib: inventory, vehicleKeys, online, medical... The lib calls ai-core for you.
A Lua resourceaiLib from ai-lib (shared_script '@ai-lib/init.lua'), or ai-core's exports directly.
An ESX / QB / Qbox scriptNothing 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: resourceExport reads them from CitizenExports in @aicore-fivem/shared. A resource that may not run uses optionalExport("x") (null while stopped).
  • Names: every export also answers with the first letter's case swapped (GetMoney and getMoney).
  • 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 online mirror does this).

Pages

PageWhat
ai-core server exportsCharacters, money, jobs, gangs, items, keys, medical, phone, dispatch, prison, world, buckets, logs, connection, admin panel.
ai-core client exportsPlayer data, HUD, key hints, world sync, items, radial, gestures, looks, dialogs.
Events and stateCORE.* events with payloads, state bags, framework events the bridge fires.
Script exportsExports 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 LuaaiLib in Lua resources.

On this page