concommand/Add

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Fixed up. There's no reason to have 3 examples that show the exact same thing.)
Line 37: Line 37:
 
}}
 
}}
 
{{Example
 
{{Example
|Description=Adds a concommand 'printnick' which will print the user's name to console
+
|Description=Adds a concommand 'killyourself' which will kill the user.
|Code=concommand.Add("printnick",function(ply,cmd,args,str)
+
|Code=concommand.Add("killyourself",function( ply )
    print("Concommand printnick has been used by: "..ply:Nick())
+
end)
+
}}
+
{{Example
+
|Description=Adds a concommand 'killyourself' which will kill the user. --[[User:Devul|by Devul.]] 13:47, 13 March 2013 (UTC)
+
|Code=concommand.Add("killyourself",function(ply)
+
 
     ply:Kill()
 
     ply:Kill()
 
     print("You killed yourself!")
 
     print("You killed yourself!")
end)
 
}}
 
 
 
{{Example
 
|Description=Adds a concommand 'to give yourself 200 hp.'
 
--[[User: PropGamer|by PropGamer.]]
 
|Code=concommand.Add("get200hp",function( Player )
 
    Player:SetHealth( 200 )
 
    print("You have been given 200 hp!")
 
 
end)
 
end)
 
}}
 
}}

Revision as of 17:05, 14 December 2013

 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.

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. Optional.

Args: ( string cmd , string args )

Arguments

string helpText=nil

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

Arguments

number flags=0

Concommand flags from FCVAR_ Enums. Optional.

Examples

Example

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

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


Personal tools
Navigation