Commands | |
Variables | |
cmds. | This is used when specifying an argument to flag the argument as optional. |
cmds. | This is used when specifying a string argument to flag that only what was specified for autocomplete is allowed to be passed as a valid argument. |
cmds. | This is used when specifying a string argument to flag that this argument should use up any remaining args, whether quoted as one arg or not. |
cmds. | This is used when specifying a number argument to flag the argument to round the number to the nearest integer. |
cmds. | This is used when specifying a command that should ignore the can_target property in the groups config. |
cmds. | This is used when specyfing a number argument that should allow time string representations to be parsed (eg, ‘1w1d’ for 1 week 1 day). |
cmds. | Just defines the basics for us, used in autocomplete and command callbacks. |
Functions | |
cmds. | Used to, you guessed it, parse and validate an argument specified by a user. |
cmds. | Used to autocomplete a command. |
cmds. | Prints a basic usage message for this parameter. |
cmds. | A number arg, inherits from cmds.BaseArg. |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
cmds. | A boolean arg, inherits from cmds.BaseArg. |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
cmds. | A player arg, inherits from cmds.BaseArg. |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
cmds. | A table of players arg, inherits from cmds.PlayerArg. |
Functions | |
cmds. | See <cmds.PlayerArg:parseAndValidate> |
cmds. | See <cmds.PlayerArg:usage> |
cmds. | Simply used to retrieve the player using the command. |
Functions | |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | A player arg, inherits from cmds.BaseArg. |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
Tables | |
cmds. | Holds all the commands that are set up through the translator. |
cmds. | Offers an abstraction on the “console command” concept. |
Functions | |
cmds. | |
cmds. | Add an argument to this command. |
cmds. | Set the command opposite for this command. |
cmds. | |
cmds. | This is just a pass-through function for calling the function callback. |
cmds. | |
cmds. | Transforms a command and argument list as passed by the source engine into a ULib command table. |
cmds. | Given a ULib command table and the information to pass to the command callback, execute the command. |
cmds. | You must run this function on BOTH client AND server. This function is very similar to garry’s concommand.Add() function with a few key differences. |
cmds. | Exactly like cmds.addCommand, except it will expect the callback to be run on the local client instead of the server. |
cmds.takeRestOfLine
This is used when specifying a string argument to flag that this argument should use up any remaining args, whether quoted as one arg or not. This is useful for things like specifying a ban reason where you don’t want to force users to write an entire sentence within quotes.
Just defines the basics for us, used in autocomplete and command callbacks. These default implementations just throw an error if called. You shouldn’t need any great knowledge about the functions in these types, just that they exist and how to pass in restrictions.
2.40 | Initial |
Functions | |
cmds. | Used to, you guessed it, parse and validate an argument specified by a user. |
cmds. | Used to autocomplete a command. |
cmds. | Prints a basic usage message for this parameter. |
function cmds.BaseArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
Used to, you guessed it, parse and validate an argument specified by a user. Takes user command line input and converts it to a regular lua variable of the correct type.
ply | The player using the command. Useful for querying. |
arg | The arg to parse. It’s already properly trimmed. |
cmdInfo | A table containing data about this command. |
plyRestrictions | The restrictions from the access tag for this player. |
The parsed arg correctly typed if it validated, false and an explanation otherwise.
function cmds.BaseArg:complete( arg, cmdInfo, plyRestrictions )
Used to autocomplete a command. Passes back the options the player has in using this command.
arg | The arg to parse. It’s already properly trimmed. |
cmdInfo | A table containing data about this command. |
plyRestrictions | The restrictions from the access tag for this player. |
A table of strings containing the options that are available.
function cmds.BaseArg:usage( cmdInfo, plyRestrictions )
Prints a basic usage message for this parameter.
cmdInfo | A table containing data about this command. |
plyRestrictions | The restrictions from the access tag for this player. |
A string describing what this parameter is and how to use it.
A number arg, inherits from cmds.BaseArg. Restrictions can include a numeric value for keys ‘min’, ‘max’, and ‘default’. All do what you think they do. If the argument is optional and no default is specified, 0 is used for default. You can specify the allowTimeString key to allow time string representations. Lastly, you can specify a value for the key ‘hint’ for a hint on what this argument is for, IE “damage”.
The following code creates a command that accepts an optional numeric second argument that defaults to 0 and has to be at least 0.
cmd = ULib.cmds.TranslateCommand( "ugm slap", ULib.slap ) cmd:addParam{ type=ULib.cmds.PlayerArg, target="*", default="^", ULib.cmds.optional } cmd:addParam{ type=ULib.cmds.NumArg, min=0, default=0, ULib.cmds.optional }
2.40 | Initial |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
A boolean arg, inherits from cmds.BaseArg. You can specify a value for the key ‘hint’ for a hint on what this argument is for, IE “revoke access”.
The following code creates a command that accepts an option boolean third argument that defaults to false.
local groupallow = ULib.cmds.TranslateCommand( "ulx groupallow", ulx.groupallow ) groupallow:addParam{ type=ULib.cmds.StringArg } groupallow:addParam{ type=ULib.cmds.StringArg } groupallow:addParam{ type=ULib.cmds.BoolArg, hint="revoke access", ULib.cmds.optional }
2.40 | Initial |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
A player arg, inherits from cmds.BaseArg. Can be restricted by specifying a string in the key ‘target’. This string is passed to getUser() with keywords enabled to get a list of players this user is allowed to target.
The following code creates a command that accepts an optional player argument that defaults to self and cannot be any superadmins.
cmd = ULib.cmds.TranslateCommand( "ugm slap", ULib.slap ) cmd:addParam{ type=ULib.cmds.PlayerArg, target="!%superadmin", default="^", ULib.cmds.optional } cmd:addParam{ type=ULib.cmds.NumArg, min=0, default=0, ULib.cmds.optional }
2.40 | Initial |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
A table of players arg, inherits from cmds.PlayerArg. Can be restricted by specifying a string in the key ‘target’. This string is passed to getUsers() with keywords enabled to get a list of players this user is allowed to target.
2.40 | Initial |
Functions | |
cmds. | See <cmds.PlayerArg:parseAndValidate> |
cmds. | See <cmds.PlayerArg:usage> |
Simply used to retrieve the player using the command. No validation needed.
2.40 | Initial |
Functions | |
cmds. | See <cmds.BaseArg:parseAndValidate> |
A player arg, inherits from cmds.BaseArg. You can specify completes with a table of strings for the key ‘completes’. Can be restricted to these by specifying ULib.cmds.restrictToCompletes. Can also specify ULib.cmds.takeRestOfLine to make it take up the rest of the command line arguments. ‘autocomplete_fn’ can be specified with the value of a function to call for autocompletes (this is an override). Can specify a value for the key ‘repeat_min’ when the argument repeats at least n times (this implies ULib.cmds.takeRestOfLine). Though it’s not (currently) used by ULib, you can also specify ‘repeat_max’ to mean that the argument repeats at most n times. Lastly, you can specify a value for the key ‘hint’ for a hint on what this argument is for, IE “groupname”.
The following code creates a command that accepts a first argument that is restricted to a list of strings, this same list is also used for autocompletes. A descriptive error is provided if they specify an invalid group.
local groupallow = ULib.cmds.TranslateCommand( "ulx groupallow", ulx.groupallow ) groupallow:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
2.40 | Initial |
Functions | |
cmds. | A helper function to help us figure out restrictions on this command. |
cmds. | See <cmds.BaseArg:parseAndValidate> |
cmds. | See <cmds.BaseArg:complete> |
cmds. | See <cmds.BaseArg:usage> |
Tables | |
cmds. | Holds all the commands that are set up through the translator. |
Offers an abstraction on the “console command” concept. Think of this class as a translator sitting between the user and your program. You tell this translator what arguments and types you’re expecting from the user and the translator handles the rest.
If the user tries to use a command with the incorrect number or wrong type of args, the translator informs the user of the problem and suggests how to fix it. If the user has everything correct, the translator calls the callback with the correctly typed and validated arguments.
v2.40 | Initial |
Functions | |
cmds. | |
cmds. | Add an argument to this command. |
cmds. | Set the command opposite for this command. |
cmds. | |
cmds. | This is just a pass-through function for calling the function callback. |
cmds. | |
cmds. | Transforms a command and argument list as passed by the source engine into a ULib command table. |
cmds. | Given a ULib command table and the information to pass to the command callback, execute the command. |
cmds. | You must run this function on BOTH client AND server. This function is very similar to garry’s concommand.Add() function with a few key differences. |
cmds. | Exactly like cmds.addCommand, except it will expect the callback to be run on the local client instead of the server. |
function cmds.TranslateCommand:instantiate( cmd, fn, say_cmd, hide_say, no_space_in_say, unsafe )
cmd | The command you’re creating. IE, “ulx slap”. |
fn | (Optional on client since it’s ignored) The function callback for this command. The callback receives the arguments you specify. |
say_cmd | (Optional) Specify a say command or commands (as a table) to be tied in. |
hide_say | (Optional, defaults to false) Hide the chat when the say command is used? |
no_space_in_say | (Optional, defaults to false) Is a space between the chat command and arguments required? |
unsafe | (Optional, defaults to false) Flag for ULib.execString, which disallows execution from untrusted config. |
function cmds.TranslateCommand:setOpposite( cmd, args, say_cmd, hide_say, no_space_in_say )
Set the command opposite for this command. IE, if the main command is “jail”, the opposite might be “unjail”. The same callback is called for both “jail” and “unjail”. The parameters passed to this function specify required values for arguments passed to the callback. Any nil values still allow any valid values from the user. Automatically sets default access to be the same as the “non-opposite” command.
cmd | The name of the command for this opposite. IE, “unjail”. |
args | The args to restrict or allow, in order. |
say_cmd | (Optional) Specify a say command to be tied in. |
hide_say | (Optional, defaults to false) Hide the chat when the say command is used? |
no_space_in_say | (Optional, defaults to false) Is a space between the chat command and arguments required? |
This sets the opposite to “unjail”, where the first parameter can still be any valid value, but the second value must be 0.
myCmd:setOpposite( "unjail", { _, 0 }, "!unjail" )
function cmds.TranslateCommand:call( isOpposite, ... )
This is just a pass-through function for calling the function callback. If you want to modify the behavior of TranslateCommand on the callback, this is the place to do it. For example, ULX overrides this to add logging info.
isOpposite | Is this the opposite command that’s being called? |
... | The args that will be passed to the function callback. |
function cmds.getCommandTableAndArgv( commandName, argv, valveErrorCorrection )
Transforms a command and argument list as passed by the source engine into a ULib command table.
commandName | The string top-level command. IE, “ulx”. |
argv | The argument list, as a list of strings. |
valveErrorCorrection | An optional boolean of whether to correct for source engine command line mangling. |
1 | The command table, as contained in ULib.cmds.routedCmds. If none found, returns nil. |
2 | The final computed command name |
3 | The argv table, stripped of ULX command portions. |
v2.62 | Initial |
function cmds.execute( cmdTable, ply, commandName, argv )
Given a ULib command table and the information to pass to the command callback, execute the command. Also routes server commands appropriately and executes ULib command hooks.
cmdTable | The command table, internal to ULib. |
ply | The player calling the command. |
commandName | The string of the command name. |
argv | The argument list, as a list of strings. |
v2.62 | Initial |
function cmds.addCommand( cmd, fn, autocomplete, access_string, say_cmd, hide_say, no_space_in_say, unsafe )
You must run this function on BOTH client AND server. This function is very similar to garry’s concommand.Add() function with a few key differences.
First, this function supports commands with spaces in the name. IE, “ulx slap” is handled just like you’d think it ought to be.
Second, autocompletes for spaced commands work similar to how the default autocomplete in console works. IE, if you type “ulx sl” into the console, you’ll see all commands starting with that (“ulx slap”, “ulx slay”).
Third, it will automatically tie in chat commands.
cmd | The command you’re creating. IE, “ulx slap”. |
fn | (Optional on clients since it’s ignored) The function callback for this command. The callback receives the same parameters as a callback from concommand.Add() does. This parameter is ignored on clients. |
autocomplete | (Optional) The callback for autocompletes. If left nil, ULib tries to intelligently figure out what commands there are to complete. This parameter is ignored on servers if it’s not singleplayer or a listen server. |
access_string | (Optional) Access required for use this command. It’s only used for autocomplete purposes and is NOT validated at the server. |
say_cmd | (Optional) Specify a say command or say commands as a table to be tied in. |
hide_say | (Optional, defaults to false) Hide the chat when the say command is used? |
no_space_in_say | (Optional, defaults to false) Is a space between the chat command and arguments required? |
unsafe | Flag the command as unsafe to execute for execStringULib. |
The code below creates a bunch of different commands under the first “myTest” command. If you type in “myTest “ at console, you see all the available commands for the next step in autocompletes. Note that it’s case-insensitive, but otherwise works exactly like you would expect.
cmds.addCommand( "myTest", print ) cmds.addCommand( "myTest hi", print ) cmds.addCommand( "myTest hi2", print ) cmds.addCommand( "myTest hi2 doOty", print, print ) cmds.addCommand( "myTest hi2 doot", print, print ) cmds.addCommand( "myTest hi2 color", print, function() return { "red", "green", "blue" } end ) cmds.addCommand( "myTest rEd", print, print ) cmds.addCommand( "myTest blue", print, print ) cmds.addCommand( "myTest bluegreen", print, print ) cmds.addCommand( "myTest green", print, print )
v2.63 | Added unsafe flag |
v2.40 | Initial |
This is used when specifying an argument to flag the argument as optional.
cmds.optional
This is used when specifying a string argument to flag that only what was specified for autocomplete is allowed to be passed as a valid argument.
cmds.restrictToCompletes
This is used when specifying a string argument to flag that this argument should use up any remaining args, whether quoted as one arg or not.
cmds.takeRestOfLine
This is used when specifying a number argument to flag the argument to round the number to the nearest integer.
cmds.round
This is used when specifying a command that should ignore the can_target property in the groups config.
cmds.ignoreCanTarget
This is used when specyfing a number argument that should allow time string representations to be parsed (eg, ‘1w1d’ for 1 week 1 day).
cmds.allowTimeString
Used to, you guessed it, parse and validate an argument specified by a user.
function cmds.BaseArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
Used to autocomplete a command.
function cmds.BaseArg:complete( arg, cmdInfo, plyRestrictions )
Prints a basic usage message for this parameter.
function cmds.BaseArg:usage( cmdInfo, plyRestrictions )
A helper function to help us figure out restrictions on this command.
function cmds.NumArg:processRestrictions( cmdRestrictions, plyRestrictions )
See cmds.BaseArg:parseAndValidate
function cmds.NumArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:complete
function cmds.NumArg:complete( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:usage
function cmds.NumArg:usage( cmdInfo, plyRestrictions )
A helper function to help us figure out restrictions on this command.
function cmds.BoolArg:processRestrictions( cmdRestrictions, plyRestrictions )
See cmds.BaseArg:parseAndValidate
function cmds.BoolArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:complete
function cmds.BoolArg:complete( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:usage
function cmds.BoolArg:usage( cmdInfo, plyRestrictions )
A helper function to help us figure out restrictions on this command.
function cmds.PlayerArg:processRestrictions( ply, cmdRestrictions, plyRestrictions )
See cmds.BaseArg:parseAndValidate
function cmds.PlayerArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:complete
function cmds.PlayerArg:complete( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:usage
function cmds.PlayerArg:usage( cmdInfo, plyRestrictions )
See cmds.PlayerArg:parseAndValidate
function cmds.PlayersArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
See cmds.PlayerArg:usage
function cmds.PlayersArg:usage( cmdInfo, plyRestrictions )
See cmds.BaseArg:parseAndValidate
function cmds.CallingPlayerArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
A helper function to help us figure out restrictions on this command.
function cmds.StringArg:processRestrictions( cmdRestrictions, plyRestrictions )
See cmds.BaseArg:parseAndValidate
function cmds.StringArg:parseAndValidate( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:complete
function cmds.StringArg:complete( ply, arg, cmdInfo, plyRestrictions )
See cmds.BaseArg:usage
function cmds.StringArg:usage( cmdInfo, plyRestrictions )
function cmds.TranslateCommand:instantiate( cmd, fn, say_cmd, hide_say, no_space_in_say, unsafe )
Add an argument to this command.
function cmds.TranslateCommand:addParam( t )
Set the command opposite for this command.
function cmds.TranslateCommand:setOpposite( cmd, args, say_cmd, hide_say, no_space_in_say )
function cmds.TranslateCommand:getUsage( ply )
This is just a pass-through function for calling the function callback.
function cmds.TranslateCommand:call( isOpposite, ... )
function cmds.TranslateCommand:defaultAccess( access )
Transforms a command and argument list as passed by the source engine into a ULib command table.
function cmds.getCommandTableAndArgv( commandName, argv, valveErrorCorrection )
Given a ULib command table and the information to pass to the command callback, execute the command.
function cmds.execute( cmdTable, ply, commandName, argv )
You must run this function on BOTH client AND server. This function is very similar to garry’s concommand.Add() function with a few key differences.
function cmds.addCommand( cmd, fn, autocomplete, access_string, say_cmd, hide_say, no_space_in_say, unsafe )
Exactly like cmds.addCommand, except it will expect the callback to be run on the local client instead of the server.
function cmds.addCommandClient( cmd, fn, autocomplete, unsafe )
Finds a user matching an identifier.
function ULib.getUser( target, enable_keywords, ply )
Finds users matching an identifier.
function ULib.getUsers( target, enable_keywords, ply )
Just like execString, except only for ULib-defined commands.
function ULib.execStringULib( f, safeMode )