Skip to main content

Dynamic API

Runtime API for adding and removing menu items from other resources

This section

Dynamic API

Other resources can add or remove menu items at runtime using exports or events. Changes take effect immediately if the menu is currently open.

Exports

AddMenuItem

lua
exports["code9_radialMenu"]:AddMenuItem(id, itemData, parentId)
ParameterTypeRequiredDescription
idstringYesUnique identifier for this item
itemDatatableYesItem data (label, icon, event/command/action, etc.)
parentIdstringNoParent item ID for sub-items (nil = root level)

RemoveMenuItem

lua
exports["code9_radialMenu"]:RemoveMenuItem(id)
ParameterTypeRequiredDescription
idstringYesID of the item to remove

GetDynamicItems

lua
local items = exports["code9_radialMenu"]:GetDynamicItems()

Returns the full table of dynamically added items.

Events

The same operations are available via events:

lua
-- Add an item
TriggerEvent("code9_radialMenu:addMenuItem", id, itemData, parentId)

-- Remove an item
TriggerEvent("code9_radialMenu:removeMenuItem", id)

Usage Example

lua
-- Add a heal button from another resource
exports["code9_radialMenu"]:AddMenuItem("myResource_heal", {
label = "Heal",
icon = "heart-outline",
event = "myResource:heal",
shouldClose = true,
})

-- Remove it when no longer needed
exports["code9_radialMenu"]:RemoveMenuItem("myResource_heal")