Custom Handlers
What are custom handlers
Section titled “What are 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.
When to use custom handlers
Section titled “When to use custom handlers”- React to incoming packets from the server
- Create autonomous behaviors (auto-zoning, combat responses) in conjunction with commands
Registering a custom handler
Section titled “Registering a custom handler”You probably want packetFromServer or pext (OnExtensionResponse).
packetFromServer: json, xmlpacketFromClient: strpext: 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);Unregistering a custom handler
Section titled “Unregistering a custom handler”cmd.unregister_handler(name);Example
Section titled “Example”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");