Chat Commands - PULSAR-Modders/pulsar-mod-loader GitHub Wiki

Chat Commands are created using classes which inherit from PulsarModLoader.Chat.Commands.CommandRouter.ChatCommand. No initialization is required, as the mod loader will find and instantiate all ChatCommand classes. Commands for use by clients without mods, known as Public Commands, will follow the same syntax and inherit from PulsarModLoader.Chat.Commands.CommandRouter.PublicCommand.

ChatCommand classes require 3 method overrides for command aliases (command names), the command description, and the function for execution. There are 2 optional method overrides for usage examples and subcommand + variable autofilling.

class MyCommand : ChatCommand
{
    //mandatory overrides
    public override string[] CommandAliases()
    {
        return new string[] { "MyCommand", "MC" } ;
    }

    public override string Description()
    {
        return "A brief and concise description";
    }

    public override void Execute(string arguments)
    {
        //Code for execution...
    }

    //optional overrides
    public override string[] UsageExamples()
    {
        return base.UsageExamples();
    }

    public override string[][] Arguments()
    {
        return base.Arguments();
    }
}

The CommandAliases() method provides PML with all aliases for user usage. For the example below, the user typing in '/firstAlias' or '/alias2' would trigger the Execute(string arguments) function, providing any extra text as arguments. Command aliases registered in PML and typed in by the user are compared in lowercase.

public override string[] CommandAliases()
{
    return new string[] { "firstAlias", "alias2" } ;
}

The Description() method provides a string for the /help command, which will display the command names alongside the description.

public override string Description()
{
    return "A brief and concise description";
}

The Execute(string arguments) function executes code. User text following the chat command is provided in the arguments string. If the user were to type '/firstalias arg1 arg2', the function will be fed 'arg1 arg2'.

public override void Execute(string arguments)
{
    //Code for execution...
}

The Arguments() Method provides autofill via tab key while typing for subcommands and arguments. This has features for autofilling with player names and roles by using %player_name or %player_role.

public override string[][] Arguments()
{
    return new string[][] { new string[] { "argOption1", "argOption2" } };;
}