mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 11:54:23 -05:00
TeamRandomizer plugin
This commit is contained in:
parent
d9e3d2b041
commit
cfbebb4ad4
40
README.md
40
README.md
@ -510,34 +510,6 @@ The following is a list of plugins built into SquadJS, you can click their title
|
||||
<pre><code>667741905228136459</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>DiscordTeamkill</summary>
|
||||
<h2>DiscordTeamkill</h2>
|
||||
<p>The <code>DiscordTeamkill</code> plugin logs teamkills and related information to a Discord channel for admins to review.</p>
|
||||
<h3>Options</h3>
|
||||
<h4>discordClient (Required)</h4>
|
||||
<h6>Description</h6>
|
||||
<p>Discord connector name.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>discord</code></pre>
|
||||
<h4>channelID (Required)</h4>
|
||||
<h6>Description</h6>
|
||||
<p>The ID of the channel to log teamkills to.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code></code></pre><h6>Example</h6>
|
||||
<pre><code>667741905228136459</code></pre>
|
||||
<h4>color</h4>
|
||||
<h6>Description</h6>
|
||||
<p>The color of the embeds.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>16761867</code></pre>
|
||||
<h4>disableSCBL</h4>
|
||||
<h6>Description</h6>
|
||||
<p>Disable Squad Community Ban List information.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>false</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>IntervalledBroadcasts</summary>
|
||||
<h2>IntervalledBroadcasts</h2>
|
||||
@ -594,6 +566,18 @@ The following is a list of plugins built into SquadJS, you can click their title
|
||||
<h6>Default</h6>
|
||||
<pre><code>Live!</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>TeamRandomizer</summary>
|
||||
<h2>TeamRandomizer</h2>
|
||||
<p>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</p>
|
||||
<h3>Options</h3>
|
||||
<h4>command</h4>
|
||||
<h6>Description</h6>
|
||||
<p>The command used to randomize the teams.</p>
|
||||
<h6>Default</h6>
|
||||
<pre><code>randomize</code></pre>
|
||||
</details>
|
||||
|
||||
## Creating Your Own Plugins
|
||||
To create your own plugin you need a basic knowledge of JavaScript.
|
||||
|
13
config.json
13
config.json
@ -157,14 +157,6 @@
|
||||
"discordClient": "discord",
|
||||
"role": ""
|
||||
},
|
||||
{
|
||||
"plugin": "DiscordTeamkill",
|
||||
"enabled": true,
|
||||
"discordClient": "discord",
|
||||
"channelID": "",
|
||||
"color": 16761867,
|
||||
"disableSCBL": false
|
||||
},
|
||||
{
|
||||
"plugin": "IntervalledBroadcasts",
|
||||
"enabled": false,
|
||||
@ -180,6 +172,11 @@
|
||||
"liveEnabled": true,
|
||||
"liveThreshold": 52,
|
||||
"liveMessage": "Live!"
|
||||
},
|
||||
{
|
||||
"plugin": "TeamRandomizer",
|
||||
"enabled": true,
|
||||
"command": "randomize"
|
||||
}
|
||||
]
|
||||
}
|
8
index.js
8
index.js
@ -6,13 +6,13 @@ printLogo();
|
||||
const config = process.env.config;
|
||||
const configPath = process.argv[2];
|
||||
|
||||
if(config && configPath) throw new Error('Cannot accept both a config and config path.');
|
||||
if (config && configPath) throw new Error('Cannot accept both a config and config path.');
|
||||
|
||||
let server;
|
||||
if(config) {
|
||||
server = SquadServer.buildFromConfigString(config);
|
||||
if (config) {
|
||||
server = SquadServer.buildFromConfigString(config);
|
||||
} else {
|
||||
server = SquadServer.buildFromConfigFile(configPath || './config.json');
|
||||
}
|
||||
|
||||
server.then(server => server.watch());
|
||||
server.then((server) => server.watch());
|
||||
|
@ -288,4 +288,8 @@ export default class Rcon extends EventEmiiter {
|
||||
async warn(steamID, message) {
|
||||
await this.execute(`AdminWarn "${steamID}" ${message}`);
|
||||
}
|
||||
|
||||
async switchTeam(steamID) {
|
||||
await this.execute(`AdminForceTeamChange "${steamID}"`);
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,10 @@ export default class SquadServer extends EventEmitter {
|
||||
data.victim = await this.getPlayerByName(data.victimName);
|
||||
data.attacker = await this.getPlayerByName(data.attackerName);
|
||||
|
||||
if (data.victim && data.attacker) data.teamkill = data.victim.teamID === data.attacker.teamID && data.victim.steamID !== data.attacker.steamID;
|
||||
if (data.victim && data.attacker)
|
||||
data.teamkill =
|
||||
data.victim.teamID === data.attacker.teamID &&
|
||||
data.victim.steamID !== data.attacker.steamID;
|
||||
|
||||
delete data.victimName;
|
||||
delete data.attackerName;
|
||||
@ -143,7 +146,10 @@ export default class SquadServer extends EventEmitter {
|
||||
data.victim = await this.getPlayerByName(data.victimName);
|
||||
data.attacker = await this.getPlayerByName(data.attackerName);
|
||||
|
||||
if (data.victim && data.attacker) data.teamkill = data.victim.teamID === data.attacker.teamID && data.victim.steamID !== data.attacker.steamID;
|
||||
if (data.victim && data.attacker)
|
||||
data.teamkill =
|
||||
data.victim.teamID === data.attacker.teamID &&
|
||||
data.victim.steamID !== data.attacker.steamID;
|
||||
|
||||
delete data.victimName;
|
||||
delete data.attackerName;
|
||||
@ -156,7 +162,10 @@ export default class SquadServer extends EventEmitter {
|
||||
data.victim = await this.getPlayerByName(data.victimName);
|
||||
data.attacker = await this.getPlayerByName(data.attackerName);
|
||||
|
||||
if (data.victim && data.attacker) data.teamkill = data.victim.teamID === data.attacker.teamID && data.victim.steamID !== data.attacker.steamID;
|
||||
if (data.victim && data.attacker)
|
||||
data.teamkill =
|
||||
data.victim.teamID === data.attacker.teamID &&
|
||||
data.victim.steamID !== data.attacker.steamID;
|
||||
|
||||
delete data.victimName;
|
||||
delete data.attackerName;
|
||||
|
@ -56,7 +56,12 @@ export default class DiscordServerStatus extends BasePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
await options.discordClient.user.setActivity(`(${server.a2sPlayerCount}/${server.publicSlots}) ${server.layerHistory[0].layer || 'Unknown'}`, { type: 'WATCHING' });
|
||||
await options.discordClient.user.setActivity(
|
||||
`(${server.a2sPlayerCount}/${server.publicSlots}) ${
|
||||
server.layerHistory[0].layer || 'Unknown'
|
||||
}`,
|
||||
{ type: 'WATCHING' }
|
||||
);
|
||||
}, options.updateInterval);
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,10 @@ import DiscordBasePlugin from './discord-base-plugin.js';
|
||||
|
||||
export default class DiscordTeamkill extends DiscordBasePlugin {
|
||||
static get description() {
|
||||
return 'The <code>DiscordTeamkill</code> plugin logs teamkills and related information to a Discord channel for ' +
|
||||
'admins to review.';
|
||||
return (
|
||||
'The <code>DiscordTeamkill</code> plugin logs teamkills and related information to a Discord channel for ' +
|
||||
'admins to review.'
|
||||
);
|
||||
}
|
||||
|
||||
static get defaultEnabled() {
|
||||
|
@ -10,9 +10,9 @@ import DiscordRcon from './discord-rcon.js';
|
||||
import DiscordRoundWinner from './discord-round-winner.js';
|
||||
import DiscordServerStatus from './discord-server-status.js';
|
||||
import DiscordSubsystemRestarter from './discord-subsystem-restarter.js';
|
||||
import DiscordTeamkill from './discord-teamkill.js';
|
||||
import IntervalledBroadcasts from './intervalled-broadcasts.js';
|
||||
import SeedingMode from './seeding-mode.js';
|
||||
import TeamRandomizer from './team-randomizer.js';
|
||||
|
||||
const plugins = [
|
||||
AutoTKWarn,
|
||||
@ -27,9 +27,9 @@ const plugins = [
|
||||
DiscordRoundWinner,
|
||||
DiscordServerStatus,
|
||||
DiscordSubsystemRestarter,
|
||||
DiscordTeamkill,
|
||||
IntervalledBroadcasts,
|
||||
SeedingMode
|
||||
SeedingMode,
|
||||
TeamRandomizer
|
||||
];
|
||||
|
||||
const pluginsByName = {};
|
||||
|
55
squad-server/plugins/team-randomizer.js
Normal file
55
squad-server/plugins/team-randomizer.js
Normal file
@ -0,0 +1,55 @@
|
||||
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';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user