AddCommand: Difference between revisions

From Onset Developer Wiki
(Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|AddCommand(CommandName, LuaFunction)}} {{FuncParameters}} {{FuncParam|CommandName|__EDIT_ME__}} {{...")
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Client & Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Adds a command that can be executed with the prefix '''/'''.}}


{{FuncSyntax|AddCommand(CommandName, LuaFunction)}}
{{FuncSyntax|AddCommand(CommandName, LuaFunction)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|CommandName|__EDIT_ME__}}
{{FuncParam|CommandName|The specified command name. Command names are always lower case.}}
{{FuncParam|LuaFunction|__EDIT_ME__}}
{{FuncParam|LuaFunction|The function name.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns '''true''' on success.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua>
function cmd_commands(playerid)
AddPlayerChat(playerid, "You just executed a command!")
return
end
AddCommand("commands", cmd_commands)
AddCommand("cmds", cmd_commands)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
* [[AddPlayerChat]]

Latest revision as of 21:29, 6 October 2020

AddCommand

Type: Function
Context: Client & Server
Introduced: v1.0

Description

Adds a command that can be executed with the prefix /.

Syntax

AddCommand(CommandName, LuaFunction)

Parameters

  • CommandName
    The specified command name. Command names are always lower case.
  • LuaFunction
    The function name.

Return Value

  • Returns true on success.

Example

function cmd_commands(playerid)
	AddPlayerChat(playerid, "You just executed a command!")
	return
end
AddCommand("commands", cmd_commands)
AddCommand("cmds", cmd_commands)

See also