From d650c7f18a221a0c47cb6263d71a45c1cd400ce1 Mon Sep 17 00:00:00 2001 From: Fantino Davide Date: Thu, 15 Sep 2022 13:20:09 +0200 Subject: [PATCH] separated currentLayer and nextLayer --- mapvote.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mapvote.js b/mapvote.js index e14fd1e..34a8760 100644 --- a/mapvote.js +++ b/mapvote.js @@ -146,6 +146,7 @@ export default class MapVote extends BasePlugin { if (this.options.automaticSeedingMode) { if (this.server.players.length >= 1 && this.server.players.length < 40) { const seedingMaps = Layers.layers.filter((l) => l.layerid && l.gamemode.toUpperCase() == "SEED" && !this.options.layerLevelBlacklist.find((fl) => l.layerid.toLowerCase().startsWith(fl.toLowerCase()))) + if (this.server.currentLayer) { const rndMap = randomElement(seedingMaps); if (this.server.currentLayer.gamemode.toLowerCase() != "seed") { @@ -154,22 +155,22 @@ export default class MapVote extends BasePlugin { this.verbose(1, 'Going into seeding mode.'); this.server.rcon.execute(`AdminChangeLayer ${newCurrentMap}`); } - - if (this.server.nextLayer) { - const nextMaps = seedingMaps.filter((l) => l.layerid != this.server.currentLayer.layerid) - let rndMap2; - do rndMap2 = randomElement(nextMaps); - while (rndMap2.layerid == rndMap.layerid) - - if (isNewGameEvent && this.server.players.length < 20 && this.server.nextLayer.gamemode.toLowerCase() != "seed") { - const newNextMap = rndMap2.layerid; - this.server.rcon.execute(`AdminSetNextLayer ${newNextMap}`); - } - } else this.verbose(1, "Bad data (nextLayer). Seeding mode for next layer skipped to prevent errors."); } - } else this.verbose(1, "Bad data (currentLayer). Seeding mode skipped to prevent errors."); + } else this.verbose(1, "Bad data (currentLayer). Seeding mode for current layer skipped to prevent errors."); + + if (this.server.nextLayer) { + const nextMaps = seedingMaps.filter((l) => (!this.server.currentLayer || l.layerid != this.server.currentLayer.layerid)) + let rndMap2; + do rndMap2 = randomElement(nextMaps); + while (rndMap2.layerid == rndMap.layerid) - } else this.verbose(1, "Player count doesn't allow seeding mode"); + if (isNewGameEvent && this.server.players.length < 20 && this.server.nextLayer.gamemode.toLowerCase() != "seed") { + const newNextMap = rndMap2.layerid; + this.server.rcon.execute(`AdminSetNextLayer ${newNextMap}`); + } + } else this.verbose(1, "Bad data (nextLayer). Seeding mode for next layer skipped to prevent errors."); + + } else this.verbose(1, `Player count doesn't allow seeding mode (${this.server.players.length}/20)`); } else this.verbose(1, "Seeding mode disabled in config"); } else console.log("[MapVote][1] Bad data (this/this.server/this.options). Seeding mode skipped to prevent errors."); }