tModLoader Custom Commands - Making your own Commands

Trivaxy

Skeletron Prime
Hello and welcome to the Custom Commands Mod - A mod you can use to code your own commands.
NOTE: This mod is currently obsolete for later versions of tModLoader and will not work on versions that have ModCommand implemented.
This mod was made due to the lack of ModCommand, of course, this is only a placeholder until ModCommand releases. But this is still pretty functional, which is why I'm sharing it.

Custom Commands allows you to create commands with arguments that you can use easily. Sooner or later you'll make a /help command that spawns moon lord at the player's position! :p

You can find the Custom Commands wiki here on Github: https://github.com/XVoltzX/TrivaxysThings/wiki


Now, I'll just provide a step-by-step example of making your own command within your mod.

1. Download the CustomCommands mod from here, or on the Mod Browser.
2. After you have installed CommandsMod, go to your Mod's build.txt file.
3. In your build.txt file, add this line: " modReferences = CommandsMod "


Note: Your mod will not be able to load if CommandsMod is not loaded, so kindly ask your mod players to install CommandsMod, or if you want, make a separate mod for adding commands. But hey, it's all up to you.

After you followed these steps you should be good to go. Now to making an example command..

Command Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommandsMod; //Adding this is very important!
using Terraria; //This too.

namespace MyMod.Command
{

public class MyCommand : CustomCommand
{

public override string Command()
{
return "mycommand"; //People will use it as /mycommand
}

public override int[] InputCount()
{
return new int[1]; //How many arguments people need to put in, in this case, 1. If you don't want arguments, make it 0.
}

public override string Description()
{
return "Does stuff."; //Description of your command that will display when people do /description mycommand
}

public override string Usage()
{
return "/mycommand <1 word of text>"; //Usage of your command that will display when people do /usage mycommand
}

public override void Action(string[] args)
{ //OHOHO HERE COMES THE JUICY PART. This is what your command will do.

//Remember how we told the command "we have 1 argument the player needs to input" in InputCount ?

//Ok, now we will use it. See that " string[] args " ? This is the array of arguments the player inputs. However, its size is 1 because, well, look at InputCount.

//Of course, the arguments are in the form of strings, you'll have to convert them to ints or something if you don't want them to be strings.

//But I'm just gonna put a simple Main.NewText because I'm lazy.


Main.NewText(args[0].ToString(), 40, 80, 100);

//Let's say the player does /mycommand Hello
//The game would print "Hello" in the color of rgb values up there which are 40, 80 and 100
}

}

}​

There, an example of making the command itself!
But we're not done, one thing we have to do to make it work and not let it just sit there!

In our Mod.cs file, we will add this:

public override void Load()
{
//You must add all your commands like this.
//We want to add our command 'MyCommand' which is the class name.
CommandHandler.AddCommand(new MyCommand());
}

And that's all! Recompile the mod, go into chat and type /mycommand HELLO
to see it in action.

I hope you find a use for this, but just taking the time to look at it means a lot to me :)
If you use this, then no need to credit! But I'd like to ask you to show me a picture of the commands you made :D

Getting errors when trying to make commands? That's perfectly fine! You can always drop a reply here and I'll get back to you as soon as possible.

Please report any bugs you find to me, by the way. And have a good day!



(If you want a more detailed example, then here is the /spawnnpc included with CommandsMod):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using CommandsMod;
using Terraria.ModLoader;
using Terraria.ID;

namespace CommandsMod.Commands
{

public class SpawnNPCCommand : CustomCommand
{

public override string Command()
{
return "spawnnpc";
}

public override int[] InputCount()
{
return new int[3];
}

public override string Description()
{
return "Spawns a npc at a specified location.";
}

public override string Usage()
{
return "/spawnnpc <NPC ID> <X Coordinate> <Y Coordinate>";
}

public override void Action(string[] args)
{
try //We're using a try..catch here in case the player inputs arguments that are not.. expected. (preventing a crash, but I already handle most)
{
int Type = Convert.ToInt32(args[0]);
int X = Convert.ToInt32(args[1]);
int Y = Convert.ToInt32(args[2]);

NPC.NewNPC(X, Y, Type);
Main.NewText("NPC " + Type + " spawned at " + X + ", " + Y + ".", 50, 80, 120);
}

catch(Exception e)
{
Main.NewText("Error: Bad Arguments. Are you inputting correct data?",200,10,10);
}

}

}

}


Download from Mediafire:
Click here.

Or um, it is also available on the Mod Browser.

Changelog for 1.1:
Added a /list command that lists all the commands.
 
Last edited:
ugh its confusing... can you just add something like /spawnboss "(boss name)"
For example: /spawnboss "Destroyer" or /spawnboss "Moon Lord"
that would be very useful!
 
Are you gonna release a command content pack to avoid having to setup basic commands yourself ?
Yes, I will start working on it and include it with this mod itself, to whoever doesn't want to make them.
ugh its confusing... can you just add something like /spawnboss "(boss name)"
For example: /spawnboss "Destroyer" or /spawnboss "Moon Lord"
that would be very useful!
Well, it'd be fairly simple to do, you can expect it in the next update.
 
Yes, I will start working on it and include it with this mod itself, to whoever doesn't want to make them.

Well, it'd be fairly simple to do, you can expect it in the next update.
ok, also try /spawnnpc (npc name, like.. Guide,dryad,merhcant, etc.) (#) ex: /spawnnpc Dryad 5
or, of course, /spawnmob Zombie 10
 
ok, also try /spawnnpc (npc name, like.. Guide,dryad,merhcant, etc.) (#) ex: /spawnnpc Dryad 5
or, of course, /spawnmob Zombie 10
That'd be wayyyyyyy too much of a hassle because of, well, um, programming.
Right now I did accomplish a /spawnboss that does, for example, /spawnboss retinazer ~ ~ which spawns retinazer at your position.
 
Note to everyone: tModLoader has updated since quite a while, and this certain tML update basically broke Custom Commands since it removed one of the things I needed.

I will proceed to port this mod over to newer versions of tML, with a whole new bundle of commands.
 
Your mod is best. But there is one problem. I have never played it because is too old and my tmodloader (0.10.1.4) cant compile it! :(

Are you planing to update mod? Please Update it!

Thanks!
 
Back
Top Bottom