Skip to main content

CmdrTypes

This class is a collection of types used in Cmdr. Some of the comments here may not be entirely accurate.

Types

TypeDefinition

interface TypeDefinition {
DisplayNamestring
Prefixesstring
Transformnil | (
rawTextstring,
executorPlayer
) → any
Validatenil | (valueT) → (
boolean,
string?
)
ValidateOncenil | (valueT) → (
boolean,
string?
)
Autocompletenil | (valueT) → (
{string},
{IsPartialboolean?}
)
Parse(valueT) → any
Default(plrPlayer) → string
Listableboolean
}
Field Description
DisplayName Optionally overrides the user-facing name of this type in the autocomplete menu. If omitted, the registered name of this type will be used.
Prefixes String containing default Prefixed Union Types for this type. This property should omit the initial type name, so this string should begin with a prefix character, e.g. Prefixes = "# integer ! boolean".
Transform Transform is an optional function that is passed two values: the raw text, and the player running the command. Then, whatever values this function returns will be passed to all other functions in the type (Validate, Autocomplete, and Parse).
Validate The Validate function is passed whatever is returned from the Transform function (or the raw value if there is no Transform function). If the value is valid for the type, it should return true. If it the value is invalid, it should return two values: false, and a string containing an error message. If this function isn't present, anything will be considered valid.
ValidateOnce This function works exactly the same as the normal Validate function, except it only runs once (after the user presses Enter). This should only be used if the validation process is relatively expensive or needs to yield. For example, the PlayerId type uses this because it needs to call GetUserIdFromNameAsync in order to validate. For the vast majority of types, you should just use Validate instead.
AutoComplete A function that returns a list of possible completions for the value. Returns a list of strings and an optional boolean indicating if the completions are partial.
Parse Parse is the only required function in a type definition. It is the final step before the value is considered finalized. This function should return the actual parsed value that will be sent to the command functions.
Default The Default function is optional and should return the "default" value for this type, as a string. For example, the default value of the players type is the name of the player who ran the command.
Listable If you set the optional key Listable to true in your table, this will tell Cmdr that comma-separated lists are allowed for this type. Cmdr will automatically split the list and parse each segment through your Transform, Validate, Autocomplete, and Parse functions individually, so you don't have to change the logic of your Type at all. The only limitation is that your Parse function must return a table. The tables from each individual segment's Parse will be merged into one table at the end of the parse step. The uniqueness of values is ensured upon merging, so even if the user lists the same value several times, it will only appear once in the final table.

ArgumentContext

interface ArgumentContext {
CommandCommandContext--

The command context this argument belongs to.

Namestring--

The name of the argument

TypeTypeDefinition--

The type definition of the argument

Requiredboolean--

Whether or not this argument is required

ExecutorPlayer--

The player that ran the command this argument belongs to.

RawValuestring--

The raw value of the argument

RawSegments{string}--

The raw segments of the argument

Prefixstring--

The prefix of the argument

}

CommandContext

interface CommandContext {
ExecutorPlayer--

The player who executed the command

Namestring--

the name of the command

Descriptionstring--

the description of the command

Aliasstring--

The specific alias of this command that was used to trigger this command (may be the same as Name)

Aliases{string}--

The list of aliases that could have been used to trigger this command

Groupany--

The group this command is a part of. Defined in command definitions, typically a string.

RawTextstring--

the raw text of the command

RawArguments{string}--

the raw arguments of the command

Arguments{ArgumentContext}--

the parsed arguments of the command

Cmdrtable
Dispatchertable--

the dispatcher that ran the command

Statetable--

A blank table that can be used to store user-defined information about this command's current execution. This could potentially be used with hooks to add information to this table which your command or other hooks could consume.

}

CommandArgument

interface CommandArgument {
Typestring | TypeDefinition--

The argument type (case sensitive), or an inline TypeDefinition object

Namestring--

The argument name, this is displayed to the user as they type.

Descriptionstring--

A description of what the argument is, this is also displayed to the user.

Optionalboolean?--

If this is present and set to true, then the user can run the command without filling out this value. The argument will be sent to your commands as nil.

Defaultany?--

If present, the argument will be optional and if the user doesn't supply a value, your function will receive whatever you set this to. Default being set implies Optional = true, so Optional can be omitted.

}

CommandDefinition

