(This tutorial has been copied with the approval of D1st0rt from D1st0rt's website.)

Tutorial 3: Commands

Written by D1st0rt @ Friday, 19 November 2004
Last updated: Wednesday, 02 March 2005

Uh oh, we have no control over our bot. Not to fear, thats what commands are for. Commands mainly utilize the CommandInterpreter, though technically you can do it without one. In order to make sure the wrong people don't use certain commands, we will use an OperatorList, which gives access to staff at the same level they are in your zone's moderate, smod and sysop.txt files.

//Make the package name the same as the bot's name so you can spawn it
package twcore.bots.mybot;
//Import all of the TWCore classes so you can use them
import twcore.core.*;

public class mybot extends SubspaceBot
    //Requests all of the events from the core
    private EventRequester events;
    //Handles all commands sent to bot by players
    private CommandInterpreter cmds;
    //Stores Staff Access Levels
    private OperatorList oplist;

    //Creates a new mybot
    public mybot(BotAction botAction)
        //This instantiates your BotAction
        //Instantiate your EventRequester
        events = m_botAction.getEventRequester();
        //Request PlayerEntered events
        //Request chat message events
        //Instantiate your CommandInterpreter
        cmds = new CommandInterpreter(m_botAction);
        //Instantiate your Operator List
        oplist = m_botAction.getOperatorList();
        //Set up your interpreter

    //What to do when the bot logs on
    public void handleEvent(LoggedOn event)
        //Get the data from mybot.cfg
        BotSettings config = m_botAction.getBotSettings();
        //Get the initial arena from config and enter it
        String initial = config.getString("InitialArena");
        //NOTE: m_botAction is inherited from SubspaceBot

    //What to do when a player enters the arena
    public void handleEvent(PlayerEntered event)
        //Get the name of player that just entered
        String name = event.getPlayerName();
        //Greet them

    //What to do when somebody says something
    public void handleEvent(Message event)
        //Pass it to the interpreter

    //Set up commands
    public void addCommands()
        //Allowed message types for commands
        int ok = Message.PRIVATE_MESSAGE | Message.PUBLIC_MESSAGE;
        //Add any commands as you see fit

    //Got command: !help
    public void help(String name, String msg)
        //Help Message
        String[] help =
        {"!help - this message",
         "!die - kills bot",
         "!go (arena) - sends bot to arena"};
        //Send player the help message

    //Got command: !die
    public void die(String name, String msg)
        //Make sure player has clearance
            //Destroy bot, allows another to be spawned

    //Got command: !go
    public void go(String name, String msg)
        //Make sure player has clearance
            //Join arena specified by player

The first parameter in registerCommand is what the player types. The second is the allowed message types, the third is the object that the method will be called in, and the last is the name of the method to be called. oplist.isER() will return true if the player is at least an , the staff hierarchy is as follows:

Previous Tutorial | Next Tutorial