Skip to content

Commands

Comprehensive command registration, parsing, and execution system for the Lilia framework.


Overview

The commands library provides comprehensive functionality for managing and executing commands in the Lilia framework. It handles command registration, argument parsing, access control, privilege management, and command execution across both server and client sides. The library supports complex argument types including players, booleans, strings, and tables, with automatic syntax generation and validation. It integrates with the administrator system for privilege-based access control and provides user interface elements for command discovery and argument prompting. The library ensures secure command execution with proper permission checks and logging capabilities.

lia.command.buildSyntaxFromArguments(args)

Purpose

Generate a human-readable syntax string from a list of argument definitions.

When Called

During command registration to populate data.syntax for menus and help text.

Parameters

table args Array of argument tables {name=, type=, optional=}.

Returns

string Concatenated syntax tokens describing the command arguments.

Example Usage

  local syntax = lia.command.buildSyntaxFromArguments({
      {name = "target", type = "player"},
      {name = "amount", type = "number", optional = true}
  })
  -- "[player target] [string amount optional]"

lia.command.add(command, data)

Purpose

Register a command and normalize its metadata, syntax, privileges, aliases, and callbacks.

When Called

During schema or module initialization to expose new chat/console commands.

Parameters

string command Unique command key.

table data Command definition (arguments, desc, privilege, superAdminOnly, adminOnly, alias, onRun, onCheckAccess, etc.).

Example Usage

  lia.command.add("bring", {
      desc = "Bring a player to you.",
      adminOnly = true,
      arguments = {
          {name = "target", type = "player"}
      },
      onRun = function(client, args)
          local target = lia.command.findPlayer(args[1])
          if IsValid(target) then target:SetPos(client:GetPos() + client:GetForward() * 50) end
      end
  })

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

Purpose

Determine whether a client may run a command based on privileges, hooks, faction/class access, and custom checks.

When Called

Before executing a command or showing it in help menus.

Parameters

Player client Player requesting access.

string command Command name to check.

table data optional Command definition; looked up from lia.command.list when nil.

Returns

boolean, string allowed result and privilege name for UI/feedback.

Example Usage

  local canUse, priv = lia.command.hasAccess(ply, "bring")
  if not canUse then ply:notifyErrorLocalized("noPerm") end

lia.command.extractArgs(text)

Purpose

Split a raw command string into arguments while preserving quoted segments.

When Called

When parsing chat-entered commands before validation or prompting.

Parameters

string text Raw command text excluding the leading slash.

Returns

table Array of parsed arguments.

Example Usage

  local args = lia.command.extractArgs("'John Doe' 250")
  -- {"John Doe", "250"}

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

Purpose

Execute a registered command for a given client with arguments and emit post-run hooks.

When Called

After parsing chat input or console invocation server-side.

Parameters

Player client optional Player that issued the command (nil when run from server console).

string command Command key to execute.

table arguments optional Parsed command arguments.

Example Usage

  lia.command.run(ply, "bring", {targetSteamID})

lia.command.parse(client, text, realCommand, arguments, Pre, Pre)

Purpose

Parse chat text into a command invocation, prompt for missing args, and dispatch authorized commands.

When Called

On the server when a player sends chat starting with '/' or when manually dispatching a command.

Parameters

Player client Player whose chat is being parsed.

string text Full chat text.

string realCommand optional Command key when bypassing parsing (used by net/message dispatch).

table arguments optional Pre-parsed arguments; when nil they are derived from text.

unknown Pre parsed arguments; when nil they are derived from text.

unknown Pre parsed arguments; when nil they are derived from text.

Returns

boolean true if the text was handled as a command.

Example Usage

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

lia.command.openArgumentPrompt(cmdKey, missing, prefix)

Purpose

Display a clientside UI prompt for missing command arguments and send the completed command back through chat.

When Called

After the server requests argument completion via the liaCmdArgPrompt net message.

Parameters

string cmdKey Command key being completed.

table missing Names of missing arguments.

table prefix optional Prefilled argument values.

Example Usage

  lia.command.openArgumentPrompt("pm", {"target", "message"}, {"steamid"})

lia.command.send(command)

Purpose

Send a command invocation to the server via net as a clientside helper.

When Called

From UI elements or client logic instead of issuing chat/console commands directly.

Parameters

string command Command key to invoke.

Example Usage

  lia.command.send("respawn", LocalPlayer():SteamID())