Chat Commands

SML adds a system allowing you to add your own chat commands. It is highly recommended that you use this system as opposed to writing your own so that the behavior of chat commands is consistent across different mods.

AChatCommandInstance

Each chat command you want to implement in BP should inherit from AChatCommandInstance.

This class contains some attributes you need to set to tell SML about your command:

  • Only Usable by Player

    This allows you to make sure only players can execute the command, as opposed to other mods calling them.

  • Min Number Of Arguments

    If the number of arguments used to execute the command is lower than this value, the command wont get executed.

  • Command Name

    This is the name of your command you want to add. It will be what the user types to run the command.

  • Aliases

    This is a list alternative Command Names for your command. You will be able to use them in place of the Command Name when running the command.

  • Usage

    This is the description of your command how it should get used by the player. It will be displayed in help menus and when the command is not given enough arguments. You should provide a description of what the command does, what each parameter is, and possibly an example valid command.

To give the command now some functionality, you just need to override the Execute Command function and add your own logic to it.

This function receives the command sender, the command arguments, and the used alias (if any) and should either return COMPLETED in the case of success, or, in the case of an error, logging an error about what in the execution didn’t work and returning UNCOMPLETED, INSUFFICIENT_PERMISSIONS, or BAD_ARGUMENTS.

After that you need to register your command for SML to be able to load it. You can do that by simply adding it to the M Chat Commands array of your Game World Module.

UCommandSender

This class represents the sender of a chat command and allows you to get abstract information about the sender.

A sender could be a player, for example.

AChatCommandSubsystem

This subsystem provides a number of helpful chat command utilities. It allows you to…​

  • Register a chat command instance manually

  • Get a list of registered commands

  • Executed a command programmatically

  • Access the ParsePlayerName function, which allows you to get the AFGPlayerController based on the player name.

    • This is generally used to parse the player name that was passed as command argument. It also allows you to parse selectors in the command like @all and @self.