Create Console Commands

On this page we will explain how to create own console commands.

Onsharp offers a possiblity to create own console commands. Onset itself does not implement any kind of console input. Onsharp puts a console management layer above the Onset server and allows you to create those interactions.

The console command creation does not differentiate much from the normal commands the only big change is, that you don't have any player at the first parameter.

So to create such a console command you just need to create a handling method and mark it as console command:

using Onsharp.Commands;
using Onsharp.Entities;
using Onsharp.Plugins;

namespace Tutorial
{
    public class PluginMain : Plugin
    {
        public override void OnStart()
        {
             //Your start up logic here
        }
        
        public override void OnStop()
        {
            //Your stop and clean up logic here
        }  
        
        [ConsoleCommand("name", "Does something")]
        public void OnConsoleCommand(string param1)
        {
            // Does something
        }
    }
}

You see, its almost the same, but what you also can see is, that you need to define the command description because the console command manager offers the help command to see which commands are registered and how to use them.

Register Commands

Registering commands manually is the same procedure as with the normal commands. Please head over to read more about it: click here.

The methods to register them are:

  • Runtime.RegisterConsoleCommands() : for non static methods

  • Runtime.RegisterConsoleCommands<>() : for static methods

Last updated