interface CommandDefinition {
Namestring
Descriptionstring
Aliases{string}
Groupany?
Args{CommandArgument | (contextCommandContext) → CommandArgument}
Data((
contextCommandContext,
...any
) → any)?
AutoExec{string}?
ClientRun((
contextCommandContext,
...any
) → string?)?
}
Field Description
Name The name that's in auto complete and displayed to user.
Description A description of the command which is displayed to the user.
Aliases Aliases that are not in the autocomplete, but if matched will run this command just the same. For example, m might be an alias of announce.
Group The group this command is a part of
Args Array of CommandArgument objects, or functions that return CommandArgument objects.
Data If your command needs to gather some extra data from the client that's only available on the client, then you can define this function. It should accept the CommandContext for the current command as an argument, and return a single value which will be available in the command with CommandContext.GetData.
AutoExec A list of commands to run automatically when this command is registered at the start of the game. This should primarily be used to register any aliases regarding this command with the built-in alias command, but can be used for initializing state as well. Command execution will be deferred until the end of the frame.
ClientRun An optional function to be run from the executing client
Show raw api
{
    "functions": [],
    "properties": [],
    "types": [
        {
            "name": "TypeDefinition",
            "desc": "| Field | Description |\n| ----- | --- |\n| DisplayName | Optionally overrides the user-facing name of this type in the autocomplete menu. If omitted, the registered name of this type will be used. |\n| Prefixes | String containing default **Prefixed Union Types** for this type. This property should omit the initial type name, so this string should begin with a prefix character, e.g. `Prefixes = \"# integer ! boolean\"`. |\n| Transform | Transform is an optional function that is passed two values: the raw text, and the player running the command. Then, whatever values this function returns will be passed to all other functions in the type (`Validate`, `Autocomplete`, and `Parse`). |\n| Validate | The `Validate` function is passed whatever is returned from the Transform function (or the raw value if there is no Transform function). If the value is valid for the type, it should return true. If it the value is invalid, it should return two values: false, and a string containing an error message. If this function isn't present, anything will be considered valid. |\n| ValidateOnce | This function works exactly the same as the normal `Validate` function, except it only runs once (after the user presses Enter). This should only be used if the validation process is relatively expensive or needs to yield. For example, the PlayerId type uses this because it needs to call `GetUserIdFromNameAsync` in order to validate. For the vast majority of types, you should just use `Validate` instead. |\n| AutoComplete |  A function that returns a list of possible completions for the value. Returns a list of strings and an optional boolean indicating if the completions are partial. |\n| Parse | Parse is the only required function in a type definition. It is the final step before the value is considered finalized. This function should return the actual parsed value that will be sent to the command functions. |\n| Default | The `Default` function is optional and should return the \"default\" value for this type, as a string. For example, the default value of the `players` type is the name of the player who ran the command. |\n| Listable | If you set the optional key Listable to true in your table, this will tell Cmdr that comma-separated lists are allowed for this type. Cmdr will automatically split the list and parse each segment through your Transform, Validate, Autocomplete, and Parse functions individually, so you don't have to change the logic of your Type at all. The only limitation is that your Parse function must return a table. The tables from each individual segment's Parse will be merged into one table at the end of the parse step. The uniqueness of values is ensured upon merging, so even if the user lists the same value several times, it will only appear once in the final table.",
            "fields": [
                {
                    "name": "DisplayName",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Prefixes",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Transform",
                    "lua_type": "nil | (rawText: string, executor: Player) -> any",
                    "desc": ""
                },
                {
                    "name": "Validate",
                    "lua_type": "nil | (value: T) -> (boolean, string?)",
                    "desc": ""
                },
                {
                    "name": "ValidateOnce",
                    "lua_type": "nil | (value: T) -> (boolean, string?)",
                    "desc": ""
                },
                {
                    "name": "Autocomplete",
                    "lua_type": "nil | (value: T) -> ({string}, {IsPartial: boolean?})",
                    "desc": ""
                },
                {
                    "name": "Parse",
                    "lua_type": "(value: T) -> any",
                    "desc": ""
                },
                {
                    "name": "Default",
                    "lua_type": "(plr: Player) -> string",
                    "desc": ""
                },
                {
                    "name": "Listable",
                    "lua_type": "boolean",
                    "desc": ""
                }
            ],
            "source": {
                "line": 35,
                "path": "lib/cmdrhandler/src/Shared/CmdrTypes.luau"
            }
        },
        {
            "name": "ArgumentContext",
            "desc": "",
            "fields": [
                {
                    "name": "Command",
                    "lua_type": "CommandContext",
                    "desc": "The command context this argument belongs to."
                },
                {
                    "name": "Name",
                    "lua_type": "string",
                    "desc": "The name of the argument"
                },
                {
                    "name": "Type",
                    "lua_type": "TypeDefinition",
                    "desc": "The type definition of the argument"
                },
                {
                    "name": "Required",
                    "lua_type": "boolean",
                    "desc": "Whether or not this argument is required"
                },
                {
                    "name": "Executor",
                    "lua_type": "Player",
                    "desc": "The player that ran the command this argument belongs to."
                },
                {
                    "name": "RawValue",
                    "lua_type": "string",
                    "desc": "The raw value of the argument"
                },
                {
                    "name": "RawSegments",
                    "lua_type": "{string}",
                    "desc": "The raw segments of the argument"
                },
                {
                    "name": "Prefix",
                    "lua_type": "string",
                    "desc": "The prefix of the argument"
                }
            ],
            "source": {
                "line": 60,
                "path": "lib/cmdrhandler/src/Shared/CmdrTypes.luau"
            }
        },
        {
            "name": "CommandContext",
            "desc": "https://eryn.io/Cmdr/api/CommandContext.html#commandcontext",
            "fields": [
                {
                    "name": "Executor",
                    "lua_type": "Player",
                    "desc": "The player who executed the command"
                },
                {
                    "name": "Name",
                    "lua_type": "string",
                    "desc": "the name of the command"
                },
                {
                    "name": "Description",
                    "lua_type": "string",
                    "desc": "the description of the command"
                },
                {
                    "name": "Alias",
                    "lua_type": "string",
                    "desc": "The specific alias of this command that was used to trigger this command (may be the same as Name)"
                },
                {
                    "name": "Aliases",
                    "lua_type": "{string}",
                    "desc": "The list of aliases that could have been used to trigger this command"
                },
                {
                    "name": "Group",
                    "lua_type": "any",
                    "desc": "The group this command is a part of. Defined in command definitions, typically a string."
                },
                {
                    "name": "RawText",
                    "lua_type": "string",
                    "desc": "the raw text of the command"
                },
                {
                    "name": "RawArguments",
                    "lua_type": "{string}",
                    "desc": "the raw arguments of the command"
                },
                {
                    "name": "Arguments",
                    "lua_type": "{ArgumentContext}",
                    "desc": "the parsed arguments of the command"
                },
                {
                    "name": "Cmdr",
                    "lua_type": "table",
                    "desc": ""
                },
                {
                    "name": "Dispatcher",
                    "lua_type": "table",
                    "desc": "the dispatcher that ran the command"
                },
                {
                    "name": "State",
                    "lua_type": "table",
                    "desc": "A blank table that can be used to store user-defined information about this command's current execution. This could potentially be used with hooks to add information to this table which your command or other hooks could consume."
                }
            ],
            "source": {
                "line": 92,
                "path": "lib/cmdrhandler/src/Shared/CmdrTypes.luau"
            }
        },
        {
            "name": "CommandArgument",
            "desc": "",
            "fields": [
                {
                    "name": "Type",
                    "lua_type": "string | TypeDefinition",
                    "desc": "The argument type (case sensitive), or an inline TypeDefinition object"
                },
                {
                    "name": "Name",
                    "lua_type": "string",
                    "desc": "The argument name, this is displayed to the user as they type."
                },
                {
                    "name": "Description",
                    "lua_type": "string",
                    "desc": "A description of what the argument is, this is also displayed to the user."
                },
                {
                    "name": "Optional",
                    "lua_type": "boolean?",
                    "desc": "If this is present and set to `true`, then the user can run the command without filling out this value. The argument will be sent to your commands as `nil`."
                },
                {
                    "name": "Default",
                    "lua_type": "any?",
                    "desc": "If present, the argument will be optional and if the user doesn't supply a value, your function will receive whatever you set this to. Default being set implies `Optional = true`, so Optional can be omitted."
                }
            ],
            "source": {
                "line": 126,
                "path": "lib/cmdrhandler/src/Shared/CmdrTypes.luau"
            }
        },
        {
            "name": "CommandDefinition",
            "desc": "| Field | Description |\n| ----- | ----------- |\n| Name | The name that's in auto complete and displayed to user. |\n| Description | A description of the command which is displayed to the user. |\n| Aliases | Aliases that are not in the autocomplete, but if matched will run this command just the same. For example, `m` might be an alias of `announce`. |\n| Group | The group this command is a part of |\n| Args | Array of `CommandArgument` objects, or functions that return `CommandArgument` objects. |\n| Data | If your command needs to gather some extra data from the client that's only available on the client, then you can define this function. It should accept the CommandContext for the current command as an argument, and return a single value which will be available in the command with `CommandContext.GetData`. |\n| AutoExec | A list of commands to run automatically when this command is registered at the start of the game. This should primarily be used to register any aliases regarding this command with the built-in `alias` command, but can be used for initializing state as well. Command execution will be deferred until the end of the frame. |\n| ClientRun | An optional function to be run from the executing client |",
            "fields": [
                {
                    "name": "Name",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Description",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "Aliases",
                    "lua_type": "{string}",
                    "desc": ""
                },
                {
                    "name": "Group",
                    "lua_type": "any?",
                    "desc": ""
                },
                {
                    "name": "Args",
                    "lua_type": "{CommandArgument | (context: CommandContext) -> CommandArgument}",
                    "desc": ""
                },
                {
                    "name": "Data",
                    "lua_type": "((context: CommandContext, ...any) -> any)?",
                    "desc": ""
                },
                {
                    "name": "AutoExec",
                    "lua_type": "{string}?",
                    "desc": ""
                },
                {
                    "name": "ClientRun",
                    "lua_type": "((context: CommandContext, ...any) -> string?)?",
                    "desc": ""
                }
            ],
            "source": {
                "line": 157,
                "path": "lib/cmdrhandler/src/Shared/CmdrTypes.luau"
            }
        }
    ],
    "name": "CmdrTypes",
    "desc": "This class is a collection of types used in Cmdr. Some of the comments here may not be entirely accurate.",
    "source": {
        "line": 7,
        "path": "lib/cmdrhandler/src/Shared/CmdrTypes.luau"
    }
}