diff --git a/README.md b/README.md index 6ab77576..19090737 100644 --- a/README.md +++ b/README.md @@ -786,7 +786,55 @@ Grafana:
Default
false
- +
+ EnforceSquadLeaderKit +

EnforceSquadLeaderKit

+

The EnforceSquadLeaderKit plugin ensures that squad leaders select the correct Squad Leader kit. It will warn players who do not comply and disband their squad if they fail to switch after multiple warnings.

+ +

Options

+ + +

Behavior

+ + +

Example Configuration

+
{
+  "plugin": "EnforceSquadLeaderKit",
+  "enabled": true,
+  "warningMessage": "You must take the Squad Leader kit, or your squad will be disbanded!",
+  "checkInterval": 30,
+  "maxWarnings": 3
+}
+
FogOfWar

FogOfWar

diff --git a/config.json b/config.json index f07dbe29..5db721c9 100644 --- a/config.json +++ b/config.json @@ -211,6 +211,14 @@ "channelID": "", "color": 16761867, "disableCBL": false + }, + { + "plugin": "EnforceSquadLeaderKit", + "enabled": true, + "warningMessage": "You must take the Squad Leader kit, or your squad will be disbanded!", + "warningTimeout": 30, + "checkInterval": 30, + "maxWarnings": 10 }, { "plugin": "FogOfWar", diff --git a/squad-server/plugins/enforce-squad-leader-kit.js b/squad-server/plugins/enforce-squad-leader-kit.js new file mode 100644 index 00000000..e5e08484 --- /dev/null +++ b/squad-server/plugins/enforce-squad-leader-kit.js @@ -0,0 +1,70 @@ +import BasePlugin from './base-plugin.js'; + +export default class EnforceSquadLeaderKit extends BasePlugin { + static get description() { + return 'Ensures squad leaders take the correct Squad Leader kit, warns them if they do not, and disbands the squad if they fail to comply.'; + } + + static get defaultEnabled() { + return true; + } + + static get optionsSpecification() { + return { + warningMessage: { + required: false, + description: 'Warning message for squad leaders without the correct kit.', + default: 'You must take the Squad Leader kit, or your squad will be disbanded!' + }, + checkInterval: { + required: false, + description: 'Interval (in seconds) to check all squad leaders.', + default: 30 + }, + maxWarnings: { + required: false, + description: 'Number of warnings before disbanding the squad.', + default: 3 + } + }; + } + + constructor(server, options, connectors) { + super(server, options, connectors); + this.warningCounts = {}; + this.checkSquadLeaders = this.checkSquadLeaders.bind(this); + } + + async mount() { + this.checkInterval = setInterval(this.checkSquadLeaders, this.options.checkInterval * 1000); + } + + async unmount() { + clearInterval(this.checkInterval); + } + + async checkSquadLeaders() { + for (const player of this.server.players) { + if (player.isLeader) { + if (!player.role.includes('SL')) { + this.issueWarning(player); + } else if (this.warningCounts[player.steamID]) { + this.server.rcon.warn(player.steamID, "Thank you for taking the correct kit!"); + this.warningCounts[player.steamID] = 0; + } + } + } + } + + async issueWarning(player) { + const warnings = this.warningCounts[player.steamID] || 0; + this.warningCounts[player.steamID] = warnings + 1; + + this.server.rcon.warn(player.steamID, `${this.options.warningMessage} (${warnings + 1}/${this.options.maxWarnings})`); + + if (this.warningCounts[player.steamID] >= this.options.maxWarnings) { + this.server.rcon.execute(`AdminDisbandSquad ${player.teamID} ${player.squadID}`); + this.warningCounts[player.steamID] = 0; + } + } +}