Difference between revisions of "ScriptHook: Console Commands"

From Nomad DB
(Created page with "The ScriptHook Console can be extended by custom commands from Scripts. This guide will show you how to register these c...")
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The [[WD2 ScriptHook: Console|ScriptHook Console]] can be extended by custom commands from [[WD2 ScriptHook: Script|Scripts]]. This guide will show you how to register these commands and impement validating arguments.
+
The [[ScriptHook: Console|ScriptHook Console]] can be extended by custom commands from [[ScriptHook: Script|Scripts]]. '''A full example for a custom command can be found [[ICommandRegistry:AddArgument|here]].'''
  
== Example ==
+
== Short Example ==
 
The following snippet will register the console command ''my_cmd <arg1>''.
 
The following snippet will register the console command ''my_cmd <arg1>''.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
Line 11: Line 11:
 
local my_cmd = ScriptHook.RegisterCommand("my_cmd", my_callback)
 
local my_cmd = ScriptHook.RegisterCommand("my_cmd", my_callback)
 
my_cmd:AddArgument("arg1", true, CommandArgumentType.Any)
 
my_cmd:AddArgument("arg1", true, CommandArgumentType.Any)
 +
my_cmd:SetDescription("This is my_cmd help text.")
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Related Pages ==
 
== Related Pages ==
* [[WD2 ScriptHook: Console]]
+
* [[ScriptHook: Console]]
 
* [[ScriptHook.RegisterCommand]]
 
* [[ScriptHook.RegisterCommand]]
  
[[Category:WD2 ScriptHook]]
+
[[Category:ScriptHook]]

Latest revision as of 23:04, 6 October 2020

The ScriptHook Console can be extended by custom commands from Scripts. A full example for a custom command can be found here.

Short Example

The following snippet will register the console command my_cmd <arg1>.

local function my_callback(arg1)
	print("Hello from my_cmd")
	print("arg1: ", arg1)
end

local my_cmd = ScriptHook.RegisterCommand("my_cmd", my_callback)
my_cmd:AddArgument("arg1", true, CommandArgumentType.Any)
my_cmd:SetDescription("This is my_cmd help text.")

Related Pages