Skip to content

Commands

Shiva provides a commands system via the ICommands contract. Commands are registered with typed arguments, permission levels, and help text.

Registering a Command

lua
local commands = container:make('ICommands')

commands:register('fish', {
    description = 'Start fishing at your current location',
    permission  = 'user',      -- 'user' | 'mod' | 'admin' | 'superadmin'
    params      = {},
    handler     = function(source, args)
        -- handle the command
    end,
})

Commands with Arguments

lua
commands:register('givemoney', {
    description = 'Give a player money',
    permission  = 'admin',
    params      = {
        { name = 'target',  type = 'number', help = 'Player server ID' },
        { name = 'account', type = 'string', help = 'Account name (cash/bank)' },
        { name = 'amount',  type = 'number', help = 'Amount to give' },
    },
    handler = function(source, args)
        local economy = container:make('IEconomy')
        economy:addMoney(args.target, args.account, args.amount)
    end,
})

Permission Levels

LevelWho Has It
userAll players
modModerators
adminAdmins
superadminServer owners

Assign permissions in shiva.config.lua or via the admin panel.

Chat Suggestions

Commands registered through ICommands automatically appear as chat suggestions in the FiveM chat tab-completion.

Using Raw FiveM Commands

Prefer ICommands over RegisterCommand directly — it adds permission checking, logging, and appears in shiva help.

If you must use raw RegisterCommand, still check permissions:

lua
RegisterCommand('mycommand', function(source, args)
    local player = container:make('IPlayer')
    if not player:hasPermission(source, 'admin') then
        return
    end
    -- ...
end, true)  -- restricted = true

See Also

Released under the MIT License.