> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-radial-menu-v2/exports.md).

# Exports

The CAS Radial Menu export API, open, close and block the RedM wheel from your own resource, add slices at runtime, and listen for what the player picks.

All exports are **client side** and live under the resource name:

```lua
exports['cas-radialmenu']:Toggle()
```

These wrappers are the contract. The resource's own globals (`OpenMenu`, `BuildMenu`, `Walk`, and so on) are deliberately not, they can be renamed or split up in an update, and anything reaching into them would break.

## Opening and closing

| Export      | Returns   | What                                                                            |
| ----------- | --------- | ------------------------------------------------------------------------------- |
| `IsOpen()`  | `boolean` | Whether the wheel is up.                                                        |
| `Open()`    |           | Open it. Ignored if it is blocked, the player is dead, or the pause menu is up. |
| `Close()`   |           | Close it.                                                                       |
| `Toggle()`  |           | The same thing the key does.                                                    |
| `Refresh()` |           | Rebuild and re-push while it is open. No-op when shut.                          |

```lua
if not exports['cas-radialmenu']:IsOpen() then
    exports['cas-radialmenu']:Open()
end
```

## Blocking the wheel

The common one: your resource has its own focused NUI up, and the player pressing the radial key on top of it would put two focused pages on screen at once.

| Export                | Returns   | What                                                                                                              |
| --------------------- | --------- | ----------------------------------------------------------------------------------------------------------------- |
| `SetEnabled(enabled)` | `boolean` | `false` holds the wheel shut in **your** resource's name, and closes it if it is open. `true` releases your hold. |
| `IsEnabled()`         | `boolean` | `true` when nothing is holding it shut.                                                                           |

```lua
-- while your menu is up
exports['cas-radialmenu']:SetEnabled(false)

-- when you are done
exports['cas-radialmenu']:SetEnabled(true)
```

{% hint style="info" %}
Holds are **counted per resource**, not a shared boolean. Two resources can both be holding the wheel shut and neither one releasing clears the other's hold. If your resource stops while holding one, it is released for you.
{% endhint %}

## Adding slices at runtime

For items that only exist while something is happening. `config.lua` is still the place to author a permanent menu.

### `AddItem(parentId, item)`

`parentId` is the wheel to add to: a **tab id** (`'main'`), or the **id of an item that already opens a sub-wheel** (`'character'`). `item` takes exactly the same shape as a `Config.Menu` entry, see [Item fields](broken://pages/editing-the-menu#item-fields).

```lua
exports['cas-radialmenu']:AddItem('main', {
    id    = 'shop.buy',
    label = 'Buy Supplies',
    icon  = 'provisions',
    hint  = 'You are standing in the general store',
    event = 'my-shop:open',
})
```

Returns `true` if it was accepted. Adding the same `id` twice **replaces** it rather than duplicating, so a resource that re-registers on every spawn does not stack up slices.

### `RemoveItem(id)`

```lua
exports['cas-radialmenu']:RemoveItem('shop.buy')
```

Returns `true` if something was removed. Items are also removed automatically when the resource that added them stops.

{% hint style="warning" %}
Items are folded in when the wheel is built, which is on open. Add one while the wheel is already up and it appears after `Refresh()` or the next open. Favourites and History do not accept runtime items, Favorites is a fixed set of numbered slots that an appended item would push out of alignment.
{% endhint %}

## Notifications

### `Notify(text, tone)`

A line of text in the wheel's own toast. Only visible while the wheel is open. `tone` is `'info'` (default), `'good'` or `'bad'`.

```lua
exports['cas-radialmenu']:Notify('Nothing to sell here', 'bad')
```

## Events

Listen for what the player picked, without touching this resource:

```lua
AddEventHandler('cas-radialmenu:selected', function(item) print(item.id) end)
AddEventHandler('cas-radialmenu:emote',    function(id) end)
AddEventHandler('cas-radialmenu:clothing', function(id, on) end)
AddEventHandler('cas-radialmenu:weapon',   function(id) end)
AddEventHandler('cas-radialmenu:waypoint3d', function(on, at) end)  -- at = {x,y,z}
```

`cas-radialmenu:selected` fires for **every** selection, so it is the one to use if you only want a single handler.

## Checking it from the console

`casradial_api` prints what is holding the wheel shut and what has been added to it, the two things that are invisible from `config.lua` alone when another resource is misbehaving.
