Commands

How to create a Command

To start creating a Command you have to create a Type that inherit from SynapseCommand and has the Attribute SynapseCommandAttribute which contains all the information for the Command

using Neuron.Core.Meta;
using Neuron.Modules.Commands;
using Synapse3.SynapseModule.Command;

namespace DocsExample;

[Automatic]
[SynapseCommand(
    CommandName = "Hello",
    Aliases = new[] { "HelloWorld" },
    Description = "A Example Command",
    Permission = "docs.hello",
    Platforms = new [] { CommandPlatform.PlayerConsole }
    )]
public class HelloWorldCommand : SynapseCommand
{
    public override void Execute(SynapseContext context, ref CommandResult result)
    {
        
    }
}

Inside your Execute method can you now Place your code that should be executed when this command is used

Result and Context

You have maybe noticed that your Execute method has 2 Arguments: SynapseContext and CommandResult.

SynapseContext gives you information about the execution of the command like Arguments Player or Platform.

CommandResult is what will be send back to the Player: Response is the Message and StatusCode mostly just the Color

using Neuron.Core.Meta;
using Neuron.Modules.Commands;
using Neuron.Modules.Commands.Command;
using Synapse3.SynapseModule.Command;

namespace DocsExample;

[Automatic]
[SynapseCommand(
    CommandName = "Hello",
    Aliases = new[] { "HelloWorld" },
    Description = "A Example Command",
    Permission = "docs.hello",
    Platforms = new [] { CommandPlatform.PlayerConsole, CommandPlatform.RemoteAdmin, CommandPlatform.ServerConsole }
    )]
public class HelloWorldCommand : SynapseCommand
{
    public override void Execute(SynapseContext context, ref CommandResult result)
    {
        result.Response = "Hello " + context.Player.NickName;
        result.StatusCode = CommandStatusCode.Error;
    }
}

Platform

The Property Platforms inside the SynapseCommand Attribute will be used to determine in which Console(s) you can use this Command

PreExecute and Permission

Your command has also a Method called PreExecute which is called before your actual Execute method. By default this method will check the Player Permission when the Property is not empty or null.

Last updated