From c8370673d59b5d50f14722ae76f768e422fccdf3 Mon Sep 17 00:00:00 2001 From: Davide Fantino <80767709+fantinodavide@users.noreply.github.com> Date: Tue, 4 Oct 2022 19:48:38 +0200 Subject: [PATCH] updateNextMap --- mapvote.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mapvote.js b/mapvote.js index 36b3761..751496a 100644 --- a/mapvote.js +++ b/mapvote.js @@ -396,9 +396,11 @@ export default class MapVote extends DiscordBasePlugin { } if (!skipSetNextMap) { const nextMap = randomElement(cpyWinners); - const baseDataExist = this && this.options && this.server && this.server.players && this.server.nextLayer && this.server.nextLayer.layerid; - if (!baseDataExist || this.server.nextLayer.layerid != nextMap) + const baseDataExist = this && this.server; + const layerDataExist = this.server.nextLayer && this.server.nextLayer.layerid; + if (baseDataExist && (!layerDataExist || this.server.nextLayer.layerid != nextMap)) this.server.rcon.execute(`AdminSetNextLayer ${nextMap}`); + else console.log("[MapVote][1] Bad data (this/this.server). Next layer not set to prevent errors."); } } @@ -468,7 +470,7 @@ export default class MapVote extends DiscordBasePlugin { ); for (let i = 1; i <= maxOptions; i++) { let l, maxtries = 10; - do l = randomElement(all_layers); while ((rnd_layers.find(lf => lf.layerid == l.layerid) || rnd_layers.filter(lf => lf.map.name == l.map.name).length > (this.options.allowedSameMapEntries-1)) && --maxtries >= 0) + do l = randomElement(all_layers); while ((rnd_layers.find(lf => lf.layerid == l.layerid) || rnd_layers.filter(lf => lf.map.name == l.map.name).length > (this.options.allowedSameMapEntries - 1)) && --maxtries >= 0) if (maxtries > 0) { rnd_layers.push(l); this.nominations[ i ] = l.layerid @@ -493,7 +495,7 @@ export default class MapVote extends DiscordBasePlugin { const cls = cl.split('_'); const fLayers = sanitizedLayers.filter((l) => ((cls[ 0 ] == "*" || l.layerid.toLowerCase().startsWith(cls[ 0 ])) && (l.gamemode.toLowerCase().startsWith(cls[ 1 ]) || (!cls[ 1 ] && [ 'RAAS', 'AAS', 'INVASION' ].includes(l.gamemode.toUpperCase()))) && (!cls[ 2 ] || l.version.toLowerCase().startsWith("v" + cls[ 2 ].replace(/v/gi, ''))))); let l, maxtries = 10; - do l = randomElement(fLayers); while ((rnd_layers.filter(lf => lf.map.name == l.map.name).length > (this.options.allowedSameMapEntries-1)) && --maxtries >= 0) + do l = randomElement(fLayers); while ((rnd_layers.filter(lf => lf.map.name == l.map.name).length > (this.options.allowedSameMapEntries - 1)) && --maxtries >= 0) if (l) { rnd_layers.push(l); this.nominations[ i ] = l.layerid