updateNextMap

This commit is contained in:
Davide Fantino 2022-10-04 19:48:38 +02:00
parent 12607a3d2e
commit c8370673d5

View File

@ -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