Custom Commands Guide

Updated a month ago

Custom Commands Guide

ScarletRCON allows mod developers to create custom RCON commands through a simple attribute-based system. This guide covers all aspects of command creation and registration.

Command Basics

Creating a Command

Define static methods with the [RconCommand] attribute to create commands:

[RconCommand("greet", "Sends a greeting message", "<playerName>")]
public static string Greet(string playerName) 
{
    return $"Hello, {playerName}!";
}

(Note: commands will have your mod's assembly name as a prefix automatically, e.g. mymod.greet)

Key Requirements:

  • Methods must be static
  • Return type should be string for command responses
  • Include a description (second parameter) for help documentation
  • Optionally specify usage syntax (third parameter)

Command Organization

Categorizing Commands

Group related commands using the [RconCommandCategory] attribute:

[RconCommandCategory("Player Management")]
public static class PlayerCommands
{
    [RconCommand("player.kick", "Kicks a player from the server", "<playerName> <reason>")]
    public static string KickPlayer(string playerName, string reason)
    {
        // Implementation
        return $"{playerName} has been kicked. Reason: {reason}";
    }
    
    [RconCommand("player.ban", "Bans a player from the server", "<playerName> <duration> <reason>")]
    public static string BanPlayer(string playerName, int duration, string reason)
    {
        // Implementation
        return $"{playerName} has been banned for {duration} minutes. Reason: {reason}";
    }
}
  • Categories appear in help output
  • Uncategorized commands default to "Miscellaneous"
  • Categories help organize large command sets

Command Naming Conventions

  • Spaces in command names automatically convert to dots (.)
  • Example: "manage player" becomes manage.player
  • This maintains compatibility with RCON systems

Advanced Command Features

Parameter Support

ScarletRCON supports these parameter types:

Type Example Input Notes
int 42 Integer values
float 3.14 Floating-point numbers
bool true/false Case-insensitive
string "hello" Always available
List<string> a b c Must be the last parameter

Method Overloading

Create multiple versions of a command with different parameters:

// Version with custom message
[RconCommand("announce", "Make a server announcement", "<message>")]
public static string Announce(string message) 
{
    Broadcast(message);
    return $"Announced: {message}";
}

// Version with default message
[RconCommand("announce", "Make default server announcement")]
public static string Announce() 
{
    const string defaultMsg = "Server restart in 10 minutes!";
    Broadcast(defaultMsg);
    return $"Announced default message";
}

The system automatically selects the best match based on provided arguments.

Command Registration

Integration Methods

Choose the registration approach that matches your integration:

Option 1: Using ScarletRCON Directly

// Typically in your mod's initialization
CommandHandler.RegisterAll();

Option 2: Using Optional Integration

// For mods with optional ScarletRCON dependency
RconCommandRegistrar.RegisterAll();

Command Invocation Format

Commands follow this structure when called via RCON:

<modPrefix>.<commandName> <arguments>

Example for a mod called "ChatMod":

chatmod.announce Hello everyone!

For complete integration examples and advanced scenarios, visit the Integration Guide.