Return to Main Docs Page

concommand.Add

NewerShared.png Creates a console command that runs a function in lua.

concommand.Add( string name , function callback, string helpstring, number flags )
               

Arguments:


  • 1) string name
  • The command name to be used in console.

    This cannot be a name of existing console command or console variable. It will silently fail if it is.

  • 2) function callback
  • The function to run when the concommand is executed.

    Function callback arguments are:
    • CBasePlayer ply
    • - The player that ran the concommand. NULL entity if command was entered with the dedicated server console.
    • string cmd
    • - The concommand string (if one callback is used for several concommands).
    • string arg
    • - The arguments as a string.

  • 3) string helpstring
  • The function to run when the concommand is executed.

  • 4) number flags
  • The function to run when the concommand is executed.

Example:


concommand.Add("ConsoleCommand", function(ply, cmd, arg) 
   print("ConCommand is Working!")
   if arg ~= nil then
      print(ply:GetPlayerName().." executed command: "..cmd.." with "..arg.." as argument. ")
   end
end)
               

Output:


ConCommand is Working!
Dim1xs executed command: ConsoleCommand with 1 as argument.