concommand.Add
From GMod Wiki
Function | |
Syntax |
concommand.Add( String commandName, Function commandFunction [, Function :Table :String autoCompleteFunc , String HelpText ] ) Where is this used? |
Description: | |
Creates a console command that runs a function in lua with optional autocompletion function and help text. | |
Returns: | nil |
Part of Library: | concommand |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Concommand.Add]Concommand.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Examples
Additional Notes
- The command function syntax is nothing like GM9. Player is the player object calling the object (not the userid), command is the command used (in our example it would be 'PrintSomething'), and arguments is a table of arguments, not a string.
- autoCompleteFunc is called when the user is typing in the command. It should return a table containing a list of options (ie: a list of filenames).
- autoCompleteFunc has two arguments - commandName and args. Command name is the name of the command being typed, and args is a list of arguments that have been typed so far.
- autoCompleteFunc is optional and will only work on the client.
- If this function is used on clientside, then only that client can use the command.
- There are two characters you can add to the beginning of a concommand name for a special type of concommand. These are + and -. If you create a command called "+dostuff" and bind it to a key, when the key is pressed the function for "+dostuff" is called once. When the key is released, the function for "-dostuff" is called automatically. If you manually enter "+dostuff" into the console, "-dostuff" will never be called unless you also type it in manually. This is especially useful for hooks and VGUI.