lia.command
Registration, parsing, and handling of commands.
Commands can be ran through the chat with slash commands or they can be executed through the console. Commands can be manually restricted to certain usergroups using a CAMI-compliant admin mod.
If you are looking for the command structure, you can find it here.
Functions
extractArgs(text)
Returns a table of arguments from a given string. Words separated by spaces will be considered one argument. To have an argument containing multiple words, they must be contained within quotation marks.
Parameters
-
text
String
String to extract arguments from
Returns
-
table
Arguments extracted from string
Example Usage
PrintTable(lia.command.extractArgs("these are \"some arguments\""))
> 1 = these
> 2 = are
> 3 = some arguments
findFaction(client, name)
Attempts to find a faction by an identifier.
Parameters
-
client
Player
to give a notification to if the faction could not be found
-
name
String
Search query
Returns
-
table
Faction that matches the given search query
-
nil
If a faction could not be found
findPlayer(client, name)
Attempts to find a player by an identifier. If unsuccessful, a notice will be displayed to the specified player. The search criteria is derived from lia.command.findPlayer.
Parameters
-
client
Player The client to give a notification to if the player could not be found.
-
name
string Search query
Returns
-
player or nil
Player that matches the given search query, or nil if a player could not be found
See Also
findPlayerSilent(client, name)
Attempts to find a player by an identifier silently.
Parameters
-
client
Player
to give a notification to if the player could not be found
-
name
String
Search query
Returns
-
player or nil
Player that matches the given search query, or nil if not found
hasAccess(client, command, data)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Returns true if a player is allowed to run a certain command.
Parameters
-
client
Player
to check access for
-
command
String
Name of the command to check access for
-
data
Table
optional
command data, if not provided, it will be fetched from
lia.command.list
Returns
-
bool
Whether or not the player is allowed to run the command
parse(client, text, realCommand, arguments)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Parses a command from an input string and executes it.
Parameters
-
client
Player
The player who is executing the command
-
text
String
Input string to search for the command format
-
realCommand
String
optional
Specific command to check for. If specified, it will only try to run this command
-
arguments
Table
optional
Array of arguments to pass to the command. If not specified, it will try to extract them from the text
Returns
-
any
bool Whether or not a command has been found and executed
Example Usage
lia.command.parse(player.GetByID(1), "/roll 10")
run(client, command, arguments)
Forces a player to execute a command by name.
Parameters
-
client
Player
who is executing the command
-
command
String
Full name of the command to be executed. This string gets lowered, but it's good practice to stick with the exact name of the command
-
arguments
Table
Array of arguments to be passed to the command
Example Usage
lia.command.run(player.GetByID(1), "Roll", {10})
send(command, ...)
Request the server to run a command. This mimics similar functionality to the client typing /CommandName
in the chatbox.
Parameters
-
command
String
Unique ID of the command
-
...
Table
Arguments to pass to the command
Example Usage
lia.command.send("roll")
Tables
CommandStructure
When registering commands with lia.command.add
, you'll need to pass in a valid command structure. This is simply a table
with various fields defined to describe the functionality of the command.
Fields
-
onRun
function
This function is called when the command has passed all the checks and can execute. The arguments will be the calling player and subsequent argument list.
-
adminOnly
bool
default: false
Provides an additional check to see if the user is an admin before running.
-
superAdminOnly
bool
default: false
Provides an additional check to see if the user is a superadmin before running.
-
privilege
string
default: nil
Manually specify a privilege name for this command. It will always be prefixed with
"Commands - "
. This is used in the case that you want to group commands under the same privilege, or use a privilege that you've already defined (i.e grouping/charban
and/charunban
into theCommands - Ban Characters
privilege).
-
onCheckAccess
function
default: nil
This callback checks whether or not the player is allowed to run the command. This callback should NOT** be used in conjunction with
adminOnly
orsuperAdminOnly
, as populating those fields create a custom aOnCheckAccess
callback for you internally. This is used in cases where you want more fine-grained access control for your command. Consider this example command:lia.command.add("slap", { adminOnly = true, privilege = "Can Slap", onRun = function(client, arguments) -- WHAM! end })
Creates a new command.
-
command
String
Name of the command (recommended in UpperCamelCase)
-
data
Table
Data describing the command