Skip to content

nut.command

Chat Command module.

Handles registration, parsing, and execution of chat and console commands.

Functions

nut.command.add (command, data)
nut.command.add

Adds a new command to the list of commands.

Parameters:

string command Command name

table data Command definition table

See also:

nut.command.extractArgs (text)
nut.command.extractArgs

Internal

This is used internally - although you're able to use it you probably shouldn't.

Gets a table of arguments from a string.

Parameters:

string text Input text to parse

Returns:

table Extracted arguments

nut.command.findFaction (client, name)
nut.command.findFaction

Finds a faction based on the uniqueID, and then the name if no such uniqueID exists.

Parameters:

Client client Command source

string name Faction name or ID

Returns:

table Faction data or nil

nut.command.run (client, command, arguments)
nut.command.run

Forces a player to run a command.

Parameters:

Client client Player running command

string command Command name

table arguments Command arguments

nut.command.parse (client, text, realCommand, arguments)
nut.command.parse

Add a function to parse a regular chat string.

Parameters:

Client client Player running command

string text Full command text

string realCommand optional Pre-extracted command name

table arguments optional Pre-extracted arguments

Returns:

bool Whether a command was executed

nut.command.send (command, ...)
nut.command.send

Sends a command from client to server

Parameters:

string command Command name

vararg ... Command arguments

Tables

CommandDef
CommandDef

Configuration table for command definitions

Fields:

vararg group String/table of allowed usergroups

vararg alias String/table of command aliases

string syntax Command usage syntax (e.g. " [amount]")

function onRun Function(client, args) - Command execution callback

function onCheckAccess Function(client) - Permission check

boolean adminOnly Boolean shortcut for admin-only commands

boolean superAdminOnly Boolean shortcut for superadmin-only commands

string realCommand Original command name if different from registered name

See also:

Usage:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    nut.command.add("givecash", {
        syntax = "<name> <amount>",
        adminOnly = true,
        onRun = function(client, args)
            local target = nut.command.findPlayer(client, args[1])
            local amount = tonumber(args[2])
            -- Command logic here
        end
    })