Register Action
⚠️

If the action is registered server-side, it will be executed server-side, as well as the restricted function.

RegisterAction

Adds a new action to the menu.

Parameters

NameTypeDescriptionRequired
namestringName of the actionYes
funcfun(source: number, arguments: (number | string | nil)[], rawCommand?: string)Function to be executedYes
argumentTypes{ name: string; type: 'string' | 'playerId' | 'number'; required?: boolean; choices: { label: string, value: string | number }[] }[]The arguments of the actionNo
isCommandbooleanWhether a command should be created or notNo
restrictedboolean | fun(source: number): booleanDo not make the action available to everyone. If it is a function, the action will only be executed if the function returns a true valueNo

Example

-- TriggerEvent('cmdmenu:RegisterAction', ...) also works
local action = exports['monolith-cmdmenu']:RegisterAction('test', function(source, arguments, raw)
  local msg = ('%s says %s is the coolest player and prefers %s')
 
  print(msg:format(GetPlayerName(source), GetPlayerName(arguments[1]), arguments[2]))
end, {
  {
    name = 'Player',
    type = 'playerId',
    required = true
  },
  {
    name = 'Preference',
    type = 'string',
    required = true,
    choices = {
      {
        label = 'Pizza',
        value = 'Pizza'
      },
      {
        label = 'Burger',
        value = 'Burger'
      }
    }
  }
})