CommandMod

dani0105

Modder
Registered
#1
Command Mod for Spaceflight Simulator
A simple command console for Spaceflight Simulator and API for modders.

How to install
It is necessary to install modloader, you can download it at this link. This mod is easy to install, all you need to do is go to release and download the version you need, then download CommandMod.zip and put it in the MODS folder where you have SFS installed, then unzip your file and you will get something like CommandMod folder with CommandMod.dll file inside. Now run your game and if you press P the console will appear.

How to Use
To use this mod, you just need to press P and type the command you need. If you need to know what commands are installed, type /help, this command will show you all installed commands.

How to Implement on my mod
I will attach an example of how to register commands from your mod.

C#:
using ModLoader;
using SFS.Parts.Modules;
using SFS.World;
using System;
using UnityEngine;
using CommandMod;
using CommandMod.Commands;
using System.Collections.Generic;

namespace MyMod
{
  public class Main : SFSMod
  {
    public Main() : base(
        "mymodid", // mod id
        "My Mod Name", // Mod name
        "author",  // author
        "v1.1.x", // min modloader version  require
        "v1.0.0", // mod version
        "Mod Description", // description
        null, // assets file name if you need
        new Dictionary<string, string[]> { { "commandMod", new string[] { "v1.0.0"}  } } //add Command Mod as dependency
        )
    {
    }

    public override void load()
    {
      // get command mod instance
      CommandMod.CommandMod commandMod = (CommandMod.CommandMod) Loader.main.getMod("commandMod");
      // create my command
      ConsoleCommand helloWorld = new ConsoleCommand("helloworld","Print 'Hello World!'", "/helloworld",this.helloWorld);
      // register my command
      commandMod.registerCommand(helloWorld);
    }

    // command function
    private string helloWorld(string[] args)
    {
      // do things here
      return "Hello World!";
    }

    public override void unload()
    {
      throw new System.NotImplementedException();
    }
  }
}
 

Attachments

#5
See the "How to implement in my mod" section. there I tell you how you should use in your mod
what does this: ("helloworld","Print 'Hello World!'", "/helloworld" part do? I get that /helloworld is how you call a command, but what are the others, also how do I set int by command like /helloworld {int}?
 

dani0105

Modder
Registered
#6
what does this: ("helloworld","Print 'Hello World!'", "/helloworld" part do? I get that /helloworld is how you call a command, but what are the others, also how do I set int by command like /helloworld {int}?
commandID is used to identify your command when the user types to the console.
C#:
string commandID = "helloworld";
string description = "Print 'Hello World!";
string format = "/helloworld";   //The format is only used to show how the user should type their command.

ConsoleCommand myCommand = new ConsoleCommand( commandID, description , format, this.helloWorld );

For parameters it's easy, because when the user writes something like this
Bash:
/helloworld 1 5
the commandmod will take the values 1 and 5 as parameters and store them in the string[] which is passed as parameter args as in the example

C#:
// command function
    private string helloWorld(string[] args)
    {
      // do things here
      return "Hello World!";
    }
 
#7
commandID is used to identify your command when the user types to the console.
C#:
string commandID = "helloworld";
string description = "Print 'Hello World!";
string format = "/helloworld";   //The format is only used to show how the user should type their command.

ConsoleCommand myCommand = new ConsoleCommand( commandID, description , format, this.helloWorld );

For parameters it's easy, because when the user writes something like this
Bash:
/helloworld 1 5
the commandmod will take the values 1 and 5 as parameters and store them in the string[] which is passed as parameter args as in the example

C#:
// command function
    private string helloWorld(string[] args)
    {
      // do things here
      return "Hello World!";
    }
Thank you, tho what is comand ID used for?
 
#9
commandID is used to identify your command when the user types to the console.
C#:
string commandID = "helloworld";
string description = "Print 'Hello World!";
string format = "/helloworld";   //The format is only used to show how the user should type their command.

ConsoleCommand myCommand = new ConsoleCommand( commandID, description , format, this.helloWorld );

For parameters it's easy, because when the user writes something like this
Bash:
/helloworld 1 5
the commandmod will take the values 1 and 5 as parameters and store them in the string[] which is passed as parameter args as in the example

C#:
// command function
    private string helloWorld(string[] args)
    {
      // do things here
      return "Hello World!";
    }
Now, there is another problem, Im getting this error. Everything is set to same name, idk what is the problem....
 

Attachments

dani0105

Modder
Registered
#10
Now, there is another problem, Im getting this error. Everything is set to same name, idk what is the problem....
there are an error on "private string setTrhust". your method should be like this
C#:
private string MyCommand(string[] args)
{
    return "";
}
the args param is important and the return