Skip to content

Implementing A New Command

Rocky Bevins edited this page Aug 9, 2020 · 20 revisions

Send a players HP to everyone in the current room.

Lets add a 'report' command that will give the command issuer's current HP to their current Room.

First add new file 'report.js' to src/commands (note that new commands can be added directly into commands.js).

'use strict'
var World = require('../world');

module.exports = function(entity, command) {
    World.msgRoom(command.roomObj, {
        msg: 'Current HP: ' +  entity.chp
    });
};

Now when you restart the server you can expect a 'report' command to give every player in the room the callers current HP.

Aliases

If you wanted a player facing alias for our new report command (for example 'rep') you can expand the logic in your client file. RockMUDs public/js/rockmud-client.js serves as an example.

Clone this wiki locally