AI Core

Items

Open the player's inventory, check an item, read the weapon in hand, and open the admin item picker, whatever inventory the server runs.

These exports go through ai-core's inventory layer: the inventory the server owner picked (ai-inventory, or a supported third-party inventory) answers them. Your script never calls a specific inventory's exports, so it keeps working when the inventory changes. While no inventory runs, the checks answer false / null and opening does nothing.

The client only reads and opens. Giving and taking items always happens on the server (lib inventory on the server, or ai-core's server exports), where the server checks the player first.

OpenInventory

Opens the player's own inventory screen in the active inventory (with whatever that inventory shows around it: the ground, a trunk, a glovebox).

Side: Client · Waits: no

Signature
OpenInventory(): void
Lua
exports['ai-core']:OpenInventory() -- or aiLib.inventory.openInventory()

Parameters

None.

Returns

Nothing. Without an active inventory nothing opens.

Example

resource/client/index.ts
import { inventory } from "@aicore-fivem/lib/client";

RegisterCommand("bag", () => inventory.openInventory(), false);

HasItem

Tells whether the player holds at least a number of an item. Use it to show or hide an option (a radial item, a target option) before you ask the server to do something.

Side: Client · Waits: no

Signature
HasItem(item: string, count?: number): boolean
Lua
local has = exports['ai-core']:HasItem(item, count) -- or aiLib.inventory.hasItem(item, count)

Parameters

Prop

Type

Returns

boolean: true when the player holds at least count. false when they hold fewer, when item is not a string, or when no inventory runs.

Example

resource/client/index.ts
import { inventory, notify, triggerServerCallback } from "@aicore-fivem/lib/client";
import { Locale } from "common";

RegisterCommand(
  "picklock",
  async () => {
    // A quick check for the player; the server checks the item again before it does anything.
    if (!inventory.hasItem("lockpick")) return notify(Locale("NEED_LOCKPICK"), "error");
    await triggerServerCallback("myscript:picklock", []);
  },
  false,
);

A client answer can be faked by a cheater. Use HasItem for what the player sees; the server must check and remove the item itself.

GetCurrentWeapon

Returns the weapon item the player holds in their hand, with its label and picture, through the active inventory.

Side: Client · Waits: no

Signature
GetCurrentWeapon(): HeldWeapon | null
Lua
local weapon = exports['ai-core']:GetCurrentWeapon() -- { name, label, image? } or nil

Parameters

None.

Returns

HeldWeapon while a weapon item is in hand, null when the hands are empty or no inventory runs.

Prop

Type

Example

resource/client/weapon.ts
import { inventory, onCache } from "@aicore-fivem/lib/client";

// Read it when the weapon in hand changes, not every frame.
onCache("weapon", () => {
  const weapon = inventory.currentWeapon();
  SendNUIMessage({ action: "weapon", data: weapon });
});

OpenItemPicker

Opens ai-core's item picker: a searchable grid of every item in the active inventory with pictures, where the player builds a list of items and counts. It is meant for admin tools (giving items to a player): the item list comes from the server, which sends it to admins only. The list the player takes arrives later as the client event ai-lib:client:menuResult.

Side: Client · Waits: no (the answer arrives as an event; the lib's itemPicker waits for you)

Signature
OpenItemPicker(requestId: number, request: ItemPickerRequest): void
Lua
local list = aiLib.itemPicker({ title = 'Give items', target = 12 }) -- waits; call inside a thread

Parameters

Prop

Type

ItemPickerRequest

See also ItemPickerRequest.

Prop

Type

Returns

Nothing right away. Later ai-core fires ai-lib:client:menuResult with (resource, requestId, value): value is a PickedItem[] list ({ name, count }) when the player took it, null when they closed the picker. The lib's itemPicker(request) returns Promise<PickedItem[] | null> with that value, and aiLib.itemPicker(request) returns the list or nil.

Example

resource/client/admin.ts
import { itemPicker, triggerServerCallback } from "@aicore-fivem/lib/client";
import { Locale } from "common";

// Admin tool: pick items for a player, the server checks the admin and gives every item.
export async function giveItemsTo(target: number): Promise<void> {
  const list = await itemPicker({ title: Locale("GIVE_ITEMS"), target });
  if (!list || list.length === 0) return;
  await triggerServerCallback("myadmin:giveItems", [target, list]);
}

The picker only shows items to admins (ai.admin): for anyone else the grid is empty. The server answers at most two openings per player in 2 seconds; a target who is not online counts as the picking admin. The player's answer is client data: your server must check that the caller is an admin and check every item and count before giving anything.

On this page