ITextChatCommand Interface

Can be implemented to create custom commands.

Definition

Namespace: Alteruna.Multiplayer
Assembly: Alteruna (in Alteruna.dll) Version: 2.0.1+a1176e08a0b4a6bfd8fefeddde6163a16d29e5ab
C#
public interface ITextChatCommand

Remarks

ITextChatCommand is used to create slash commands that can be used with TextChatSynchronizable.

There are several built-in commands in Alteruna. One of them is "/execute". It can be used to run command as a different user.
/execute as allInclusive say Hello everyone!
This would make all players say "Hello everyone!" in the chat. Note that allInclusive can be replaced by the shorthand alli.

Example

Here we have an example adding a simple command to the text chat.
C#
public class CommandPrintLine : ITextChatCommand
{
       public string Command { get; } = "printline";
       public string Description { get; } = "print a message to local chat.";
       public string Usage { get; } = "/printLine <msg>";
       public bool IsCheat { get; } = false;
       public bool IgnoreCase { get; } = true;

       // Register command
       [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
       public static void Init() => TextChatSynchronizable.Commands.Add(new CommandPrintLine());

       public string Execute(TextChatSynchronizable textChat, string[] args)
       {
           if (args.Length < 0)
           {
               // Log error to the chat and return an empty response
               textChat.LogError("No message");
               return null;
           }

           // Join arguments as a singular string and return it to log it.
           return string.Join(" ", args);
       }
}
Here's an example of accessing MultiplayerManager.
C#
public class DisplayUserCommand : ITextChatCommand
{
       public string Command => "displayuser";
       public string Description => "displays username and ID of the user who used the command.";
       public string Usage => "/displayuser";
       public bool IsCheat => false;
       public bool IgnoreCase => true;

       [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
       public static void Init() => TextChatSynchronizable.Commands.Add(new DisplayUserCommand());

       public string Execute(TextChatSynchronizable textChat, string[] args)
       {
           // We can access MultiplayerManager to get the user who ran the command.
           User user = textChat.Multiplayer.GetUser();

           // We return the message we want the TextChatSynchronizable the send to the chat.
           // The message will also be sent to the Unity console.
           return $"{user.Name} with ID {user.Index} ran the /displayuser command!";
       }
}

Properties

Command The written command name. Inputting a slash following with the command name runs the command.
Description The description that is displayed when running /help.
IgnoreCase Determines whether capital letters are taken into consideration or not.
IsCheat Determines whether the command is a cheat or not. A cheat can be considered a developer shortcut.
Usage Displays how the command is written to run properly.

Methods

Execute Called when command is executed by a user.

See Also