mirror of
https://github.com/AsgardEternal/squad-js-map-vote.git
synced 2025-01-23 23:03:51 -06:00
removed unnecessary code, config options for seeding mode, * in map name filter
This commit is contained in:
parent
0721661af3
commit
53ed42f803
63
mapvote.js
63
mapvote.js
@ -35,29 +35,29 @@ export default class MapVote extends BasePlugin {
|
|||||||
description: "command name to use in chat",
|
description: "command name to use in chat",
|
||||||
default: "!vote"
|
default: "!vote"
|
||||||
},
|
},
|
||||||
voteRulesPath:
|
|
||||||
{
|
|
||||||
required: false,
|
|
||||||
description: 'the path to the layersConfig file',
|
|
||||||
default: ''
|
|
||||||
},
|
|
||||||
minPlayersForVote:
|
minPlayersForVote:
|
||||||
{
|
{
|
||||||
required: false,
|
required: false,
|
||||||
description: 'number of players needed on the server for a vote to start',
|
description: 'number of players needed on the server for a vote to start',
|
||||||
default: 50
|
default: 40
|
||||||
},
|
},
|
||||||
voteWaitTimeFromMatchStart:
|
voteWaitTimeFromMatchStart:
|
||||||
{
|
{
|
||||||
required: false,
|
required: false,
|
||||||
description: 'time in mils from the start of a round to the start of a new map vote',
|
description: 'time in mins from the start of a round to the start of a new map vote',
|
||||||
default: 20
|
default: 15
|
||||||
},
|
},
|
||||||
voteBroadcastInterval:
|
voteBroadcastInterval:
|
||||||
{
|
{
|
||||||
required: false,
|
required: false,
|
||||||
description: 'broadcast interval for vote notification in mils',
|
description: 'broadcast interval for vote notification in mins',
|
||||||
default: 15
|
default: 7
|
||||||
|
},
|
||||||
|
automaticSeedingMode:
|
||||||
|
{
|
||||||
|
required: false,
|
||||||
|
description: 'set a seeding layer if server has less than 20 players',
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -82,9 +82,6 @@ export default class MapVote extends BasePlugin {
|
|||||||
|
|
||||||
this.msgBroadcast = (msg) => { this.server.rcon.broadcast(msg); };
|
this.msgBroadcast = (msg) => { this.server.rcon.broadcast(msg); };
|
||||||
this.msgDirect = (steamid, msg) => { this.server.rcon.warn(steamid, msg); };
|
this.msgDirect = (steamid, msg) => { this.server.rcon.warn(steamid, msg); };
|
||||||
|
|
||||||
//load voteRules with options from source file
|
|
||||||
this.loadLayersConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async mount() {
|
async mount() {
|
||||||
@ -92,6 +89,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
this.server.on('CHAT_MESSAGE', this.onChatMessage);
|
this.server.on('CHAT_MESSAGE', this.onChatMessage);
|
||||||
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
|
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
|
||||||
this.verbose(1, 'Map vote was mounted.');
|
this.verbose(1, 'Map vote was mounted.');
|
||||||
|
this.setSeedingMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
async unmount() {
|
async unmount() {
|
||||||
@ -102,23 +100,6 @@ export default class MapVote extends BasePlugin {
|
|||||||
this.verbose(1, 'Map vote was un-mounted.');
|
this.verbose(1, 'Map vote was un-mounted.');
|
||||||
}
|
}
|
||||||
|
|
||||||
//loads layer configs from disk into plugin memory
|
|
||||||
loadLayersConfig() {
|
|
||||||
this.verbose(1, `Fetching Map Voting Lists...`);
|
|
||||||
|
|
||||||
let layersConfigString = '';
|
|
||||||
try {
|
|
||||||
if (!fs.existsSync(this.options.voteRulesPath))
|
|
||||||
throw new Error(`Could not find Map Vote List at ${this.options.voteRulesPath}`);
|
|
||||||
layersConfigString = fs.readFileSync(this.options.voteRulesPath, 'utf8');
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
this.verbose('SquadServer', 1, `Error fetching mapvoting list: ${options.voteRulesPath}`, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.voteRules = JSON.parse(layersConfigString);
|
|
||||||
}
|
|
||||||
|
|
||||||
async onNewGame() {
|
async onNewGame() {
|
||||||
//wait to start voting
|
//wait to start voting
|
||||||
this.endVoting();
|
this.endVoting();
|
||||||
@ -127,6 +108,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
this.nominations = [];
|
this.nominations = [];
|
||||||
this.factionStrings = [];
|
this.factionStrings = [];
|
||||||
setTimeout(this.beginVoting, toMils(this.options.voteWaitTimeFromMatchStart));
|
setTimeout(this.beginVoting, toMils(this.options.voteWaitTimeFromMatchStart));
|
||||||
|
this.setSeedingMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPlayerDisconnected() {
|
async onPlayerDisconnected() {
|
||||||
@ -134,6 +116,19 @@ 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(){
|
||||||
|
if(this.options.automaticSeedingMode && Layers.layers.filter((l)=>l.layerid == server.nextLayer)[0].gamemode.toLowerCase()!="seed"){
|
||||||
|
const mapBlacklist = ["BlackCoast"];
|
||||||
|
const seedingMaps = Layers.layers.filter((l) => l.gamemode.toUpperCase()=="SEED" && !mapBlacklist.includes(l.classname))
|
||||||
|
const nextMap = randomElement(seedingMaps).layerid;
|
||||||
|
if(this.server.players && this.server.players.length < 20){
|
||||||
|
this.verbose(1, 'Going into seeding mode.');
|
||||||
|
this.server.rcon.execute(`AdminSetNextLayer ${nextMap}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onChatMessage(info) {
|
async onChatMessage(info) {
|
||||||
@ -277,11 +272,11 @@ export default class MapVote extends BasePlugin {
|
|||||||
this.factionStrings = [];
|
this.factionStrings = [];
|
||||||
let rnd_layers = [];
|
let rnd_layers = [];
|
||||||
// let rnd_layers = [];
|
// let rnd_layers = [];
|
||||||
if (!cmdLayers) {
|
if (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)]);
|
||||||
let l = all_layers[ Math.floor(Math.random() * all_layers.length) ];
|
let l = randomElement(all_layers);
|
||||||
rnd_layers.push(l);
|
rnd_layers.push(l);
|
||||||
this.nominations.push(l.layerid)
|
this.nominations.push(l.layerid)
|
||||||
this.tallies.push(0);
|
this.tallies.push(0);
|
||||||
@ -292,7 +287,7 @@ export default class MapVote extends BasePlugin {
|
|||||||
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('_');
|
||||||
const fLayers = Layers.layers.filter((l) => (l.classname.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, '')))));
|
const fLayers = Layers.layers.filter((l) => ((l.classname.toLowerCase().startsWith(cls[ 0 ]) || 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 = fLayers[ Math.floor(Math.random() * fLayers.length) ]; rnd_layers.push(l);
|
let l = fLayers[ Math.floor(Math.random() * fLayers.length) ]; rnd_layers.push(l);
|
||||||
this.nominations.push(l.layerid)
|
this.nominations.push(l.layerid)
|
||||||
this.tallies.push(0);
|
this.tallies.push(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user