AI Core

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 is null while ai-core is stopped).
  • Every export also answers with the first letter's case swapped: GetPlayerData and getPlayerData are 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

resource/client/index.ts
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.

ExportTypeScript libLua aiLibPage
GetPlayerData, IsPlayerLoaded, GetDefinitionsgetPlayerData, onPlayerDataaiLib.playerData.get, aiLib.playerData.onChangePlayer
HideHud, ShowHud, IsHudVisiblehud.hide, hud.show, hud.visible, hud.onChangeaiLib.hud.hide, aiLib.hud.show, aiLib.hud.visibleHUD
OpenHudSettings, HasHudSettingsnonenoneHUD
ShowKeyHint, HideKeyHintkeyHints.show, keyHints.hideaiLib.keyHints.show, aiLib.keyHints.hideKeybinds and key hints
GetKeybindKey, GetKeyHints, OpenKeyboardnonenoneKeybinds and key hints
PauseWorldSync, ResumeWorldSyncworld.pauseSync, world.resumeSyncaiLib.world.pauseSync, aiLib.world.resumeSyncWeather and time sync
OpenInventory, HasItem, GetCurrentWeaponinventory.openInventory, inventory.hasItem, inventory.currentWeaponaiLib.inventory.* (same names)Items
OpenItemPickeritemPickeraiLib.itemPickerItems
AddRadialItem, RemoveRadialItem, RefreshRadialradial.add, radial.remove, radial.refreshaiLib.radial.* (same names)Radial menu
IsHandsUp, IsPointing, GetGestureProvider, PlayEmote, CancelEmote, GetEmoteProvidergestures.*aiLib.gestures.*Gestures and emotes
ApplyAppearance, GetPedAppearance, OpenClothingMenu, WearOutfit, ReloadSkinappearance.apply, read, openMenu, wearOutfit, reloadSkinaiLib.appearance.* (same names)Appearance
IsDeadmedical.isDead, medical.onChangenone (call the export)Medical
GetSeatbelt, GetSeatbeltProviderseatbelt.isOn, seatbelt.provider, seatbelt.onChangeaiLib.seatbelt.* (same names)Seat belt
OpenMdtmdt.openaiLib.mdt.openMDT
ExternalNotifynone (used by ai-lib)noneNotifications

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).

On this page