cw.command class
Defines the cw.command library, the registry of chat commands, and the cwCmd console command that runs them.
A command is created with cw.command:New and registered with its aliases; its CMD_ flags name the states (dead,
ragdolled, in a vehicle and so on) in which it is refused. On the server cw.command:ConsoleCommand checks
cooldown, access and arguments before calling COMMAND:OnRun, and on the client each command is listed on the
Commands page of the directory.
Summary
Methods
cwCmd console command.Methods
cw.command:AddHelp(commandTable)
client gamemodes/catwork/gamemode/core/libraries/sh_command.lua:327Adds a command's syntax and tip to the Commands page of the directory.
Does nothing once the client has finished booting (so Lua refreshes add nothing) or when the command already has a help entry. The syntax and tip are translated when the page is shown.
Parameters
- commandTable Command The command to add
cw.command:ConsoleCommand(player, command, arguments)
server gamemodes/catwork/gamemode/core/libraries/sh_command.lua:198Runs a command for a player, as typed through the cwCmd console command.
Checks, in order: the player has initialized, the command exists, the command's cooldown
(skipped for admins), the PlayerCanUseCommand hook, the argument count, the player's access
flags, faction or permission, and the command's CMD_* state flags. Then calls
COMMAND:OnRun in protected mode, prints errors to the console, and on success logs the use
and runs the PostCommandUsed hook. The player is notified when a check fails. Does nothing
when run from the server console.
Parameters
- player Player The player running the command
- command String Name of the console command, unused
- arguments List<String> The command name followed by its arguments; the name is removed from the list
Returns
- Any The value returned by
OnRun, orfalsewhile the command is on cooldown
cw.command:FindByAlias(identifier)
shared gamemodes/catwork/gamemode/core/libraries/sh_command.lua:170Finds a command by its name or one of its aliases.
Parameters
- identifier String Command name or alias; case and whitespace are ignored
Returns
- Command The command, or
nilif none matches
See also
Finds a command by its name, ignoring aliases.
Parameters
- identifier String Command name; case and whitespace are ignored
Returns
- Command The command, or
nilif none matches
See also
Returns the alias lookup table.
Every command's own unique ID is included as an alias of itself.
Returns
- Map<String> Command unique IDs keyed by lowercased alias
Returns every registered, visible command keyed by unique ID.
Returns
- Map<Command> Commands keyed by their lowercased, space-less name
Creates a new, unregistered command object.
Set its fields and call CLASS_TABLE:Register on it. text is the syntax, tip the
description, flags a combination of CMD_* flags that block the command in some states,
access the flags a player needs, arguments the minimum argument count, and alias,
cooldown and faction are optional. COMMAND:OnRun(player, arguments) runs the command.
local COMMAND = cw.command:New('SetCash')
COMMAND.tip = '#Command_Setcash_Description'
COMMAND.text = '#Command_Setcash_Syntax'
COMMAND.flags = CMD_DEFAULT
COMMAND.access = 's'
COMMAND.arguments = 2
function COMMAND:OnRun(player, arguments)
end
COMMAND:Register()
Parameters
- name String optional, defaults to
'Unknown'Name of the command, as typed after the command prefix
Returns
- Command The new command object
Registers a command and its aliases.
Fills in defaults: text becomes #Command_NoSyntax, flags 0, access 'b' and
arguments 0. The unique ID is the name lowercased with whitespace removed. On the client the
command's help entry is (re)created.
Parameters
- data Command The command object or table
- name String Command name
Returns
- Command The registered command table
cw.command:RemoveByID(identifier)
shared gamemodes/catwork/gamemode/core/libraries/sh_command.lua:78Removes a registered command.
Its aliases and help entry are left in place.
Parameters
- identifier String Command name; case and whitespace are ignored
cw.command:RemoveHelp(commandTable)
client gamemodes/catwork/gamemode/core/libraries/sh_command.lua:356Removes a command's entry from the Commands page of the directory.
Parameters
- commandTable Command The command to remove
cw.command:SetHidden(name, bHidden)
shared gamemodes/catwork/gamemode/core/libraries/sh_command.lua:90Hides a command from the command list, or shows a hidden one again.
Hidden commands are moved out of the stored commands, so they cannot be found or run. On the server the change is sent to every client; on the client the command's help entry is removed or added.
Parameters
- name String Command name; case and whitespace are ignored
- bHidden Boolean Whether the command should be hidden