forked from joske2865/AMQ-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamqTeamRandomizer.user.js
81 lines (69 loc) · 2.64 KB
/
amqTeamRandomizer.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ==UserScript==
// @name AMQ Team Randomizer
// @namespace https://github.com/TheJoseph98
// @version 1.0.1
// @description Team randomizer for tag team custom mode, once all players join the lobby, type "/teams" in chat to randomize teams, the teams will be output to chat
// @author TheJoseph98
// @match https://animemusicquiz.com/*
// @grant none
// @require https://raw.githubusercontent.com/TheJoseph98/AMQ-Scripts/master/common/amqScriptInfo.js
// @updateURL https://github.com/TheJoseph98/AMQ-Scripts/raw/master/amqTeamRandomizer.user.js
// ==/UserScript==
if (!window.setupDocumentDone) return;
let players = [];
let playersPerTeam = 2;
let commandListener = new Listener("Game Chat Message", (payload) => {
if (payload.sender === selfName && payload.message.startsWith("/teams")) {
if (lobby.inLobby) {
let message = "";
sendChatMessage("Randomizing teams...");
for (let playerId in lobby.players) {
players.push(lobby.players[playerId]._name);
}
shuffle(players);
for (let teamId = 0; teamId < players.length / playersPerTeam; teamId++) {
message += "Team " + (teamId + 1) + ": ";
for (let playerId = 0; playerId < playersPerTeam; playerId++) {
let playerIdx = teamId * playersPerTeam + playerId;
if (playerId === 0 && playerIdx < players.length) {
message += "@" + players[playerIdx];
}
if (playerId !== 0 && playerIdx < players.length) {
message += " / @" + players[playerIdx];
}
}
sendChatMessage(message);
message = "";
}
players = [];
}
else {
gameChat.systemMessage("Must be in pre-game lobby");
}
}
});
function shuffle(array) {
let counter = array.length;
while (counter > 0) {
let index = Math.floor(Math.random() * counter);
counter--;
let temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
function sendChatMessage(message) {
gameChat.$chatInputField.val(message);
gameChat.sendMessage();
}
commandListener.bindListener();
AMQ_addScriptData({
name: "Team Randomizer",
author: "TheJoseph98",
description: `
<p>Team randomizer for the Tag Teams custom mode</p>
<p>Type "/teams" in chat to randomize the teams</p>
<p>Works only while in the lobby (ie. not currently in a quiz)</p>
`
})