AI Core

Radial menu

Add, remove and refresh items on whichever radial menu the server runs, with conditions, sub menus and press handlers.

The radial menu is the wheel players open with a key to pick quick actions (vehicle doors, emotes, job actions). Scripts add their items to ai-core, and ai-core hands them to the radial menu the server runs: ai-radialmenu, or a supported third-party one (tgiann-radialmenu, qb-radialmenu, codem-supreme-radialmenu, ox_lib's radial).

ai-core keeps every item. When the radial menu restarts, or the server owner switches to another one, ai-core adds every item again by itself, so your script adds its items once at start and never has to watch the radial resource. Items are removed when the resource that added them stops.

AddRadialItem

Adds an item to the radial menu, or replaces the item with the same id. The item's functions (canShow, onPressed) run inside your resource.

Side: Client · Waits: no

Signature
AddRadialItem(item: RadialItem): void
Lua
exports['ai-core']:AddRadialItem(item) -- or aiLib.radial.add(item)

Parameters

Prop

Type

RadialItem

See also RadialItem.

Prop

Type

Returns

Nothing. An item without a text id or label is not added, and ai-core prints a warning naming your resource.

Example

resource/client/radial.ts
import { cache, radial } from "@aicore-fivem/lib/client";
import { RADIAL_VEHICLE } from "@aicore-fivem/shared";
import { Locale } from "common";

// Once at start: an engine switch in the vehicle sub menu, only for the driver.
radial.add({
  id: "myscript_engine",
  label: Locale("RADIAL_ENGINE"),
  icon: "power-off",
  parent: RADIAL_VEHICLE,
  canShow: () => cache.vehicle !== false && cache.seat === -1,
  onPressed: () => {
    if (cache.vehicle === false) return;
    SetVehicleEngineOn(cache.vehicle, !GetIsVehicleEngineRunning(cache.vehicle), false, true);
  },
});

canShow runs every time the wheel opens: keep it cheap (read cache, a local variable or HasItem), never call the server from it. Do not add the same items again when the radial menu restarts; ai-core already does that.

RemoveRadialItem

Removes an item by its id.

Side: Client · Waits: no

Signature
RemoveRadialItem(id: string): void
Lua
exports['ai-core']:RemoveRadialItem(id) -- or aiLib.radial.remove(id)

Parameters

Prop

Type

Returns

Nothing.

Example

resource/client/duty.ts
import { onPlayerData, radial } from "@aicore-fivem/lib/client";
import { Locale } from "common";

// A cuff action only while on duty as police.
onPlayerData("duty", (duty) => {
  if (duty === "police")
    radial.add({ id: "myscript_cuff", label: Locale("RADIAL_CUFF"), icon: "handcuffs", onPressed: () => ExecuteCommand("cuff") });
  else radial.remove("myscript_cuff");
});

The id is not checked against the resource that added it: removing "myscript_cuff" removes it whoever added it. Use ids that start with your resource name. For an item that comes and goes often, a canShow is simpler than adding and removing.

RefreshRadial

Reads every canShow of an open wheel again, so items appear or disappear while the player looks at it. Call it after something a canShow reads has changed (the player got in a vehicle, went on duty).

Side: Client · Waits: no

Signature
RefreshRadial(): void
Lua
exports['ai-core']:RefreshRadial() -- or aiLib.radial.refresh()

Parameters

None.

Returns

Nothing. Without a running radial menu it does nothing.

Example

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

// Vehicle items depend on the seat: refresh when it changes.
onCache("seat", () => radial.refresh());

On this page