ai-core client exports
What ai-core's client exports are, how to call them from TypeScript and Lua, and which lib helper wraps each one.
A client export is a function that ai-core's client side offers to every other resource on the same player's game. Your client script calls it to read the local player's data, hide the HUD, add a radial menu item, check an item, play an emote and so on.
Most of these exports are layers: ai-core does not do the job itself, it forwards the call to whichever script the server runs for that job (the inventory, the clothing script, the radial menu, the emote menu, the death script, the MDT). Your script calls one name and keeps working when the server owner swaps one of those scripts for another.
Before you start
- Every client export is synchronous: it answers at once and never waits. Nothing on these pages returns a Promise, and nothing needs a thread in Lua. The one export whose answer needs time (
OpenItemPicker) answers through an event. - Call them from client code only. The server has its own list: ai-core server exports.
- ai-core must be started. A resource that may run without ai-core uses
optionalExport("ai-core")in TypeScript (it isnullwhile ai-core is stopped). - Every export also answers with the first letter's case swapped:
GetPlayerDataandgetPlayerDataare the same function. - Things a resource adds through these exports (HUD hide reasons, key hints, radial items, world sync pauses) belong to that resource. ai-core removes them when the resource stops, so a crash or restart never leaves the HUD hidden or a dead menu item behind.
Calling an export
import { resourceExport } from "@aicore8/lib/client";
// One typed handle, at the top of the file. Types come from @aicore8/shared (AiCoreClientExports).
const core = resourceExport("ai-core");
RegisterCommand(
"myjob",
() => {
const data = core.GetPlayerData();
console.log(data ? `job: ${data.job.job}` : "no character loaded");
},
false,
);Use the lib helper when there is one
Most exports have a helper in @aicore8/lib/client and the same helper on aiLib for Lua resources (shared_script '@ai-lib/init.lua'). The helpers call the export for you, check its answer and add a change listener where one exists. Prefer them; call the export directly when you cannot use the lib.
| Export | TypeScript lib | Lua aiLib | Page |
|---|---|---|---|
GetPlayerData, IsPlayerLoaded, GetDefinitions | getPlayerData, onPlayerData | aiLib.playerData.get, aiLib.playerData.onChange | Player |
HideHud, ShowHud, IsHudVisible | hud.hide, hud.show, hud.visible, hud.onChange | aiLib.hud.hide, aiLib.hud.show, aiLib.hud.visible | HUD |
OpenHudSettings, HasHudSettings | none | none | HUD |
ShowKeyHint, HideKeyHint | keyHints.show, keyHints.hide | aiLib.keyHints.show, aiLib.keyHints.hide | Keybinds and key hints |
GetKeybindKey, GetKeyHints, OpenKeyboard | none | none | Keybinds and key hints |
PauseWorldSync, ResumeWorldSync | world.pauseSync, world.resumeSync | aiLib.world.pauseSync, aiLib.world.resumeSync | Weather and time sync |
OpenInventory, HasItem, GetCurrentWeapon | inventory.openInventory, inventory.hasItem, inventory.currentWeapon | aiLib.inventory.* (same names) | Items |
OpenItemPicker | itemPicker | aiLib.itemPicker | Items |
AddRadialItem, RemoveRadialItem, RefreshRadial | radial.add, radial.remove, radial.refresh | aiLib.radial.* (same names) | Radial menu |
IsHandsUp, IsPointing, GetGestureProvider, PlayEmote, CancelEmote, GetEmoteProvider | gestures.* | aiLib.gestures.* | Gestures and emotes |
ApplyAppearance, GetPedAppearance, OpenClothingMenu, WearOutfit, ReloadSkin | appearance.apply, read, openMenu, wearOutfit, reloadSkin | aiLib.appearance.* (same names) | Appearance |
IsDead | medical.isDead, medical.onChange | none (call the export) | Medical |
GetSeatbelt, GetSeatbeltProvider | seatbelt.isOn, seatbelt.provider, seatbelt.onChange | aiLib.seatbelt.* (same names) | Seat belt |
OpenMdt | mdt.open | aiLib.mdt.open | MDT |
ExternalNotify | none (used by ai-lib) | none | Notifications |
Do not call exports every frame
Exports cross a resource boundary, which costs more than a local function call. Read a value once, then follow the event that tells you when it changes. Each page names that event; they are all listed in Events and state.
The menus, input dialogs, notifications, prompts, progress bar and minigames are ai-lib's, not ai-core's. Use the lib's notify, menu, input, progress and skillCheck (or the same names on aiLib).