Skip to content
arendjr edited this page Jan 28, 2013 · 7 revisions

There's a bunch of commands included with the PlainText engine, but chances are you will want to add your own and/or modify the ones that are available. First thing you will want to know is there are 3 types of commands: regular commands, admin commands, and API commands.

Every common command, like "say", or "go" is a simple, plain, regular command. You can easily get an overview of all these commands:

help commands

Admin commands are those that may only be executed by users who are an admin. All the commands for OLC / room building fall under this category. If you are an admin, you can also request an overview of these:

help admin-commands

API commands are more internal to the engine, and are used for communication between the MUD server and the HTML5 interface. They are not related to gameplay, not visible to the user, and you cannot get an overview of them (other than peeking in the code).

JavaScript Commands

The preferred way to implement commands is through JavaScript. The JavaScript commands are located in the data/commands/ directory. Admin commands are located in the admin/ subdirectory. API commands currently cannot be implemented in JavaScript.

The skeleton for a regular JavaScript command looks like this:

function MyCommand() {
    Command.call(this);

    this.setDescription("Here you give the description of the command, as shown by the " +
                        "help command.");
}

MyCommand.prototype = new Command();
MyCommand.prototype.constructor = MyCommand;

MyCommand.prototype.execute = function(player, command) {

    this.prepareExecute(player, command);

    // here goes the actual code implementing the "my" command...
};

CommandRegistry.registerCommand("my", new MyCommand());

As you can see, there's a bit of boiler plate code that you should just copy/paste. You can rename "MyCommand" to anything you like, as long as you carefully replace all instances.

The last line serves to register the command so that players can actually use it. You can register the command under multiple names if you like, by simply repeating that last line and using different names as the first argument.

C++ Commands

It's also possible to implement commands in C++. Unless you're implementing an API command or a command that is very resource intensive, I advise against using C++ as it's harder to use and more work to maintain.

If you want to take a look though, the C++ commands are located in the src/engine/commands/ directory.

C++ commands are registered directly inside the CommandRegistry.

Further Reading

Read how you can create triggers, or how you can customize game objects and game events.

You may want to take a look at the Frequently Asked Questions.

Clone this wiki locally