Onsharp
  • What is Onsharp?
  • Changelog
  • Onsharp Environment
    • Onsharp Runtime Environment
    • Installation
    • Configuration
  • Basic Usage
    • Preparation
    • Create a Basic Plugin
    • Concept of Entry Points
    • Create Commands
    • The EventAPI of Onsharp
    • Configs and DataStorage
    • Logging
    • Debugging
  • Advance Usage
    • Auto Updater
    • Overriding Entity Factories
    • Interop of LUA and vice versa
    • Entity Pool Refreshing
    • Create Console Commands
    • Providing LUA packages
  • Modules
    • Lazy Mover
    • I18n
Powered by GitBook
On this page

Was this helpful?

  1. Advance Usage

Create Console Commands

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

PreviousEntity Pool RefreshingNextProviding LUA packages

Last updated 4 years ago

Was this helpful?

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 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

The methods to register them are:

  • Runtime.RegisterConsoleCommands() : for non static methods

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

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

commands
click here