Skip to content

Command

Command registration, parsing, permissions, argument prompts, and network dispatch helpers for Lilia commands.


Overview

The command library centralizes shared command registration under `lia.command`, normalizes command argument metadata, manages command aliases and privilege checks, parses chat commands on the server, opens clientside argument prompts for missing required arguments, and sends command payloads from the client to the server.

lia.command.buildSyntaxFromArguments(args)View Source

Purpose

Builds a display syntax string from a command argument definition list.

Realm

Shared

Parameters

table args Sequential command argument definitions. Each entry may define `name`, `type`, and `optional`.

Returns

string A space-separated syntax string in bracketed argument format.

Example Usage

  local syntax = lia.command.buildSyntaxFromArguments({
      {name = "target", type = "player"},
      {name = "reason", type = "string", optional = true}
  })

lia.command.add(command, data)View Source

Purpose

Registers a Lilia command, resolves localized command metadata, normalizes argument definitions, creates aliases, registers admin privileges when required, and wraps the command callback with access checks.

Realm

Shared

Parameters

string command The command name to register.

table data The command definition. Expected fields include `onRun`, and may include `arguments`, `syntax`, `desc`, `alias`, `adminOnly`, `superAdminOnly`, `privilege`, `privilegeName`, `AdminStick`, and `onCheckAccess`.

Example Usage

  lia.command.add("example", {
      desc = "@exampleDesc",
      arguments = {
          {name = "target", type = "player"}
      },
      onRun = function(client, arguments)
          client:notifyInfo("Example command ran.")
      end
  })

lia.command.hasAccess(client, command, data)View Source

Purpose

Checks whether a player can use a registered command.

Realm

Shared

Parameters

Player client The player whose access is being checked.

string command The command name being checked.

table data Optional command definition. When omitted, the command is looked up in `lia.command.list`.

Returns

boolean True when the player can use the command, otherwise false. string The display name of the privilege or access level used for the check.

Example Usage

  local canUse, privilege = lia.command.hasAccess(client, "plygetplaytime")
  if not canUse then
      client:notifyErrorLocalized("noPerm")
  end

lia.command.extractArgs(text)View Source

Purpose

Splits a raw command argument string into arguments while preserving quoted text as a single argument.

Realm

Shared

Parameters

string text The raw argument string to parse.

Returns

table Sequential command arguments extracted from the input string.

Example Usage

  local arguments = lia.command.extractArgs("target \"quoted reason\"")

lia.command.run(client, command, arguments)View Source

Purpose

Executes a registered command callback and handles localized string return values as player notifications.

Realm

Server

Parameters

Player client The player running the command.

string command The command name to execute.

table arguments Optional parsed arguments to pass to the command callback.

Example Usage

  lia.command.run(client, "playtime", {})

lia.command.parse(client, text, realCommand, arguments)View Source

Purpose

Parses chat command text, checks command access, prompts the player for missing required arguments when needed, and runs the command.

Realm

Server

Parameters

Player client The player whose input is being parsed.

string text The raw chat text or command text.

string realCommand Optional command name to run instead of parsing one from `text`.

table arguments Optional pre-parsed command arguments.

Returns

boolean True when the text was handled as a command, otherwise false.

Example Usage

  hook.Add("PlayerSay", "ParseLiliaCommands", function(client, text)
      if lia.command.parse(client, text) then return "" end
  end)

lia.command.openArgumentPrompt(cmdKey, missing, prefix, definitions)View Source

Purpose

Opens the clientside command argument prompt for missing required command arguments.

Realm

Client

Parameters

string cmdKey The command key being completed.

table missing Argument names that still need values.

table prefix Arguments already supplied before the prompt opened.

table definitions Optional argument definitions used when the command is not available locally.

Example Usage

  lia.command.openArgumentPrompt("example", {"target"}, {}, definitions)

lia.command.send(command)View Source

Purpose

Sends a command and its arguments from the client to the server over the Lilia command net message.

Realm

Client

Parameters

string command The command name to send.

Example Usage

  lia.command.send("playtime")

Hooks

Library-specific hooks documented for this library.


CanPlayerUseCommand(client, command)View Source

Purpose

Allows plugins or modules to override whether a player can use a command after normal privilege checks are prepared.

Realm

Shared

Parameters

Player client The player whose command access is being checked.

string command The command name being checked.

Returns

boolean|nil Return true to allow the command, false to deny it, or nil to keep the normal access result.


CommandAdded(command, data)View Source

Purpose

Runs after a command has been registered with `lia.command.add`.

Realm

Shared

Parameters

string command The command name that was registered.

table data The command definition table stored in `lia.command.list`.


CommandRan(client, command, arguments, results)View Source

Purpose

Runs after a command callback has executed.

Realm

Server

Parameters

Player client The player who ran the command.

string command The command name that was executed.

table arguments The parsed command arguments passed to the command.

table results The return values from the command callback.