mirror of
https://github.com/AsgardEternal/squad-js-map-vote.git
synced 2025-01-23 20:43:52 -06:00
fixed mapvote
This commit is contained in:
parent
cc0a391b24
commit
c3b4193a2a
45
mapvote.js
45
mapvote.js
@ -101,14 +101,15 @@ export default class MapVote extends BasePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onNewGame() {
|
async onNewGame() {
|
||||||
//wait to start voting
|
setTimeout(async () => {
|
||||||
this.endVoting();
|
this.endVoting();
|
||||||
this.trackedVotes = {};
|
this.trackedVotes = {};
|
||||||
this.tallies = [];
|
this.tallies = [];
|
||||||
this.nominations = [];
|
this.nominations = [];
|
||||||
this.factionStrings = [];
|
this.factionStrings = [];
|
||||||
setTimeout(this.beginVoting, toMils(this.options.voteWaitTimeFromMatchStart));
|
setTimeout(this.beginVoting, toMils(this.options.voteWaitTimeFromMatchStart));
|
||||||
setTimeout(this.setSeedingMode, 30000);
|
setTimeout(() => { this.setSeedingMode() }, 20000);
|
||||||
|
}, 10000)
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPlayerDisconnected() {
|
async onPlayerDisconnected() {
|
||||||
@ -116,14 +117,15 @@ export default class MapVote extends BasePlugin {
|
|||||||
await this.server.updatePlayerList();
|
await this.server.updatePlayerList();
|
||||||
this.clearVote();
|
this.clearVote();
|
||||||
this.updateNextMap();
|
this.updateNextMap();
|
||||||
this.setSeedingMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSeedingMode() {
|
setSeedingMode() {
|
||||||
|
// setTimeout(()=>{this.msgDirect('76561198419229279',"MV\ntest\ntest")},1000)
|
||||||
|
// this.msgBroadcast("[MapVote] Seeding mode active")
|
||||||
if (this.options.automaticSeedingMode && (this.server.nextLayer.gamemode.toLowerCase() != "seed" || this.server.currentLayer.layerid == this.server.nextLayer.layerid)) {
|
if (this.options.automaticSeedingMode && (this.server.nextLayer.gamemode.toLowerCase() != "seed" || this.server.currentLayer.layerid == this.server.nextLayer.layerid)) {
|
||||||
const mapBlacklist = [ "BlackCoast" ];
|
const mapBlacklist = [ "BlackCoast" ];
|
||||||
const seedingMaps = Layers.layers.filter((l) => l.gamemode.toUpperCase() == "SEED" && !mapBlacklist.includes(l.classname) && l.layerid != this.server.currentLayer.layerid)
|
const seedingMaps = Layers.layers.filter((l) => l.gamemode.toUpperCase() == "SEED" && !mapBlacklist.includes(l.classname) && l.layerid != this.server.currentLayer.layerid)
|
||||||
|
|
||||||
const nextMap = randomElement(seedingMaps).layerid;
|
const nextMap = randomElement(seedingMaps).layerid;
|
||||||
if (this.server.players && this.server.players.length < 20) {
|
if (this.server.players && this.server.players.length < 20) {
|
||||||
this.verbose(1, 'Going into seeding mode.');
|
this.verbose(1, 'Going into seeding mode.');
|
||||||
@ -159,12 +161,6 @@ export default class MapVote extends BasePlugin {
|
|||||||
switch (subCommand) // select the sub command
|
switch (subCommand) // select the sub command
|
||||||
{
|
{
|
||||||
case "choices": //sends choices to player in the from of a warning
|
case "choices": //sends choices to player in the from of a warning
|
||||||
if (!this.votingEnabled) {
|
|
||||||
await this.msgDirect(steamID, "There is no vote running right now");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.directMsgNominations(steamID);
|
|
||||||
return;
|
|
||||||
case "results": //sends player the results in a warning
|
case "results": //sends player the results in a warning
|
||||||
if (!this.votingEnabled) {
|
if (!this.votingEnabled) {
|
||||||
await this.msgDirect(steamID, "There is no vote running right now");
|
await this.msgDirect(steamID, "There is no vote running right now");
|
||||||
@ -273,7 +269,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
this.factionStrings = [];
|
this.factionStrings = [];
|
||||||
let rnd_layers = [];
|
let rnd_layers = [];
|
||||||
// let rnd_layers = [];
|
// let rnd_layers = [];
|
||||||
if (cmdLayers.length == 0) {
|
if (!cmdLayers || cmdLayers.length == 0) {
|
||||||
const all_layers = Layers.layers.filter((l) => [ 'RAAS', 'AAS', 'INVASION' ].includes(l.gamemode.toUpperCase()));
|
const all_layers = Layers.layers.filter((l) => [ 'RAAS', 'AAS', 'INVASION' ].includes(l.gamemode.toUpperCase()));
|
||||||
for (let i = 0; i < 6; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
// rnd_layers.push(all_layers[Math.floor(Math.random()*all_layers.length)]);
|
// rnd_layers.push(all_layers[Math.floor(Math.random()*all_layers.length)]);
|
||||||
@ -286,7 +282,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
}
|
}
|
||||||
if (!bypassRaasFilter && rnd_layers.filter((l) => l.gamemode === 'RAAS').length < 3) this.populateNominations();
|
if (!bypassRaasFilter && rnd_layers.filter((l) => l.gamemode === 'RAAS').length < 3) this.populateNominations();
|
||||||
} else {
|
} else {
|
||||||
if (cmdLayers.length == 1 && cmdLayers[0].split('_')[0]=="*") for (let i = 0; i < 5; i++) cmdLayers.push(cmdLayers[ 0 ])
|
if (cmdLayers.length == 1 && cmdLayers[ 0 ].split('_')[ 0 ] == "*") for (let i = 0; i < 5; i++) cmdLayers.push(cmdLayers[ 0 ])
|
||||||
if (cmdLayers.length <= 6)
|
if (cmdLayers.length <= 6)
|
||||||
for (let cl of cmdLayers) {
|
for (let cl of cmdLayers) {
|
||||||
const cls = cl.split('_');
|
const cls = cl.split('_');
|
||||||
@ -315,6 +311,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
//checks if there are enough players to start voting, if not binds itself to player connected
|
//checks if there are enough players to start voting, if not binds itself to player connected
|
||||||
//when there are enough players it clears old votes, sets up new nominations, and starts broadcast
|
//when there are enough players it clears old votes, sets up new nominations, and starts broadcast
|
||||||
beginVoting(force = false, steamid = null, cmdLayers = null) {
|
beginVoting(force = false, steamid = null, cmdLayers = null) {
|
||||||
|
this.verbose(1, "Starting vote")
|
||||||
const playerCount = this.server.players.length;
|
const playerCount = this.server.players.length;
|
||||||
const minPlayers = this.options.minPlayersForVote;
|
const minPlayers = this.options.minPlayersForVote;
|
||||||
|
|
||||||
@ -355,7 +352,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
//NOTE: max squad broadcast message length appears to be 485 characters
|
//NOTE: max squad broadcast message length appears to be 485 characters
|
||||||
//Note: broadcast strings with multi lines are very strange
|
//Note: broadcast strings with multi lines are very strange
|
||||||
async broadcastNominations() {
|
async broadcastNominations() {
|
||||||
if (this.nominations.length > 0) {
|
if (this.nominations.length > 0 && this.votingEnabled) {
|
||||||
await this.msgBroadcast("✯ MAPVOTE ✯ Vote for the next map by writing in chat the corresponding number!\n");
|
await this.msgBroadcast("✯ MAPVOTE ✯ Vote for the next map by writing in chat the corresponding number!\n");
|
||||||
let nominationStrings = [];
|
let nominationStrings = [];
|
||||||
for (let choice in this.nominations) {
|
for (let choice in this.nominations) {
|
||||||
@ -371,13 +368,17 @@ export default class MapVote extends BasePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async directMsgNominations(steamID) {
|
async directMsgNominations(steamID) {
|
||||||
|
let strMsg = "";
|
||||||
for (let choice in this.nominations) {
|
for (let choice in this.nominations) {
|
||||||
choice = Number(choice);
|
choice = Number(choice);
|
||||||
await this.msgDirect(steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ]));
|
// await this.msgDirect(steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ]));
|
||||||
|
strMsg += (steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])) + "\n";
|
||||||
}
|
}
|
||||||
|
strMsg.trim();
|
||||||
|
this.msgDirect(steamID, strMsg)
|
||||||
|
|
||||||
const winners = this.currentWinners;
|
// const winners = this.currentWinners;
|
||||||
await this.msgDirect(steamID, `Current winner${winners.length > 1 ? "s" : ""}: ${winners.join(", ")}`);
|
// await this.msgDirect(steamID, `Current winner${winners.length > 1 ? "s" : ""}: ${winners.join(", ")}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//counts a vote from a player and adds it to tallies
|
//counts a vote from a player and adds it to tallies
|
||||||
|
Loading…
x
Reference in New Issue
Block a user