A Node.js library for creating and controlling bots in Starblast.
To prevent bots from entering custom games, add the symbol 妛 in the game name.
Install the package with npm:
npm install starblast-botsconst { StarblastBot } = require("starblast-bots")
// The bot's information
const bot = new StarblastBot(
{
mode : "survival",
create : false,
name : "senko",
hue : 31,
spectate : false,
ecpKey : "00000-00000",
gameLink : "https://starblast.io/#1092@51.255.91.80:3017"
}
)
async function main()
{
// Make the bot join the game
try
{
await bot.spawnBot()
console.log("spawned")
}
catch(error)
{
console.log(error)
return
}
// Shoot while strafing left
bot.control(["shoot", "strafeLeft"], 0)
// Stop the inputs and look at an angle of 0 degrees
bot.control(["look"], 0)
// Leave the game
bot.leave()
}
main()A bot is created by passing an options object to StarblastBot:
const bot = new StarblastBot(
{
mode : "survival",
create : false,
name : "senko",
hue : 31,
spectate : false,
ecpKey : "00000-00000",
gameLink : "https://starblast.io/#1092@51.255.91.80:3017"
}
)| Option | Type | Description |
|---|---|---|
mode |
string |
The Starblast game mode. |
create |
boolean |
Whether the bot should create a game. |
name |
string |
The name displayed by the bot. |
hue |
number |
The bot's hue/color value. |
spectate |
boolean |
Whether the bot should spectate. |
ecpKey |
string |
ECP key used by the bot. |
ecp_custom |
any |
Custom ECP data used by the bot. |
gameLink |
string |
Link to the Starblast game the bot should join. |
team |
number |
Team used when entering a team game. |
Use spawnBot() to make the bot connect to the configured game.
await bot.spawnBot()Because spawnBot() is asynchronous, it should normally be used with await:
try
{
await bot.spawnBot()
console.log("Bot spawned successfully")
}
catch(error)
{
console.error(error)
}When the bot successfully enters the game, the spawned event is emitted.
bot.botEvent.on("spawned", () =>
{
console.log("Bot spawned")
})The control() method can be used to send controls to the bot.
bot.control(["shoot"], 0)Multiple inputs can be provided:
bot.control(["shoot", "strafeLeft"], 0)The second argument controls the bot's look angle.
| Control | Description |
|---|---|
look |
Look without using another input. |
thrust |
Move forward. |
shoot |
Shoot. |
glide |
Glide. |
strafeLeft |
Strafe left. |
strafeRight |
Strafe right. |
releaseCrystals |
Release crystals. |
Use respawn() to request a respawn:
bot.respawn()Use getName() with a player ID:
bot.getName(12)Use buyLife() to buy a life:
bot.buyLife()Start a transfer:
bot.startTransfer()End a transfer:
bot.endTransfer()Use toggleHealing() to toggle healing:
bot.toggleHealing()Use leave() to disconnect the bot from the game:
bot.leave()Events are available through bot.botEvent.
Emitted when the bot successfully enters the game.
bot.botEvent.on("spawned", () =>
{
console.log("Bot spawned")
})Emitted when the connection closes.
bot.botEvent.on("close", () =>
{
console.log("Connection closed")
})Emitted when the bot's ship is destroyed.
The bot's deaths counter is also increased.
bot.botEvent.on("dead", (data) =>
{
console.log("Bot died", data)
console.log("Deaths:", bot.deaths)
})Emitted when a ship status packet belongs to the bot.
bot.botEvent.on("bot-status", (data) =>
{
console.log(data)
})Emitted when a ship status packet belongs to another ship.
bot.botEvent.on("ship-status", (data) =>
{
console.log(data)
})Emitted when crystals spawn.
bot.botEvent.on("crystal-spawn", (data) =>
{
console.log(data)
})Emitted when another ship is destroyed.
bot.botEvent.on("ship-destroyed", (data) =>
{
console.log(data)
})Emitted when radar/scoreboard data is received.
bot.botEvent.on("radar-scoreboard", (data) =>
{
console.log(data)
})Emitted when station data is received.
bot.botEvent.on("station-update", (data) =>
{
console.log(data)
})Emitted for every message received from the server.
bot.botEvent.on("server-message", (data) =>
{
console.log(data)
})Emitted when a received server message contains valid JSON.
bot.botEvent.on("json-message", (data) =>
{
console.log(data)
})Emitted when the bot receives its game information.
bot.botEvent.on("game-info", (data) =>
{
console.log(data)
})The bot exposes several useful properties.
| Property | Description |
|---|---|
botId |
The ID of the bot's ship. |
deaths |
Number of times the bot has died. |
gameInfo |
Information about the current game. |
socket |
The WebSocket connection. |
botEvent |
Event emitter used by the bot. |
controls |
Available control values. |
Example:
console.log(bot.botId)
console.log(bot.deaths)
console.log(bot.gameInfo)const { StarblastBot } = require("starblast-bots")
const bot = new StarblastBot(
{
mode : "survival",
create : false,
name : "senko",
hue : 31,
spectate : false,
ecpKey : "00000-00000",
gameLink : "https://starblast.io/#1092@51.255.91.80:3017"
}
)
async function main()
{
// Make the bot join the game
try
{
await bot.spawnBot()
console.log("spawned")
}
catch(error)
{
console.error(error)
return
}
// Handle bot death
bot.botEvent.on("dead", (data) =>
{
console.log("bot dead", data)
// Leave the game after 3 deaths
if(bot.deaths >= 3)
{
bot.leave()
return
}
// Respawn the bot
bot.respawn()
})
// Shoot while strafing left
bot.control(["shoot", "strafeLeft"], 0)
}
main()A minimal project can look like this:
my-starblast-bot/
├── node_modules/
├── package.json
├── package-lock.json
└── index.js
Install the package:
npm install starblast-botsThen put your bot code in index.js and run:
node index.jsCreates a new Starblast bot.
const bot = new StarblastBot(options)Connects the bot to the configured Starblast game.
await bot.spawnBot()Controls the bot.
bot.control(["shoot"], 0)Multiple controls can be provided:
bot.control(["shoot", "strafeLeft"], 0)Requests a respawn.
bot.respawn()Requests the name of a player.
bot.getName(12)Buys a life.
bot.buyLife()Starts a transfer.
bot.startTransfer()Ends a transfer.
bot.endTransfer()Toggles healing.
bot.toggleHealing()Disconnects the bot from the game.
bot.leave()- Node.js
- npm
- A valid Starblast game link
- An ECP key if required by the game/bot configuration