Skip to content

Custom Handlers

Custom handlers let you create automatic responses to some network message. Unlike regular commands that run one after another, handlers work in the background and can trigger at any time.

  • React to incoming packets from the server
  • Create autonomous behaviors (auto-zoning, combat responses) in conjunction with commands

You probably want packetFromServer or pext (OnExtensionResponse).

  • packetFromServer: json, xml
  • packetFromClient: str
  • pext: json, xml, str (?)

Handlers are invoked asychronously as soon as the packet is received.

// Register a handler with:
// cmd.register_handler(type, name, handlerFunction)
//
// Where:
// - type: "packetFromServer", "packetFromClient", or "pext"
// - name: unique identifier for your handler
// - handlerFunction: receives packet data and has bot instance bound
cmd.register_handler(type, name, handlerFunction);
cmd.unregister_handler(name);
cmd.register_handler("pext", "auto zone ledgermayne", async function (packet) {
if (packet.params.type == "json") {
if (packet.params.dataObj.cmd === "event") {
const zone = packet.params.dataObj.args.zoneSet;
this.bot.settings.disableCollisions = true;
let x;
let y;
switch (zone) {
case "A": // left
x = 196;
y = 355;
break;
case "B": // right
x = 869;
y = 354;
break;
default: // center
x = 501;
y = 243;
}
this.bot.player.walkTo(x, y);
await this.bot.waitUntil(
() => {
let [x_, y_] = this.bot.player.position;
if (x != x_ && y != y_) return false;
return true;
},
null,
-1,
);
this.bot.settings.disableCollisions = false;
}
}
});
cmd.enable_infiniterange();
cmd.join("ledgermayne", "Boss");
cmd.kill("*");
cmd.log("dead");
cmd.unregister_handler("auto zone ledgermayne");