mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 23:24:26 -05:00
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
|
import BasePlugin from './base-plugin.js';
|
||
|
|
||
|
export default class TeamRandomizer extends BasePlugin {
|
||
|
static get description() {
|
||
|
return (
|
||
|
"The <code>TeamRandomizer</code> can be used to randomize teams. It's great for destroying clan stacks or for " +
|
||
|
'social events. It can be run by typing, by default, <code>!randomize</code> into in-game admin chat'
|
||
|
);
|
||
|
}
|
||
|
|
||
|
static get defaultEnabled() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
static get optionsSpecification() {
|
||
|
return {
|
||
|
command: {
|
||
|
required: false,
|
||
|
description: 'The command used to randomize the teams.',
|
||
|
default: 'randomize'
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
constructor(server, options) {
|
||
|
super();
|
||
|
|
||
|
server.on(`CHAT_COMMAND:${options.command}`, async (info) => {
|
||
|
if (info.chat !== 'ChatAdmin') return;
|
||
|
|
||
|
const players = server.players.slice(0);
|
||
|
|
||
|
let currentIndex = players.length;
|
||
|
let temporaryValue;
|
||
|
let randomIndex;
|
||
|
|
||
|
while (currentIndex !== 0) {
|
||
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
||
|
currentIndex -= 1;
|
||
|
|
||
|
temporaryValue = players[currentIndex];
|
||
|
players[currentIndex] = players[randomIndex];
|
||
|
players[randomIndex] = temporaryValue;
|
||
|
}
|
||
|
|
||
|
let team = '1';
|
||
|
|
||
|
for (const player of players) {
|
||
|
if (player.teamID !== team) await server.rcon.switchTeam(player.steamID);
|
||
|
|
||
|
team = team === '1' ? '2' : '1';
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|