Difference between revisions of "ICommandRegistry:AddArgument"
From Nomad DB
(Created page with "Registers an argument to a Console Command. It is part of the ICommandRegistry interface that is returned by ScriptHook.RegisterComma...") |
|||
Line 1: | Line 1: | ||
− | Registers an argument to a [[ | + | Registers an argument to a [[ScriptHook: Console Command|Console Command]]. It is part of the [[ICommandRegistry]] interface that is returned by [[ScriptHook.RegisterCommand]]. Arguments support validation using [[CommandArgumentType]] enum. Arguments can also be marked as optional. |
== Syntax == | == Syntax == | ||
Line 18: | Line 18: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | When executing the ''teleport'' command, the [[ | + | When executing the ''teleport'' command, the [[ScriptHook: Console|Console]] will validate if |
* all required arguments are given | * all required arguments are given | ||
* the given arguments can be parsed as decimal values (float) | * the given arguments can be parsed as decimal values (float) | ||
Line 26: | Line 26: | ||
* [[CommandArgumentType]] | * [[CommandArgumentType]] | ||
− | [[Category: | + | [[Category:ScriptHook Lua]] |
Latest revision as of 12:58, 6 October 2020
Registers an argument to a Console Command. It is part of the ICommandRegistry interface that is returned by ScriptHook.RegisterCommand. Arguments support validation using CommandArgumentType enum. Arguments can also be marked as optional.
Syntax
[command]:AddArgument(name[, required, type])
- name (string) Argument name
- Optional: required (boolean) Specifies whether the argument is required (default: true)
- Optional: type (CommandArgumentType) Argument validation
Example
In this example, we imagine a teleport <x> <y> <z> command. The x, y, z coordinates are marked as float to allow decimal representation.
local cmd_teleport = ScriptHook.RegisterCommand("teleport", [...])
cmd_teleport:AddArgument("x", true, CommandArgumentType.Float)
cmd_teleport:AddArgument("y", true, CommandArgumentType.Float)
cmd_teleport:AddArgument("z", true, CommandArgumentType.Float)
When executing the teleport command, the Console will validate if
- all required arguments are given
- the given arguments can be parsed as decimal values (float)