tagpro-bot-talk
v0.2.1
Published
Efficiently communicate with other bots in TagPro.
Downloads
16
Readme
TagPro Bot Talk
This library facilitates communication between bots for the game TagPro.
Usage
To use in a userscript, add
// @require https://raw.githubusercontent.com/chrahunt/tagpro-bot-talk/master/dist/messenger.jsto your header and access the library using the global BotMessenger object. You may also include the script directly in a page, where it will behave the same (creating a BotMessenger global).
The library can also be used as an AMD/CommonJS module. Download or npm install tagpro-bot-talk and require('tagpro-bot-talk') for CommonJS or add as a dependency to your define or require calls in AMD.
To start, you need to initialize the BotMessenger. The constructor takes the id of the current player, and the game socket (or socket-like object) to be communicated over.
var messenger = new BotMessenger(tagpro.playerId, tagpro.socket);To send a message, just emit an event:
messenger.emit('gotpup', { x: 14, y: 5, type: 1 });Careful: if the resulting message exceeds 71 characters, an exception is thrown.
Use on to listen for messages:
messenger.on('gotpup', function (event) {
var location = {
x: event.data.x,
y: event.data.y
};
var type = event.data.type;
var whoSawIt = event.player;
});Messages passed to the listener function are an object with the following properties:
name{string} the name of the event that occurred.player{integer} the id of the player that sent the message.data{*} the data associated with the event, ornullif no data was passed.
BotMessenger inherits from EventEmitter, so check out that documentation for additional methods and details (removeListener and once may be helpful). The only deviation is in the exception-handling case mentioned above.
Development
- Download the repository.
npm installto install development dependencies.npm install -g gulpif gulp is not installed.gulp watchfor build and quick rebuilds tobuild.gulp build-prodfor building final version todist.
