concommand.Add

From GMod Wiki

Jump to: navigation, search
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: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Concommand.Add]Concommand.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionWhen the player types "PrintSomething" in their console, the command "fPrintSomething" is called.
Used onNewerServer.png
Code
function fPrintSomething( player, command, arguments )
    MsgN( "Printing Something." )
end
 
concommand.Add( "PrintSomething", fPrintSomething )
OutputPrints "Printing Something" to the console of the server.


DescriptionThis will create a console command and give it autocomplete options.
Used onNewerClient.png
Code
 
--Create a console command that says whatever is given to it in the server console.
function myCommand(player,command,args)
    PrintTable(args) -- Print out all the arguments
end
 
--Put three options in the autocomplete list - Red, green, and blue.
function getAutoCompleteOptions(commandName,args)
    return {"red","green","blue"}
end
concommand.Add("myCC",myCommand,getAutoCompleteOptions)
 
--Now these options in getAutoCompleteOptions will show up while the user types
--myCC in the console.
 
OutputNone


DescriptionThis will allow you to see who typed the command and the --arguments they used.
Used onNewerServer.png
Code
 
--Create a console command that says 
--whatever is given to it in the server console.
function myCommand(player,command,args)
    Msg(player:GetName().." likes "..args[1].." \n") --Prints out the first word typed 
--after command [2] will be first 2 words.
end
 
--Add the concommand line
concommand.Add("myCommand",myCommand)
 
--Now you can make scripts like ulx did, but an easier way.
 
OutputPrints The player who typed to command and the arguments in the console


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox