concommand/Add

From Garry's Mod
Jump to: navigation, search
concommand.Add( )

Contents

Description

Creates a console command that runs a function in lua with optional autocompletion function and help text.

Arguments

string name

The command name to be used in console.

It may not contain any of the following (even as a substring) or the command will not be registered:

toggleconsole, exit, gameui_activate, connect, disconnect

Arguments

function commandFunc

The function to run when the concommand is executed.
Args: ( Player ply , string cmd , table args , string fullstring )

Arguments

function autoCompleteFunc=nil

The function to call which should return a table of options for autocompletion.

This only properly works on the client since it is not networked.
Autocompletion Tutorial

Args: ( string cmd , string args )

Arguments

string helpText=nil

The text to display should a user run 'help cmdName'.

Arguments

number flags=0

Concommand flags from FCVAR_ Enums.

Examples

Example

Adds a concommand 'killyourself' which will kill the user.

concommand.Add("killyourself",function( ply )
    ply:Kill()
    print("You killed yourself!")
end)


Examples

Example

When every a player runs "retrieveplayers" in the console it'll print anyone who's on the server SteamID & Nick.

concommand.Add( "retrieveplayers", function()  
	for _, v in pairs( player.GetAll() ) do
		print( v:Nick() .. ", " .. v:SteamID() .. "\n" )
	end
end)


Personal tools
Navigation