Library
Teams and lock
Team numbering, moving players and locking teams with lockTeams().
Team numbering
| Number | Team | Constant |
|---|---|---|
0 | Spectator | TEAM_SPEC |
1 | FFA (free for all) | TEAM_FFA |
2 | Red | TEAM_RED |
3 | Blue | TEAM_BLUE |
4 | Green | TEAM_GREEN |
5 | Yellow | TEAM_YELLOW |
ts
import { TEAM_BLUE, TEAM_SPEC } from 'bonktools';
room.setTeam(playerId, TEAM_BLUE);
room.setTeam(playerId, TEAM_SPEC);Moving players
The host moves any player with setTeam(id, team). The bot moves itself with joinTeam(team).
ts
room.on('player-join', (p) => {
// sends every newcomer to spectators
room.setTeam(p.id, TEAM_SPEC);
});Locking the teams
ts
room.lockTeams(); // players can no longer switch teams or leave to spectate
room.unlockTeams(); // unlocks again
room.state.teamsLocked; // current stateWith the teams locked, only the host moves players: room.setTeam(id, team) keeps working normally. This prevents someone from joining a team on their own and unbalancing the match.
How it works
- Only the host can lock. Called by a client that isn't the host,
lockTeams()is ignored and logs a warning. - Local state.
room.state.teamsLockedis updated when locking and also when the server reports it (teamlock-toggle). - Late joiners already receive the room locked.
- Room rebuild. If the room goes down and is recreated, the lock is reapplied automatically (unless you called
unlockTeams()before). - No bursts. Calling
lockTeams()several times sends the packet only once. If the server refuses because of too many requests (rate_limit_tl), the library undoes the local state and retries after 1.5 s.
setTeamLock(boolean) is still available; lockTeams() and unlockTeams() are shortcuts.
Team mode
room.setTeamsEnabled(true) turns team mode on. Without it, everyone plays FFA. In football, always use teams.