Haxball | Script
The most popular use of scripts is competitive ranking. Rooms using scripts like Swiss Ladder or HB Ladder calculate Elo ratings for every player.
Major Haxball leagues do not use default rooms. They use scripts that:
let redScore = 0, blueScore = 0;room.onTeamGoal = function(team) if (team === 1) redScore++; if (team === 2) blueScore++;
room.sendChat(
⚽ GOAL! Score: $redScore - $blueScore); Script Haxball
// Reset ball position after goal setTimeout(() => room.setBallPosition(500, 400); , 2000); ;
Word Count: ~1,850
Let's write a simple script that announces "GOAL!" in the chat and gives the scorer +10 points.
// simpleGoalScript.jsfunction init(room) { // Listen for the goal event room.onGoal = (goalData) => { const scorerName = goalData.scorer.name; const scorerId = goalData.scorer.id;
// Send a chat message room.sendChat(`⚽ GOAL! $scorerName scores! ⚽`); // Award 10 points to the scorer (custom stat) if (!room.playerStats) room.playerStats = {}; if (!room.playerStats[scorerId]) room.playerStats[scorerId] = 0; room.playerStats[scorerId] += 10; // Announce the total points room.sendChat(`$scorerName now has $room.playerStats[scorerId] points.`); }; // Optional: Display points when a player leaves room.onPlayerLeave = (player) => if (room.playerStats && room.playerStats[player.id]) console.log(`$player.name left with $room.playerStats[player.id] points.`); ; console.log("Simple goal script loaded!");}
module.exports = init ;
To use: Save as simpleGoalScript.js, require it in your main script, and restart the room. The most popular use of scripts is competitive ranking
This is a minimal example, but it demonstrates the core pattern: listen for game events → execute custom logic → send commands back to the room.