Hitbot - A Simple Bot for hitbox.io
Hitbot is a package to run a bot on the game "hitbox.io", the usage is simple, start creating a bot instance like the example below:
const hitbot = require("@wildyshadow/hitbot");
const bot = new hitbot({
name: "Hitbot", // Name of the bot!
skin: 375932, // Skin color!
token: "" // Optional!
});
To connect a bot, you first must follow the steps below:
1: Retrieve a address
First, retrieve a address, to do that you can either get one by link or by room name
-
Retrieving address by room name (listed rooms only)
bot.addr_from_name("Hitbot's Game").then(address => { console.log(address) // {"address":"59KRoj0tlKaT","server":"..."} });
-
Retrieving address by link (both listed and unlisted)
bot.addr_from_link("https://hitbox.io/510815skdje").then(address => { console.log(address) // {"address":"FLAos95K02","server":"..."} });
2: Connect the bot!
Once you've gotten the address, simply connect!
bot.connect(address);
The bot will join the room and have a fixed ping of 1500ms, but will not start doing any stuff yet.
3: Recieve packets
To start recieving packets, you must attach a function to a event listener, to do that simply:
bot.on("message",(data) => {
console.log(data); // A message packet is formed like this: [29,0,"hello world!"] where [1] is the player and [0] is the type.
})
Start responding to commands with:
bot.on('message',(data) => {
if (data[0] == 29){
if (data[2] == "!ping"){
let user = bot.findUser(data[1]);
bot.msg(`${user.name} > Pong!`)
}
}
});
Information about hitbox packets below https://github.com/wildyShadow/DemistifyHeav/blob/main/PACKETS.md
4 (Optional): Retrieve a token!
To get the bot an account and stop using guests, you can get a token using bot.setToken(username,password) once you have initialized one
bot.setToken("example","123").then(() => {
bot.addr_from_link("https://hitbox.io/900248").then(addr => {
bot.connect(addr);
// Connected with a account!
});
});