ICommandRegistry:AddArgument

From Nomad DB
Revision as of 12:34, 15 April 2020 by Jan (talk | contribs) (Created page with "Registers an argument to a Console Command. It is part of the ICommandRegistry interface that is returned by ScriptHook.RegisterComma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)

Related Pages