Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 85.71 KB | None | 0 0
  1. // Stats: "Auth" : '["0-Games", "1-Wins", "2-Draws", "3-Losses", "4-Winrate", "5-Goals", "6-Assists", "7-GK", "8-CS", "9-CS%", "10-Role", "11-Nick"]'
  2.  
  3. /* VARIABLES */
  4.  
  5. /* ROOM */
  6.  
  7. const roomName = "🤾 [HHC] Handball 4v4 | Join us!";
  8. const botName = "HandBot";
  9. const maxPlayers = 12;
  10. const roomPublic = true;
  11. const geo = [{"code": "XK", "lat": 51.1, "lon": 10.4}];
  12.  
  13. const room = HBInit({ roomName: roomName, maxPlayers: maxPlayers, public: roomPublic, playerName: botName, geo: geo[0] });
  14.  
  15. const scoreLimitClassic = 3;
  16. const scoreLimitBig = 3;
  17. const timeLimitClassic = 5;
  18. const timeLimitBig = 5;
  19.  
  20. room.setTeamsLock(true);
  21.  
  22. var adminPassword = 1000 + getRandomInt(9000);
  23. console.log("adminPassword : " + adminPassword);
  24.  
  25. /* STADIUM */
  26.  
  27. const playerRadius = 15;
  28. var ballRadius = 10;
  29. const triggerDistance = playerRadius + ballRadius + 0.01;
  30. var aloneMap = '{"name":"No Goals from HaxMaps","width":420,"height":200,"spawnDistance":170,"bg":{"type":"hockey","width":0,"height":0,"kickOffRadius":0,"cornerRadius":0},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":170,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"},{"cMask":["ball"],"x":370,"y":-170}],"segments":[{"vis":true,"color":"ffffff","cMask":["ball"],"v0":1,"v1":6},{"vis":true,"color":"ffffff","cMask":["ball"],"v0":2,"v1":0},{"vis":true,"color":"ffffff","cMask":["ball"],"v0":3,"v1":2},{"vis":true,"color":"ffffff","cMask":["ball"],"v0":1,"v1":0}],"goals":[],"discs":[],"planes":[{"normal":[0,1],"dist":-170,"trait":"ballArea"},{"normal":[0,-1],"dist":-170,"trait":"ballArea","_selected":true},{"normal":[0,1],"dist":-200,"bCoef":0.1},{"normal":[0,-1],"dist":-200,"bCoef":0.1},{"normal":[1,0],"dist":-420,"bCoef":0.1},{"normal":[-1,0],"dist":-420,"bCoef":0.1},{"normal":[1,0],"dist":-370,"bCoef":1,"cMask":["ball"],"trait":"ballArea"},{"normal":[-1,0],"dist":-370,"bCoef":1,"cMask":["ball"],"trait":"ballArea"}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}}}'
  31. var classicMap = '{"name":"Handball 2v2 by Danny Welbeck from HaxMaps from HaxMaps","width":460,"height":240,"spawnDistance":170,"bg":{"type":"hockey","height":0,"width":0,"cornerRadius":0,"kickOffRadius":0},"vertexes":[{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-421,"y":-200},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":420,"y":-201},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-421,"y":200},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":420,"y":201},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":420,"y":-84},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-420,"y":-84},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":420,"y":84},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-420,"y":84},{"bCoef":0.1,"cGroup":["blueKO"],"trait":"kickOffBarrier","x":0,"y":-198},{"bCoef":0.1,"cGroup":["blueKO"],"trait":"kickOffBarrier","x":0,"y":198},{"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO"],"trait":"kickOffBarrier","x":0,"y":-41,"curve":-180,"_selected":true},{"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0,"y":39,"curve":-180,"_selected":"segment"},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-418,"y":132},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-294,"y":45,"curve":8},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":418,"y":132},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":294,"y":45,"curve":-8},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-418,"y":-132},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-294,"y":-45,"curve":8},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":418,"y":-132},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":294,"y":-45,"curve":-8},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-418,"y":168},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-256,"y":50,"curve":8},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":418,"y":168},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":256,"y":50,"curve":-8},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-418,"y":-168},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-256,"y":-50,"curve":8},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":418,"y":-168},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":256,"y":-50,"curve":-8},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-276,"y":-17},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-276,"y":18},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":276,"y":-17},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":276,"y":18},{"bCoef":0.1,"trait":"goalNet","x":-429,"y":-84,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":-449,"y":-58,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":429,"y":-84,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":449,"y":-58,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":-429,"y":84,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":-449,"y":58,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":429,"y":84,"vis":true},{"bCoef":0.1,"trait":"goalNet","x":449,"y":58,"vis":true},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":420.5,"y":94},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":420.5,"y":-89},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-420.5,"y":94},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-420.5,"y":-89},{"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0.5,"y":203,"vis":true,"_selected":"segment"},{"bCoef":0.5,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0,"y":-203,"vis":true},{"bCoef":0.5,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0,"y":-35,"vis":true},{"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0.5,"y":239,"vis":true},{"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0.5,"y":-239,"vis":true},{"bCoef":1,"x":-462.5,"y":132,"cMask":["blue"],"cGroup":["blue"]},{"bCoef":1,"x":462.5,"y":132,"cMask":["red"],"cGroup":["red"]},{"bCoef":1,"x":-462.5,"y":-132,"cMask":["blue"],"cGroup":["blue"]},{"bCoef":1,"x":462.5,"y":-132,"cMask":["red"],"cGroup":["red"]},{"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","x":0.5,"y":-210,"_selected":true}],"segments":[{"vis":true,"color":"ffffff","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":0,"v1":1},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":2,"v1":3},{"curve":-85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":12,"v1":13},{"curve":85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":14,"v1":15},{"curve":85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":16,"v1":17},{"curve":-85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":18,"v1":19},{"curve":8,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":17,"v1":13},{"curve":-8,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":19,"v1":15},{"curve":-85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":20,"v1":21},{"curve":85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":22,"v1":23},{"curve":85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":24,"v1":25},{"curve":-85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":26,"v1":27},{"curve":8,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":25,"v1":21},{"curve":-8,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":27,"v1":23},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":28,"v1":29},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":30,"v1":31},{"curve":-90,"bCoef":0.1,"trait":"goalNet","v0":32,"v1":33,"vis":true},{"curve":90,"bCoef":0.1,"trait":"goalNet","v0":34,"v1":35,"vis":true},{"curve":90,"bCoef":0.1,"trait":"goalNet","v0":36,"v1":37,"vis":true},{"curve":-90,"bCoef":0.1,"trait":"goalNet","v0":38,"v1":39,"vis":true},{"curve":0,"bCoef":0.1,"trait":"goalNet","v0":33,"v1":37,"vis":true},{"curve":0,"bCoef":0.1,"trait":"goalNet","v0":35,"v1":39,"vis":true},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":40,"v1":41},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":42,"v1":43},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["blueKO"],"trait":"kickOffBarrier","v0":44,"v1":11},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","v0":44,"v1":11,"_selected":true},{"vis":false,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","v0":44,"v1":47},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","v0":44,"v1":47},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","v0":45,"v1":48},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","v0":45,"v1":48},{"vis":true,"color":"ffffff","bCoef":1,"trait":"ballArea","v0":2,"v1":7},{"vis":true,"color":"ffffff","bCoef":1,"trait":"ballArea","v0":3,"v1":6},{"vis":true,"color":"ffffff","bCoef":1,"trait":"ballArea","v0":0,"v1":43},{"vis":true,"color":"ffffff","bCoef":1,"trait":"ballArea","v0":1,"v1":41},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"v0":12,"v1":49,"cMask":["blue"],"cGroup":["blue"]},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"v0":14,"v1":50,"cMask":["red"],"cGroup":["red"]},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"v0":16,"v1":51,"cMask":["blue"],"cGroup":["blue"]},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"v0":18,"v1":52,"cMask":["red"],"cGroup":["red"]},{"curve":-180,"vis":true,"color":"ffffff","bCoef":0.5,"cMask":["red","blue"],"cGroup":["blueKO"],"trait":"kickOffBarrier","v0":10,"v1":11},{"curve":180,"vis":true,"color":"ffffff","bCoef":0.5,"cMask":["red","blue"],"cGroup":["redKO"],"trait":"kickOffBarrier","v0":10,"v1":11},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"],"trait":"kickOffBarrier","v0":10,"v1":53,"_selected":true}],"goals":[{"p0":[421.5,-76],"p1":[421.5,76],"team":"blue"},{"p0":[-421.5,76],"p1":[-421.5,-76],"team":"red"}],"discs":[{"bCoef":0.5,"trait":"goalPost","pos":[-420,83],"radius":9.05538513814},{"bCoef":0.5,"trait":"goalPost","pos":[420,83],"radius":9.05538513814},{"bCoef":0.5,"trait":"goalPost","pos":[-420,-83],"radius":9.05538513814},{"bCoef":0.5,"trait":"goalPost","pos":[420,-83],"radius":9.05538513814}],"planes":[{"bCoef":1,"dist":-239,"normal":[0,-1]},{"bCoef":1,"dist":-239,"normal":[0,1]},{"bCoef":1,"dist":-460.5,"normal":[-1,0]},{"bCoef":1,"dist":-460.5,"normal":[1,0]}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}},"ballPhysics":{"radius":7.6,"color":"7CFC00"},"playerPhysics":{"kickStrength":5.95}}'; // Insert your map for 1v1 and 2v2 here. To get minimum file size, here are the instructions : 1. Download the map 2. Go to https://cssminifier.com 3. Paste the result
  32. var bigMap = '{"name":"HHC Official Field 2019 from HaxMaps","width":700,"height":350,"spawnDistance":350,"bg":{"type":"hockey","width":0,"height":0,"kickOffRadius":0,"cornerRadius":0},"vertexes":[{"x":-653,"y":315,"trait":"ballArea","vis":true,"color":"ffffff","curve":0},{"x":-653,"y":94,"trait":"ballArea","vis":true,"color":"ffffff"},{"x":-653,"y":-96,"trait":"ballArea","color":"ffffff","vis":true,"cMask":["blue"],"cGroup":["blue"]},{"x":-653,"y":-320,"trait":"ballArea","color":"ffffff","vis":true},{"x":653,"y":319,"trait":"ballArea","vis":true,"color":"ffffff","curve":0},{"x":653,"y":94,"trait":"ballArea","vis":true,"color":"ffffff","cMask":["red"],"cGroup":["red"]},{"x":653,"y":-96,"trait":"ballArea","curve":0,"vis":true,"color":"ffffff","cGroup":["red"],"cMask":["red"]},{"x":652,"y":-320,"trait":"ballArea","curve":0,"vis":true,"color":"ffffff"},{"x":-1,"y":317,"trait":"kickOffBarrier","color":"ffffff","vis":true},{"x":0,"y":80,"trait":"kickOffBarrier","color":"ffffff","vis":true,"cMask":["red"],"cGroup":["blueKO"],"curve":180},{"x":0,"y":-80,"trait":"kickOffBarrier","color":"ffffff","vis":true,"cMask":["red"],"cGroup":["blueKO"],"curve":180},{"x":0,"y":-320,"trait":"kickOffBarrier","color":"ffffff","vis":true},{"x":-653,"y":-100,"trait":"goalNet","curve":0},{"x":-693,"y":-100,"trait":"goalNet","curve":0},{"x":-693,"y":100,"trait":"goalNet","curve":0},{"x":-653,"y":100,"trait":"goalNet","curve":0},{"x":653,"y":-100,"trait":"goalNet","curve":0},{"x":693,"y":-100,"trait":"goalNet","curve":0},{"x":693,"y":100,"trait":"goalNet","curve":0},{"x":653,"y":100,"trait":"goalNet","curve":0},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-653,"y":-210,"curve":85},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-653,"y":210,"curve":-85},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-652,"y":-210,"curve":85,"color":"0000b3"},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-523,"y":-101,"curve":8,"color":"0000b3"},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-652,"y":210,"curve":-85,"color":"0000b3"},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":-523,"y":99,"curve":8,"color":"0000b3"},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":653,"y":210,"curve":85},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":653,"y":-210,"curve":-85},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":653,"y":210,"curve":85,"color":"0000b3"},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":523,"y":110,"curve":8,"color":"0000b3"},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":653,"y":-210,"curve":-85,"color":"0000b3"},{"bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"x":523,"y":-110,"curve":8,"color":"0000b3"},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-653,"y":104},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-697,"y":104},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-653.5,"y":-104},{"bCoef":1,"cMask":["blue"],"cGroup":["blue"],"x":-697,"y":-104},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":702,"y":-104},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":651.5,"y":-104},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":702,"y":104,"curve":0},{"bCoef":1,"cMask":["red"],"cGroup":["red"],"x":655.5,"y":104,"curve":0},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-652,"y":275,"curve":-85},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-463,"y":100,"curve":-85},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-652,"y":-275,"curve":85},{"bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"x":-463,"y":-100,"curve":85},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":652,"y":-275,"curve":-85},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":463,"y":-100,"curve":-85},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":652,"y":275,"curve":85},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":463,"y":100,"curve":85},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":-489,"y":-15},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":-489,"y":15},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":489,"y":-15,"curve":0},{"bCoef":1,"cMask":["red"],"cGroup":["redKO"],"x":489,"y":15,"curve":0},{"x":-331.50410819243,"y":43.982048410491,"curve":0,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-324.24320666281,"y":30.856527126474,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-306.74251161746,"y":40.537729165966,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-280.49146904942,"y":55.059532225205,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-287.75237057904,"y":68.185053509222,"cMask":["blue"],"cGroup":["blueKO"]},{"x":-312.14170411345,"y":8.9806583197798,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-293.15156307503,"y":36.627982663035,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-297.99216409478,"y":45.378330185713,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-301.90191059771,"y":31.787381643289,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-275.65086802968,"y":46.309184702527,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-268.38996650006,"y":33.183663418511,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-319.40260564307,"y":22.106179603796,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-307.3011030937,"y":0.23031079710214,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-300.04020156408,"y":-12.895210486914,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-282.53950651873,"y":-3.2140084474221,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-256.28846395069,"y":11.307794611817,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-263.54936548031,"y":24.433315895833,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-287.93869901472,"y":-34.771079293609,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-268.9485579763,"y":-7.1237549503535,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-273.78915899605,"y":1.6265925723242,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-277.69890549898,"y":-11.9643559701,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-251.44786293095,"y":2.5574470891389,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-244.18696140133,"y":-10.568074194878,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-295.19960054434,"y":-21.645558009592,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-283.09809799497,"y":-43.521426816287,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-264.46174468587,"y":-50.354166774633,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-239.34636038158,"y":-19.318421717555,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-263.73569391598,"y":-78.522816906997,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-231.35940808208,"y":-60.612593133936,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-243.46091063144,"y":-38.736724327242,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-252.3602421365,"y":-72.230035581327,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-219.9839563026,"y":-54.319811808266,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":-287.75237057904,"y":68.185053509222,"curve":0,"color":"ffffff","cMask":["blue"],"cGroup":["blueKO"]},{"x":262.80591454389,"y":-78.232878939449,"curve":0,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":270.58967634497,"y":-65.410513626287,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":253.49318926075,"y":-55.032164558191,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":227.84845863443,"y":-39.464640956047,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":220.06469683336,"y":-52.287006269208,"cMask":["red"],"cGroup":["redKO"]},{"x":283.56261268009,"y":-44.039904771018,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":250.13412025269,"y":-41.294746482035,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":244.94494571864,"y":-49.842990024143,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":258.6823637948,"y":-46.483921016083,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":233.03763316848,"y":-30.916397413939,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":240.82139496955,"y":-18.094032100777,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":275.77885087901,"y":-56.862270084179,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":288.75178721413,"y":-35.49166122891,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":296.53554901521,"y":-22.669295915749,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":279.43906193099,"y":-12.290946847652,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":253.79433130467,"y":3.276576754492,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":246.0105695036,"y":-9.5457885586695,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":309.50848535033,"y":-1.298687060479,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":276.07999292293,"y":1.4464712285037,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":270.89081838888,"y":-7.1017723136041,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":284.62823646504,"y":-3.7427033055443,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":258.98350583872,"y":11.8248202966,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":266.76726763979,"y":24.647185609761,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":301.72472354926,"y":-14.121052373641,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":314.69765988438,"y":7.2495564816287,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":311.36870508071,"y":26.817848689053,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":271.95644217384,"y":33.195429151869,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":335.45435802057,"y":41.44253065006,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":303.82585691477,"y":60.642476426038,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":290.85292057965,"y":39.271867570768,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":324.34164141583,"y":48.188457544322,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":292.71314031003,"y":67.3884033203,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":220.06469683336,"y":-52.287006269208,"curve":0,"color":"ffffff","cMask":["red"],"cGroup":["redKO"]},{"x":0,"y":-80,"trait":"kickOffBarrier","color":"ffffff","vis":false,"cMask":["red"],"cGroup":["blueKO"],"curve":180},{"x":0,"y":-350,"trait":"kickOffBarrier","color":"ffffff","vis":false},{"x":-1,"y":350,"trait":"kickOffBarrier","color":"ffffff","vis":false},{"x":0,"y":80,"trait":"kickOffBarrier","color":"ffffff","vis":false,"cMask":["red"],"cGroup":["blueKO"],"curve":180}],"segments":[{"v0":0,"v1":1,"trait":"ballArea","vis":true,"color":"ffffff","x":-653},{"v0":2,"v1":3,"trait":"ballArea","color":"ffffff","vis":true,"x":-653},{"v0":4,"v1":5,"trait":"ballArea","vis":true,"color":"ffffff"},{"v0":6,"v1":7,"trait":"ballArea","curve":0,"vis":true,"color":"ffffff"},{"v0":12,"v1":13,"trait":"goalNet","curve":0},{"v0":13,"v1":14,"trait":"goalNet","curve":0},{"v0":14,"v1":15,"trait":"goalNet","curve":0},{"v0":16,"v1":17,"trait":"goalNet","curve":0},{"v0":17,"v1":18,"trait":"goalNet","curve":0},{"v0":18,"v1":19,"trait":"goalNet","curve":0},{"v0":8,"v1":9,"trait":"kickOffBarrier","color":"ffffff","vis":true},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"],"vis":true,"color":"ffffff"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"],"color":"ffffff","vis":true},{"v0":10,"v1":11,"trait":"kickOffBarrier","color":"ffffff","vis":true},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":4,"v1":0,"curve":0,"y":290},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":3,"v1":7,"y":-290},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blue"],"v0":2,"v1":1},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["red"],"v0":6,"v1":5},{"curve":85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":22,"v1":23},{"curve":-85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":24,"v1":25},{"curve":8,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":23,"v1":25,"x":-523},{"curve":85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":28,"v1":29},{"curve":-85,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":30,"v1":31},{"curve":8,"vis":true,"color":"0000b3","bCoef":1,"cMask":["blue","red"],"cGroup":["blue","red"],"v0":29,"v1":31},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["red"],"v0":27,"v1":6},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"v0":26,"v1":5,"cMask":["red"],"cGroup":["red"]},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blue"],"v0":21,"v1":1,"x":-653},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"v0":20,"v1":2,"cMask":["blue"],"cGroup":["blue"],"x":-653},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blue"],"v0":32,"v1":33,"y":104},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blue"],"v0":34,"v1":35},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["red"],"v0":36,"v1":37,"y":-104},{"curve":0,"vis":false,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["red"],"v0":38,"v1":39,"y":104},{"vis":true,"color":"ffffff","bCoef":0.1,"cMask":["red"],"cGroup":["blueKO"],"trait":"kickOffBarrier","v0":10,"v1":9},{"curve":-85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":40,"v1":41},{"curve":85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":42,"v1":43},{"curve":8,"vis":true,"color":"ffffff","bCoef":1,"cMask":["blue"],"cGroup":["blueKO"],"v0":43,"v1":41,"x":-463},{"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":44,"v1":45,"curve":-85},{"curve":85,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":46,"v1":47},{"curve":-8,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":45,"v1":47},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":48,"v1":49,"x":-489},{"curve":0,"vis":true,"color":"ffffff","bCoef":1,"cMask":["red"],"cGroup":["redKO"],"v0":50,"v1":51},{"curve":0,"vis":true,"color":"ffffff","v0":52,"v1":84,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":52,"v1":53,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":84,"v1":55,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":55,"v1":59,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":53,"v1":54,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":54,"v1":60,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":59,"v1":58,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":63,"v1":60,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":58,"v1":61,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":61,"v1":62,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":62,"v1":57,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":63,"v1":57,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":64,"v1":68,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":68,"v1":67,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":64,"v1":65,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":65,"v1":66,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":66,"v1":72,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":71,"v1":70,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":71,"v1":67,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":75,"v1":72,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":75,"v1":69,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":70,"v1":73,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":73,"v1":74,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":69,"v1":74,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":76,"v1":78,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":78,"v1":83,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":76,"v1":79,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":77,"v1":82,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":77,"v1":81,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":81,"v1":80,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":79,"v1":82,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":80,"v1":83,"cMask":["blue"],"cGroup":["blueKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":85,"v1":117,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":85,"v1":86,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":117,"v1":88,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":88,"v1":92,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":86,"v1":87,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":87,"v1":93,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":92,"v1":91,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":96,"v1":93,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":91,"v1":94,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":94,"v1":95,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":95,"v1":90,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":96,"v1":90,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":97,"v1":101,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":101,"v1":100,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":97,"v1":98,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":98,"v1":99,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":99,"v1":105,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":104,"v1":103,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":104,"v1":100,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":108,"v1":105,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":108,"v1":102,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":103,"v1":106,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":106,"v1":107,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":102,"v1":107,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":109,"v1":111,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":111,"v1":116,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":109,"v1":112,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":110,"v1":115,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":110,"v1":114,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":114,"v1":113,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":112,"v1":115,"cMask":["red"],"cGroup":["redKO"]},{"curve":0,"vis":true,"color":"ffffff","v0":113,"v1":116,"cMask":["red"],"cGroup":["redKO"]},{"v0":118,"v1":119,"trait":"kickOffBarrier","color":"ffffff","vis":false},{"v0":120,"v1":121,"trait":"kickOffBarrier","color":"ffffff","vis":false}],"goals":[{"p0":[-653,94],"p1":[-653,-96],"team":"red"},{"p0":[653,94],"p1":[653,-96],"team":"blue"}],"discs":[{"pos":[-653,100],"trait":"goalPost","color":"FFCCCC"},{"pos":[-653,-100],"trait":"goalPost","color":"FFCCCC"},{"pos":[653,100],"trait":"goalPost","color":"CCCCFF"},{"pos":[653,-100],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-320,"trait":"ballArea"},{"normal":[0,-1],"dist":-320,"trait":"ballArea"},{"normal":[0,1],"dist":-354,"bCoef":0.1},{"normal":[0,-1],"dist":-351,"bCoef":0.1},{"normal":[1,0],"dist":-698,"bCoef":0.1},{"normal":[-1,0],"dist":-702,"bCoef":0.1}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}},"ballPhysics":{"radius":8.8,"color":"ffff00","bCoef":0.4},"playerPhysics":{"kickStrength":6.15,"bCoef":0}}'; // Read above
  33.  
  34. /* OPTIONS */
  35.  
  36. var afkLimit = 12;
  37. var drawTimeLimit = Infinity;
  38. var maxTeamSize = 4; // This works for 1 (you might want to adapt things to remove some useless stats in 1v1 like assist or cs), 2, 3 or 4
  39. var slowMode = 0;
  40.  
  41. /* PLAYERS */
  42.  
  43. const Team = { SPECTATORS: 0, RED: 1, BLUE: 2 };
  44. var extendedP = [];
  45. const eP = { ID: 0, AUTH: 1, CONN: 2, AFK: 3, ACT: 4, GK: 5, MUTE: 6 };
  46. const Ss = { GA: 0, WI: 1, DR: 2, LS: 3, WR: 4, GL: 5, AS: 6, GK: 7, CS: 8, CP: 9, RL: 10, NK: 11}
  47. var players;
  48. var teamR;
  49. var teamB;
  50. var teamS;
  51.  
  52. /* GAME */
  53.  
  54. var lastTeamTouched;
  55. var lastPlayersTouched; // These allow to get good goal notifications (it should be lastPlayersKicked, waiting on a next update to get better track of shots on target)
  56. var countAFK = false; // Created to get better track of activity
  57. var activePlay = false; // Created to get better track of the possession
  58. var goldenGoal = false;
  59. var SMSet = new Set(); // Set created to get slow mode which is useful in chooseMode
  60. var banList = []; // Getting track of the bans, so we can unban ppl if we want
  61.  
  62. /* STATS */
  63.  
  64. var game;
  65. var GKList = ["",""];
  66. var Rposs = 0;
  67. var Bposs = 0;
  68. var point = [{"x": 0, "y": 0}, {"x": 0, "y": 0}]; // created to get ball speed
  69. var ballSpeed;
  70. var lastWinner = Team.SPECTATORS;
  71. var streak = 0;
  72. var allBlues = []; // This is to count the players who should be counted for the stats. This includes players who left after the game has started, doesn't include those who came too late or ...
  73. var allReds = []; // ... those who came in a very unequal game.
  74.  
  75. /* BALANCE & CHOOSE */
  76.  
  77. var inChooseMode = false; // This variable enables to distinguish the 2 phases of playing and choosing which should be dealt with very differently
  78. var redCaptainChoice = "";
  79. var blueCaptainChoice = "";
  80. var chooseTime = 20;
  81. var timeOutCap;
  82.  
  83. /* AUXILIARY */
  84.  
  85. var checkTimeVariable = false; // This is created so the chat doesn't get spammed when a game is ending via timeLimit
  86. var statNumber = 0; // This allows the room to be given stat information every X minutes
  87. var endGameVariable = false; // This variable with the one below helps distinguish the cases where games are stopped because they have finished to the ones where games are stopped due to player movements or resetting teams
  88. var resettingTeams = false;
  89. var capLeft = false;
  90. var statInterval = 6;
  91.  
  92. loadMap(aloneMap, 0, 0);
  93.  
  94. /* OBJECTS */
  95.  
  96. function Goal(time, team, striker, assist) {
  97. this.time = time;
  98. this.team = team;
  99. this.striker = striker;
  100. this.assist = assist;
  101. }
  102.  
  103. function Game(date, scores, goals) {
  104. this.date = date;
  105. this.scores = scores;
  106. this.goals = goals;
  107. }
  108.  
  109. /* FUNCTIONS */
  110.  
  111. /* AUXILIARY FUNCTIONS */
  112.  
  113. function getRandomInt(max) { // returns a random number from 0 to max-1
  114. return Math.floor(Math.random() * Math.floor(max));
  115. }
  116.  
  117. function getTime(scores) { // returns the current time of the game
  118. return "[" + Math.floor(Math.floor(scores.time/60)/10).toString() + Math.floor(Math.floor(scores.time/60)%10).toString() + ":" + Math.floor(Math.floor(scores.time - (Math.floor(scores.time/60) * 60))/10).toString() + Math.floor(Math.floor(scores.time - (Math.floor(scores.time/60) * 60))%10).toString() + "]"
  119. }
  120.  
  121. function pointDistance(p1, p2) {
  122. var d1 = p1.x - p2.x;
  123. var d2 = p1.y - p2.y;
  124. return Math.sqrt(d1 * d1 + d2 * d2);
  125. }
  126.  
  127. /* BUTTONS */
  128.  
  129. function topBtn() {
  130. if (teamS.length == 0) {
  131. return;
  132. }
  133. else {
  134. if (teamR.length == teamB.length) {
  135. if (teamS.length > 1) {
  136. room.setPlayerTeam(teamS[0].id, Team.RED);
  137. room.setPlayerTeam(teamS[1].id, Team.BLUE);
  138. }
  139. return;
  140. }
  141. else if (teamR.length < teamB.length) {
  142. room.setPlayerTeam(teamS[0].id, Team.RED);
  143. }
  144. else {
  145. room.setPlayerTeam(teamS[0].id, Team.BLUE);
  146. }
  147. }
  148. }
  149.  
  150. function randomBtn() {
  151. if (teamS.length == 0) {
  152. return;
  153. }
  154. else {
  155. if (teamR.length == teamB.length) {
  156. if (teamS.length > 1) {
  157. var r = getRandomInt(teamS.length);
  158. room.setPlayerTeam(teamS[r].id, Team.RED);
  159. teamS = teamS.filter((spec) => spec.id != teamS[r].id);
  160. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE);
  161. }
  162. return;
  163. }
  164. else if (teamR.length < teamB.length) {
  165. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.RED);
  166. }
  167. else {
  168. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE);
  169. }
  170. }
  171. }
  172.  
  173. function blueToSpecBtn() {
  174. resettingTeams = true;
  175. setTimeout(() => { resettingTeams = false; }, 100);
  176. for (var i = 0; i < teamB.length; i++) {
  177. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  178. }
  179. }
  180.  
  181. function redToSpecBtn() {
  182. resettingTeams = true;
  183. setTimeout(() => { resettingTeams = false; }, 100);
  184. for (var i = 0; i < teamR.length; i++) {
  185. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  186. }
  187. }
  188.  
  189. function resetBtn() {
  190. resettingTeams = true;
  191. setTimeout(() => { resettingTeams = false; }, 100);
  192. if (teamR.length <= teamB.length) {
  193. for (var i = 0; i < teamR.length; i++) {
  194. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  195. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  196. }
  197. for (var i = teamR.length; i < teamB.length; i++) {
  198. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  199. }
  200. }
  201. else {
  202. for (var i = 0; i < teamB.length; i++) {
  203. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  204. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  205. }
  206. for (var i = teamB.length; i < teamR.length; i++) {
  207. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  208. }
  209. }
  210. }
  211.  
  212. function blueToRedBtn() {
  213. resettingTeams = true;
  214. setTimeout(() => { resettingTeams = false; }, 100);
  215. for (var i = 0; i < teamB.length; i++) {
  216. room.setPlayerTeam(teamB[i].id, Team.RED);
  217. }
  218. }
  219.  
  220. /* GAME FUNCTIONS */
  221.  
  222. function checkTime() {
  223. const scores = room.getScores();
  224. game.scores = scores;
  225. if (Math.abs(scores.time - scores.timeLimit) <= 0.01 && scores.timeLimit != 0) {
  226. if (scores.red != scores.blue) {
  227. if (checkTimeVariable == false) {
  228. checkTimeVariable = true;
  229. setTimeout(() => { checkTimeVariable = false; }, 3000);
  230. scores.red > scores.blue ? endGame(Team.RED) : endGame(Team.BLUE);
  231. setTimeout(() => { room.stopGame(); }, 2000);
  232. }
  233. return;
  234. }
  235. goldenGoal = true;
  236. room.sendChat("⚽ First goal wins !");
  237. }
  238. if (Math.abs(drawTimeLimit * 60 - scores.time - 60) <= 0.01 && players.length > 2) {
  239. if (checkTimeVariable == false) {
  240. checkTimeVariable = true;
  241. setTimeout(() => { checkTimeVariable = false; }, 10);
  242. room.sendChat("⌛ 60 seconds left until draw !");
  243. }
  244. }
  245. if (Math.abs(scores.time - drawTimeLimit * 60) <= 0.01 && players.length > 2) {
  246. if (checkTimeVariable == false) {
  247. checkTimeVariable = true;
  248. setTimeout(() => { checkTimeVariable = false; }, 10);
  249. endGame(Team.SPECTATORS);
  250. room.stopGame();
  251. goldenGoal = false;
  252. }
  253. }
  254. }
  255.  
  256. function endGame(winner) { // handles the end of a game : no stopGame function inside
  257. players.length >= 2 * maxTeamSize - 1 ? activateChooseMode() : null;
  258. const scores = room.getScores();
  259. game.scores = scores;
  260. Rposs = Rposs/(Rposs+Bposs);
  261. Bposs = 1 - Rposs;
  262. lastWinner = winner;
  263. endGameVariable = true;
  264. if (winner == Team.RED) {
  265. streak++;
  266. room.sendChat("🔴 Red Team won " + scores.red + "-" + scores.blue + " ! Current streak : " + streak + " 🏆");
  267. }
  268. else if (winner == Team.BLUE) {
  269. streak = 1;
  270. room.sendChat("🔵 Blue Team won " + scores.blue + "-" + scores.red + " ! Current streak : " + streak + " 🏆");
  271. }
  272. else {
  273. streak = 0;
  274. room.sendChat("💤 Draw limit reached! 💤");
  275. }
  276. room.sendChat("⭐ Possession : 🔴 " + (Rposs*100).toPrecision(3).toString() + "% : " + (Bposs*100).toPrecision(3).toString() + "% 🔵");
  277. scores.red == 0 ? (scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " and " + GKList[1].name + " kept a CS ! ") : room.sendChat("🏆 " + GKList[1].name + " kept a CS ! ")) : scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " kept a CS ! ") : null;
  278. updateStats();
  279. }
  280.  
  281. function quickRestart() {
  282. room.stopGame();
  283. setTimeout(() => { room.startGame(); }, 2000);
  284. }
  285.  
  286. function resumeGame() {
  287. setTimeout(() => { room.startGame(); }, 2000);
  288. setTimeout(() => { room.pauseGame(false); }, 1000);
  289. }
  290.  
  291. function activateChooseMode() {
  292. inChooseMode = true;
  293. slowMode = 2;
  294. room.sendChat("2 seconds slow mode enabled !");
  295. }
  296.  
  297. function deactivateChooseMode() {
  298. inChooseMode = false;
  299. clearTimeout(timeOutCap);
  300. if (slowMode != 0) {
  301. slowMode = 0;
  302. room.sendChat("Slow mode terminated.");
  303. }
  304. redCaptainChoice = "";
  305. blueCaptainChoice = "";
  306. }
  307.  
  308. function loadMap(map, scoreLim, timeLim) {
  309. if (map == aloneMap) {
  310. room.setCustomStadium(aloneMap);
  311. }
  312. else if (map == classicMap) {
  313. (classicMap != '') ? room.setCustomStadium(classicMap) : room.setDefaultStadium("Classic");
  314. }
  315. else if (map == bigMap) {
  316. (bigMap != '.') ? room.setCustomStadium(bigMap) : room.setDefaultStadium("Big");
  317. }
  318. else {
  319. room.setCustomStadium(map);
  320. }
  321. room.setScoreLimit(scoreLim);
  322. room.setTimeLimit(timeLim);
  323. }
  324.  
  325. /* PLAYER FUNCTIONS */
  326.  
  327. function updateTeams() { // update the players' list and all the teams' list
  328. players = room.getPlayerList().filter((player) => player.id != 0 && !getAFK(player));
  329. teamR = players.filter(p => p.team === Team.RED);
  330. teamB = players.filter(p => p.team === Team.BLUE);
  331. teamS = players.filter(p => p.team === Team.SPECTATORS);
  332. }
  333.  
  334. function handleInactivity() { // handles inactivity : players will be kicked after afkLimit
  335. if (countAFK && (teamR.length + teamB.length) > 1) {
  336. for (var i = 0; i < teamR.length ; i++) {
  337. setActivity(teamR[i], getActivity(teamR[i]) + 1);
  338. }
  339. for (var i = 0; i < teamB.length ; i++) {
  340. setActivity(teamB[i], getActivity(teamB[i]) + 1);
  341. }
  342. }
  343. for (var i = 0; i < extendedP.length ; i++) {
  344. if (extendedP[i][eP.ACT] == 60 * (2/3 * afkLimit)) {
  345. room.sendChat("[PV] ⛔ @" + room.getPlayer(extendedP[i][eP.ID]).name + ", if you don't move or send a message in the next " + Math.floor(afkLimit / 3) + " seconds, you will be kicked !", extendedP[i][eP.ID]);
  346. }
  347. if (extendedP[i][eP.ACT] >= 60 * afkLimit) {
  348. extendedP[i][eP.ACT] = 0;
  349. if (room.getScores().time <= afkLimit - 0.5) {
  350. setTimeout(() => { !inChooseMode ? quickRestart() : room.stopGame(); }, 10);
  351. }
  352. room.kickPlayer(extendedP[i][eP.ID], "AFK", false);
  353. }
  354. }
  355. }
  356.  
  357. function getAuth(player) {
  358. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AUTH] : null;
  359. }
  360.  
  361. function getAFK(player) {
  362. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AFK] : null;
  363. }
  364.  
  365. function setAFK(player, value) {
  366. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.AFK] = value);
  367. }
  368.  
  369. function getActivity(player) {
  370. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.ACT] : null;
  371. }
  372.  
  373. function setActivity(player, value) {
  374. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.ACT] = value);
  375. }
  376.  
  377. function getGK(player) {
  378. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.GK] : null;
  379. }
  380.  
  381. function setGK(player, value) {
  382. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.GK] = value);
  383. }
  384.  
  385. function getMute(player) {
  386. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.MUTE] : null;
  387. }
  388.  
  389. function setMute(player, value) {
  390. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.MUTE] = value);
  391. }
  392.  
  393. /* BALANCE & CHOOSE FUNCTIONS */
  394.  
  395. function updateRoleOnPlayerIn() {
  396. updateTeams();
  397. if (inChooseMode) {
  398. if (players.length == 6) {
  399. loadMap(bigMap, scoreLimitBig, timeLimitBig);
  400. }
  401. getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
  402. }
  403. balanceTeams();
  404. }
  405.  
  406. function updateRoleOnPlayerOut() {
  407. updateTeams();
  408. if (room.getScores() != null) {
  409. var scores = room.getScores();
  410. if (players.length >= 2 * maxTeamSize && scores.time >= (5/6) * game.scores.timeLimit && teamR.length != teamB.length) {
  411. if (teamR.length < teamB.length) {
  412. if (scores.blue - scores.red == 2) {
  413. endGame(Team.BLUE);
  414. room.sendChat("🤖 Ragequit detected. Game ended 🤖");
  415. setTimeout(() => { room.stopGame(); }, 100);
  416. return;
  417. }
  418. }
  419. else {
  420. if (scores.red - scores.blue == 2) {
  421. endGame(Team.RED);
  422. room.sendChat("🤖 Ragequit detected. Game ended 🤖");
  423. setTimeout(() => { room.stopGame(); }, 100);
  424. return;
  425. }
  426. }
  427. }
  428. }
  429. if (inChooseMode) {
  430. if (players.length == 5) {
  431. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  432. }
  433. if (teamR.length == 0 || teamB.length == 0) {
  434. teamR.length == 0 ? room.setPlayerTeam(teamS[0].id, Team.RED) : room.setPlayerTeam(teamS[0].id, Team.BLUE);
  435. return;
  436. }
  437. if (Math.abs(teamR.length - teamB.length) == teamS.length) {
  438. room.sendChat("🤖 No choices left, let me handle this situation... 🤖");
  439. deactivateChooseMode();
  440. resumeGame();
  441. var b = teamS.length;
  442. if (teamR.length > teamB.length) {
  443. for (var i = 0 ; i < b ; i++) {
  444. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.BLUE); }, 5*i);
  445. }
  446. }
  447. else {
  448. for (var i = 0 ; i < b ; i++) {
  449. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.RED); }, 5*i);
  450. }
  451. }
  452. return;
  453. }
  454. if (streak == 0 && room.getScores() == null) {
  455. if (Math.abs(teamR.length - teamB.length) == 2) { // if someone left a team has 2 more players than the other one, put the last chosen guy back in his place so it's fair
  456. room.sendChat("🤖 Balancing teams... 🤖");
  457. teamR.length > teamB.length ? room.setPlayerTeam(teamR[teamR.length - 1].id, Team.SPECTATORS) : room.setPlayerTeam(teamB[teamB.length - 1].id, Team.SPECTATORS);
  458. }
  459. }
  460. if (teamR.length == teamB.length && teamS.length < 2) {
  461. deactivateChooseMode();
  462. resumeGame();
  463. return;
  464. }
  465. capLeft ? choosePlayer() : getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
  466. }
  467. balanceTeams();
  468. }
  469.  
  470. function balanceTeams() {
  471. if (!inChooseMode) {
  472. if (players.length == 1 && teamR.length == 0) {
  473. quickRestart();
  474. loadMap(aloneMap, 0, 0);
  475. room.setPlayerTeam(players[0].id, Team.RED);
  476. }
  477. else if (Math.abs(teamR.length - teamB.length) == teamS.length && teamS.length > 0) {
  478. const n = Math.abs(teamR.length - teamB.length);
  479. if (players.length == 2) {
  480. quickRestart();
  481. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  482. }
  483. if (teamR.length > teamB.length) {
  484. for (var i = 0 ; i < n ; i++) {
  485. room.setPlayerTeam(teamS[i].id, Team.BLUE);
  486. }
  487. }
  488. else {
  489. for (var i = 0 ; i < n ; i++) {
  490. room.setPlayerTeam(teamS[i].id, Team.RED);
  491. }
  492. }
  493. }
  494. else if (Math.abs(teamR.length - teamB.length) > teamS.length) {
  495. const n = Math.abs(teamR.length - teamB.length);
  496. if (players.length == 1) {
  497. quickRestart();
  498. loadMap(aloneMap, 0, 0);
  499. room.setPlayerTeam(players[0].id, Team.RED);
  500. return;
  501. }
  502. else if (players.length == 5) {
  503. quickRestart();
  504. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  505. }
  506. if (players.length == maxTeamSize * 2 - 1) {
  507. allReds = [];
  508. allBlues = [];
  509. }
  510. if (teamR.length > teamB.length) {
  511. for (var i = 0 ; i < n ; i++) {
  512. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  513. }
  514. }
  515. else {
  516. for (var i = 0 ; i < n ; i++) {
  517. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  518. }
  519. }
  520. }
  521. else if (Math.abs(teamR.length - teamB.length) < teamS.length && teamR.length != teamB.length) {
  522. room.pauseGame(true);
  523. activateChooseMode();
  524. choosePlayer();
  525. }
  526. else if (teamS.length >= 2 && teamR.length == teamB.length && teamR.length < maxTeamSize) {
  527. if (teamR.length == 2) {
  528. quickRestart();
  529. loadMap(bigMap, scoreLimitBig, timeLimitBig);
  530. }
  531. topBtn();
  532. }
  533. }
  534. }
  535.  
  536. function choosePlayer() {
  537. clearTimeout(timeOutCap);
  538. if (teamR.length <= teamB.length && teamR.length != 0) {
  539. room.sendChat("[PV] To choose a player, enter his number in the list given or use 'top', 'random' or 'bottom'.", teamR[0].id);
  540. timeOutCap = setTimeout(function (player) { room.sendChat("[PV] Hurry up @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " seconds left to choose !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, "You didn't choose in time !", false); }, chooseTime * 500, teamR[0]); }, chooseTime * 1000, teamR[0]);
  541. }
  542. else if (teamB.length < teamR.length && teamB.length != 0) {
  543. room.sendChat("[PV] To choose a player, enter his number in the list given or use 'top', 'random' or 'bottom'.", teamB[0].id);
  544. timeOutCap = setTimeout(function (player) { room.sendChat("[PV] Hurry up @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " seconds left to choose !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, "You didn't choose in time !", false); }, chooseTime * 500, teamB[0]); }, chooseTime * 1000, teamB[0]);
  545. }
  546. if (teamR.length != 0 && teamB.length != 0) getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
  547. }
  548.  
  549. function getSpecList(player) {
  550. var cstm = "[PV] Players : ";
  551. for (var i = 0 ; i < teamS.length ; i++) {
  552. if (140 - cstm.length < (teamS[i].name + "[" + (i+1) + "], ").length) {
  553. room.sendChat(cstm, player.id);
  554. cstm = "... ";
  555. }
  556. cstm += teamS[i].name + "[" + (i+1) + "], ";
  557. }
  558. cstm = cstm.substring(0,cstm.length - 2);
  559. cstm += ".";
  560. room.sendChat(cstm, player.id);
  561. }
  562.  
  563. /* STATS FUNCTIONS */
  564.  
  565. function getLastTouchOfTheBall() {
  566. const ballPosition = room.getBallPosition();
  567. updateTeams();
  568. for (var i = 0; i < players.length; i++) {
  569. if (players[i].position != null) {
  570. var distanceToBall = pointDistance(players[i].position, ballPosition);
  571. if (distanceToBall < triggerDistance) {
  572. !activePlay ? activePlay = true : null;
  573. if (lastTeamTouched == players[i].team && lastPlayersTouched[0] != null && lastPlayersTouched[0].id != players[i].id) {
  574. lastPlayersTouched[1] = lastPlayersTouched[0];
  575. lastPlayersTouched[0] = players[i];
  576. }
  577. lastTeamTouched = players[i].team;
  578. }
  579. }
  580. }
  581. }
  582.  
  583. function getStats() { // gives possession, ball speed and GK of each team
  584. if (activePlay) {
  585. updateTeams();
  586. lastTeamTouched == Team.RED ? Rposs++ : Bposs++;
  587. var ballPosition = room.getBallPosition();
  588. point[1] = point[0];
  589. point[0] = ballPosition;
  590. ballSpeed = (pointDistance(point[0], point[1]) * 60 * 60 * 60)/15000;
  591. var k = [-1, Infinity];
  592. for (var i = 0; i < teamR.length; i++) {
  593. if (teamR[i].position.x < k[1]) {
  594. k[0] = teamR[i];
  595. k[1] = teamR[i].position.x;
  596. }
  597. }
  598. k[0] != -1 ? setGK(k[0], getGK(k[0]) + 1) : null;
  599. k = [-1, -Infinity];
  600. for (var i = 0; i < teamB.length; i++) {
  601. if (teamB[i].position.x > k[1]) {
  602. k[0] = teamB[i];
  603. k[1] = teamB[i].position.x;
  604. }
  605. }
  606. k[0] != -1 ? setGK(k[0], getGK(k[0]) + 1) : null;
  607. findGK();
  608. }
  609. }
  610.  
  611. function updateStats() {
  612. if (players.length >= 2 * maxTeamSize && (game.scores.time >= (5 / 6) * game.scores.timeLimit || game.scores.red == game.scores.scoreLimit || game.scores.blue == game.scores.scoreLimit) && allReds.length >= maxTeamSize && allBlues.length >= maxTeamSize) {
  613. var stats;
  614. for (var i = 0; i < allReds.length; i++) {
  615. localStorage.getItem(getAuth(allReds[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allReds[i]))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", allReds[i].name];
  616. stats[Ss.GA]++;
  617. lastWinner == Team.RED ? stats[Ss.WI]++ : lastWinner == Team.BLUE ? stats[Ss.LS]++ : stats[Ss.DR]++;
  618. stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
  619. localStorage.setItem(getAuth(allReds[i]), JSON.stringify(stats));
  620. }
  621. for (var i = 0; i < allBlues.length; i++) {
  622. localStorage.getItem(getAuth(allBlues[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allBlues[i]))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", allBlues[i].name];
  623. stats[Ss.GA]++;
  624. lastWinner == Team.BLUE ? stats[Ss.WI]++ : lastWinner == Team.RED ? stats[Ss.LS]++ : stats[Ss.DR]++;
  625. stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
  626. localStorage.setItem(getAuth(allBlues[i]), JSON.stringify(stats));
  627. }
  628. for (var i = 0; i < game.goals.length; i++) {
  629. if (game.goals[i].striker != null) {
  630. if ((allBlues.concat(allReds)).findIndex((player) => player.id == game.goals[i].striker.id) != -1) {
  631. stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].striker)));
  632. stats[Ss.GL]++;
  633. localStorage.setItem(getAuth(game.goals[i].striker), JSON.stringify(stats));
  634. }
  635. }
  636. if (game.goals[i].assist != null) {
  637. if ((allBlues.concat(allReds)).findIndex((player) => player.name == game.goals[i].assist.name) != -1) {
  638. stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].assist)));
  639. stats[Ss.AS]++;
  640. localStorage.setItem(getAuth(game.goals[i].assist), JSON.stringify(stats));
  641. }
  642. }
  643. }
  644. if (allReds.findIndex((player) => player.id == GKList[0].id) != -1) {
  645. stats = JSON.parse(localStorage.getItem(getAuth(GKList[0])));
  646. stats[Ss.GK]++;
  647. game.scores.blue == 0 ? stats[Ss.CS]++ : null;
  648. stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
  649. localStorage.setItem(getAuth(GKList[0]), JSON.stringify(stats));
  650. }
  651. if (allBlues.findIndex((player) => player.id == GKList[1].id) != -1) {
  652. stats = JSON.parse(localStorage.getItem(getAuth(GKList[1])));
  653. stats[Ss.GK]++;
  654. game.scores.red == 0 ? stats[Ss.CS]++ : null;
  655. stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
  656. localStorage.setItem(getAuth(GKList[1]), JSON.stringify(stats));
  657. }
  658. }
  659. }
  660.  
  661. function findGK() {
  662. var tab = [[-1,""], [-1,""]];
  663. for (var i = 0; i < extendedP.length ; i++) {
  664. if (room.getPlayer(extendedP[i][eP.ID]) != null && room.getPlayer(extendedP[i][eP.ID]).team == Team.RED) {
  665. if (tab[0][0] < extendedP[i][eP.GK]) {
  666. tab[0][0] = extendedP[i][eP.GK];
  667. tab[0][1] = room.getPlayer(extendedP[i][eP.ID]);
  668. }
  669. }
  670. else if (room.getPlayer(extendedP[i][eP.ID]) != null && room.getPlayer(extendedP[i][eP.ID]).team == Team.BLUE) {
  671. if (tab[1][0] < extendedP[i][eP.GK]) {
  672. tab[1][0] = extendedP[i][eP.GK];
  673. tab[1][1] = room.getPlayer(extendedP[i][eP.ID]);
  674. }
  675. }
  676. }
  677. GKList = [tab[0][1], tab[1][1]];
  678. }
  679.  
  680. setInterval(() => {
  681. var tableau = [];
  682. if (statNumber % 5 == 0) {
  683. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GA])]); } });
  684. if (tableau.length < 5) {
  685. return false;
  686. }
  687. tableau.sort(function (a, b) { return b[1] - a[1]; });
  688. room.sendChat("Games> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  689. }
  690. if (statNumber % 5 == 1) {
  691. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.WI])]); } });
  692. if (tableau.length < 5) {
  693. return false;
  694. }
  695. tableau.sort(function (a, b) { return b[1] - a[1]; });
  696. room.sendChat("Wins> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  697. }
  698. if (statNumber % 5 == 2) {
  699. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GL])]); } });
  700. if (tableau.length < 5) {
  701. return false;
  702. }
  703. tableau.sort(function (a, b) { return b[1] - a[1]; });
  704. room.sendChat("Goals> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  705. }
  706. if (statNumber % 5 == 3) {
  707. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.AS])]); } });
  708. if (tableau.length < 5) {
  709. return false;
  710. }
  711. tableau.sort(function (a, b) { return b[1] - a[1]; });
  712. room.sendChat("Assists> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  713. }
  714. if (statNumber % 5 == 4) {
  715. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.CS])]); } });
  716. if (tableau.length < 5) {
  717. return false;
  718. }
  719. tableau.sort(function (a, b) { return b[1] - a[1]; });
  720. room.sendChat("CS> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  721. }
  722. statNumber++;
  723. }, statInterval * 60 * 1000);
  724.  
  725. /* EVENTS */
  726.  
  727. /* PLAYER MOVEMENT */
  728.  
  729. room.onPlayerJoin = function(player) {
  730. extendedP.push([player.id, player.auth, player.conn, false, 0, 0, false]);
  731. updateRoleOnPlayerIn();
  732. room.sendChat("[PV] 👋 Welcome " + player.name + " ! Type '!help' to see the commands. [DISCORD: https://discord.gg/4fzgumN]", player.id);
  733. if (localStorage.getItem(player.auth) != null) {
  734. if (JSON.parse(localStorage.getItem(player.auth))[Ss.RL] != "player") {
  735. room.setPlayerAdmin(player.id, true);
  736. room.sendChat((JSON.parse(localStorage.getItem(player.auth))[Ss.RL] == "master" ? "Master " : "Admin ") + player.name + " has connected to the room !");
  737. }
  738. }
  739. }
  740.  
  741. room.onPlayerTeamChange = function(changedPlayer, byPlayer) {
  742. if (changedPlayer.id == 0) {
  743. room.setPlayerTeam(0, Team.SPECTATORS);
  744. return;
  745. }
  746. if (getAFK(changedPlayer) && changedPlayer.team != Team.SPECTATORS) {
  747. room.setPlayerTeam(changedPlayer.id, Team.SPECTATORS);
  748. room.sendChat(changedPlayer.name + " is AFK !");
  749. return;
  750. }
  751. updateTeams();
  752. if (room.getScores() != null) {
  753. var scores = room.getScores();
  754. if (changedPlayer.team != Team.SPECTATORS && scores.time <= (3/4) * scores.timeLimit && Math.abs(scores.blue - scores.red) < 2) {
  755. (changedPlayer.team == Team.RED) ? allReds.push(changedPlayer) : allBlues.push(changedPlayer);
  756. }
  757. }
  758. if (changedPlayer.team == Team.SPECTATORS) {
  759. setActivity(changedPlayer, 0);
  760. }
  761. if (inChooseMode && resettingTeams == false && byPlayer.id == 0) {
  762. if (Math.abs(teamR.length - teamB.length) == teamS.length) {
  763. deactivateChooseMode();
  764. resumeGame();
  765. var b = teamS.length;
  766. if (teamR.length > teamB.length) {
  767. for (var i = 0 ; i < b ; i++) {
  768. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.BLUE); }, 200*i);
  769. }
  770. }
  771. else {
  772. for (var i = 0 ; i < b ; i++) {
  773. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.RED); }, 200*i);
  774. }
  775. }
  776. return;
  777. }
  778. else if ((teamR.length == maxTeamSize && teamB.length == maxTeamSize) || (teamR.length == teamB.length && teamS.length < 2)) {
  779. deactivateChooseMode();
  780. resumeGame();
  781. }
  782. else if (teamR.length <= teamB.length && redCaptainChoice != "") { // choice remembered
  783. redCaptainChoice == "top" ? room.setPlayerTeam(teamS[0].id, Team.RED) : redCaptainChoice == "random" ? room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.RED) : room.setPlayerTeam(teamS[teamS.length - 1].id, Team.RED);
  784. return;
  785. }
  786. else if (teamB.length < teamR.length && blueCaptainChoice != "") {
  787. blueCaptainChoice == "top" ? room.setPlayerTeam(teamS[0].id, Team.BLUE) : blueCaptainChoice == "random" ? room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE) : room.setPlayerTeam(teamS[teamS.length - 1].id, Team.BLUE);
  788. return;
  789. }
  790. else {
  791. choosePlayer();
  792. }
  793. }
  794. }
  795.  
  796. room.onPlayerLeave = function(player) {
  797. if (teamR.findIndex((red) => red.id == player.id) == 0 && inChooseMode && teamR.length <= teamB.length) {
  798. choosePlayer();
  799. capLeft = true; setTimeout(() => { capLeft = false; }, 10);
  800. }
  801. if (teamB.findIndex((blue) => blue.id == player.id) == 0 && inChooseMode && teamB.length < teamR.length) {
  802. choosePlayer();
  803. capLeft = true; setTimeout(() => { capLeft = false; }, 10);
  804. }
  805. setActivity(player, 0);
  806. updateRoleOnPlayerOut();
  807. }
  808.  
  809. room.onPlayerKicked = function(kickedPlayer, reason, ban, byPlayer) {
  810. ban == true ? banList.push([kickedPlayer.name, kickedPlayer.id]) : null;
  811. }
  812.  
  813. /* PLAYER ACTIVITY */
  814.  
  815. room.onPlayerChat = function (player, message) {
  816. message = message.split(/ +/);
  817. player.team != Team.SPECTATORS ? setActivity(player, 0) : null;
  818. if (["!help"].includes(message[0].toLowerCase())) {
  819. room.sendChat("[PV] Player commands : !me, !games, !wins, !goals, !assists, !cs, !afks, !mutes, !bans.", player.id);
  820. player.admin ? room.sendChat("[PV] Admin : !mute <duration = 3> #<id>, !unmute all/#<id>, !clearbans <number = all>, !slow <duration>, !endslow", player.id) : null;
  821. }
  822. else if (["!afk"].includes(message[0].toLowerCase())) {
  823. if (players.length != 1 && player.team != Team.SPECTATORS) {
  824. if (player.team == Team.RED && streak > 0 && room.getScores() == null) {
  825. room.setPlayerTeam(player.id, Team.SPECTATORS);
  826. }
  827. else {
  828. room.sendChat("You can't go AFK while you're in a team !", player.id);
  829. return false;
  830. }
  831. }
  832. else if (players.length == 1 && !getAFK(player)) {
  833. room.setPlayerTeam(player.id, Team.SPECTATORS);
  834. }
  835. setAFK(player, !getAFK(player));
  836. room.sendChat(player.name + (getAFK(player) ? " is now AFK !" : " is not AFK anymore !"));
  837. getAFK(player) ? updateRoleOnPlayerOut() : updateRoleOnPlayerIn();
  838. }
  839. else if (["!afks", "!afklist"].includes(message[0].toLowerCase())) {
  840. var cstm = "[PV] AFK List : ";
  841. for (var i = 0; i < extendedP.length; i++) {
  842. if (room.getPlayer(extendedP[i][eP.ID]) != null && getAFK(room.getPlayer(extendedP[i][eP.ID]))) {
  843. if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + ", ").length) {
  844. room.sendChat(cstm, player.id);
  845. cstm = "... ";
  846. }
  847. cstm += room.getPlayer(extendedP[i][eP.ID]).name + ", ";
  848. }
  849. }
  850. if (cstm == "[PV] AFK List : ") {
  851. room.sendChat("[PV] There's nobody in the AFK List !", player.id);
  852. return false;
  853. }
  854. cstm = cstm.substring(0, cstm.length - 2);
  855. cstm += ".";
  856. room.sendChat(cstm, player.id);
  857. }
  858. else if (["!me"].includes(message[0].toLowerCase())) {
  859. var stats;
  860. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00"];
  861. room.sendChat("[PV] " + player.name + "> Game: " + stats[Ss.GA] + ", Win: " + stats[Ss.WI] + ", Draw: " + stats[Ss.DR] + ", Loss: " + stats[Ss.LS] + ", WR: " + stats[Ss.WR] + "%, Goal: " + stats[Ss.GL] + ", Assist: " + stats[Ss.AS] + ", GK: " + stats[Ss.GK] + ", CS: " + stats[Ss.CS] + ", CS%: " + stats[Ss.CP] + "%", player.id);
  862. }
  863. else if (["!games"].includes(message[0].toLowerCase())) {
  864. var tableau = [];
  865. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GA])]); } });
  866. if (tableau.length < 5) {
  867. room.sendChat("[PV] Not enough games played yet.", player.id);
  868. return false;
  869. }
  870. tableau.sort(function (a, b) { return b[1] - a[1]; });
  871. room.sendChat("[PV] Games> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id);
  872. }
  873. else if (["!wins"].includes(message[0].toLowerCase())) {
  874. var tableau = [];
  875. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.WI])]); } });
  876. if (tableau.length < 5) {
  877. room.sendChat("[PV] Not enough games played yet.", player.id);
  878. return false;
  879. }
  880. tableau.sort(function (a, b) { return b[1] - a[1]; });
  881. room.sendChat("[PV] Wins> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id);
  882. }
  883. else if (["!goals"].includes(message[0].toLowerCase())) {
  884. var tableau = [];
  885. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GL])]); } });
  886. if (tableau.length < 5) {
  887. room.sendChat("[PV] Not enough games played yet.", player.id);
  888. return false;
  889. }
  890. tableau.sort(function (a, b) { return b[1] - a[1]; });
  891. room.sendChat("[PV] Goals> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id);
  892. }
  893. else if (["!assists"].includes(message[0].toLowerCase())) {
  894. var tableau = [];
  895. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.AS])]); } });
  896. if (tableau.length < 5) {
  897. room.sendChat("[PV] Not enough games played yet.", player.id);
  898. return false;
  899. }
  900. tableau.sort(function (a, b) { return b[1] - a[1]; });
  901. room.sendChat("[PV] Assists> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id);
  902. }
  903. else if (["!cs"].includes(message[0].toLowerCase())) {
  904. var tableau = [];
  905. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.CS])]); } });
  906. if (tableau.length < 5) {
  907. room.sendChat("[PV] Not enough games played yet.", player.id);
  908. return false;
  909. }
  910. tableau.sort(function (a, b) { return b[1] - a[1]; });
  911. room.sendChat("[PV] CS> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id);
  912. }
  913. else if (["!claim"].includes(message[0].toLowerCase())) {
  914. if (message[1] == adminPassword) {
  915. room.setPlayerAdmin(player.id, true);
  916. var stats;
  917. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", player.name];
  918. if (stats[Ss.RL] != "master") {
  919. stats[Ss.RL] = "master";
  920. room.sendChat(player.name + " is now a room master !");
  921. localStorage.setItem(getAuth(player), JSON.stringify(stats));
  922. }
  923. }
  924. }
  925. else if (["!setadmin", "!admin"].includes(message[0].toLowerCase())) {
  926. if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
  927. if (message.length >= 2 && message[1][0] == "#") {
  928. message[1] = message[1].substring(1, message[1].length);
  929. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  930. var stats;
  931. localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1])))) ? stats = JSON.parse(localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1]))))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", room.getPlayer(Number.parseInt(message[1])).name];
  932. if (stats[Ss.RL] == "player") {
  933. stats[Ss.RL] = "admin";
  934. localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
  935. room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, true);
  936. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " is now an administrator of the room !");
  937. }
  938. }
  939. }
  940. }
  941. }
  942. else if (["!setplayer", "!removeadmin"].includes(message[0].toLowerCase())) {
  943. if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
  944. if (message.length >= 2 && message[1][0] == "#") {
  945. message[1] = message[1].substring(1, message[1].length);
  946. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  947. var stats;
  948. localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1])))) ? stats = JSON.parse(localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1]))))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", room.getPlayer(Number.parseInt(message[1])).name];
  949. if (stats[Ss.RL] == "admin") {
  950. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " is not an administrator of the room anymore !");
  951. stats[Ss.RL] = "player";
  952. localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
  953. room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, false);
  954. }
  955. }
  956. }
  957. }
  958. }
  959. else if (["!mutes", "!mutelist"].includes(message[0].toLowerCase())) {
  960. var cstm = "[PV] Mute List : ";
  961. for (var i = 0; i < extendedP.length; i++) {
  962. if (room.getPlayer(extendedP[i][eP.ID]) != null && getMute(room.getPlayer(extendedP[i][eP.ID]))) {
  963. if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ").length) {
  964. room.sendChat(cstm, player.id);
  965. cstm = "... ";
  966. }
  967. cstm += room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ";
  968. }
  969. }
  970. if (cstm == "[PV] Mute List : ") {
  971. room.sendChat("[PV] There's nobody in the Mute List !", player.id);
  972. return false;
  973. }
  974. cstm = cstm.substring(0, cstm.length - 2);
  975. cstm += ".";
  976. room.sendChat(cstm, player.id);
  977. }
  978. else if (["!mute"].includes(message[0].toLowerCase())) {
  979. if (player.admin) {
  980. updateTeams();
  981. var timeOut;
  982. if (!Number.isNaN(Number.parseInt(message[1])) && message.length > 1) {
  983. if (Number.parseInt(message[1]) > 0) {
  984. timeOut = Number.parseInt(message[1]) * 60 * 1000;
  985. }
  986. else {
  987. timeOut = 3 * 60 * 1000;
  988. }
  989. if (message[2].length > 1 && message[2][0] == "#") {
  990. message[2] = message[2].substring(1, message[2].length);
  991. if (!Number.isNaN(Number.parseInt(message[2])) && room.getPlayer(Number.parseInt(message[2])) != null) {
  992. if (room.getPlayer(Number.parseInt(message[2])).admin || getMute(room.getPlayer(Number.parseInt(message[2])))) {
  993. return false;
  994. }
  995. setTimeout(function (player) { setMute(player, false); }, timeOut, room.getPlayer(Number.parseInt(message[2])));
  996. setMute(room.getPlayer(Number.parseInt(message[2])), true);
  997. room.sendChat(room.getPlayer(Number.parseInt(message[2])).name + " has been muted for " + (timeOut / 60000) + " minutes!");
  998. }
  999. }
  1000. }
  1001. else if (Number.isNaN(Number.parseInt(message[1]))) {
  1002. if (message[1].length > 1 && message[1][0] == "#") {
  1003. message[1] = message[1].substring(1, message[1].length);
  1004. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  1005. if (room.getPlayer(Number.parseInt(message[1])).admin || getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1006. return false;
  1007. }
  1008. setTimeout(function (player) { setMute(player, false); }, 3 * 60 * 1000, room.getPlayer(Number.parseInt(message[1])));
  1009. setMute(room.getPlayer(Number.parseInt(message[1])), true);
  1010. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been muted for 3 minutes!");
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. else if (["!unmute"].includes(message[0].toLowerCase())) {
  1017. if (player.admin && message.length >= 2) {
  1018. if (message[1] == "all") {
  1019. extendedP.forEach((ePlayer) => { ePlayer[eP.MUTE] = false; });
  1020. room.sendChat("Mutes cleared.");
  1021. }
  1022. else if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1023. setMute(room.getPlayer(Number.parseInt(message[1])), false);
  1024. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
  1025. }
  1026. else if (Number.isNaN(Number.parseInt(message[1]))) {
  1027. if (message[1].length > 1 && message[1][0] == "#") {
  1028. message[1] = message[1].substring(1, message[1].length);
  1029. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1030. setMute(room.getPlayer(Number.parseInt(message[1])), false);
  1031. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. else if (["!slow"].includes(message[0].toLowerCase())) {
  1038. if (player.admin) {
  1039. if (message.length == 1) {
  1040. slowMode = 2;
  1041. room.sendChat("2 seconds slow mode enabled !");
  1042. }
  1043. else if (message.length == 2) {
  1044. if (!Number.isNaN(Number.parseInt(message[1]))) {
  1045. if (Number.parseInt(message[1]) > 0) {
  1046. slowMode = Number.parseInt(message[1]);
  1047. room.sendChat(slowMode + " seconds slow mode enabled !");
  1048. return false;
  1049. }
  1050. }
  1051. slowMode = 2;
  1052. room.sendChat("2 seconds slow mode enabled !");
  1053. }
  1054. }
  1055. }
  1056. else if (["!endslow"].includes(message[0].toLowerCase())) {
  1057. if (player.admin) {
  1058. slowMode != 0 ? room.sendChat("Slow mode terminated.") : null;
  1059. slowMode = 0;
  1060. }
  1061. }
  1062. else if (["!banlist", "!bans"].includes(message[0].toLowerCase())) {
  1063. if (banList.length == 0) {
  1064. room.sendChat("[PV] There's nobody in the Ban List !", player.id);
  1065. return false;
  1066. }
  1067. var cstm = "[PV] Ban List : ";
  1068. for (var i = 0; i < banList.length; i++) {
  1069. if (140 - cstm.length < (banList[i][0] + "[" + (banList[i][1]) + "], ").length) {
  1070. room.sendChat(cstm, player.id);
  1071. cstm = "... ";
  1072. }
  1073. cstm += banList[i][0] + "[" + (banList[i][1]) + "], ";
  1074. }
  1075. cstm = cstm.substring(0, cstm.length - 2);
  1076. cstm += ".";
  1077. room.sendChat(cstm, player.id);
  1078. }
  1079. else if (["!clearbans"].includes(message[0].toLowerCase())) {
  1080. if (player.admin) {
  1081. if (message.length == 1) {
  1082. room.clearBans();
  1083. room.sendChat("Bans cleared !");
  1084. banList = [];
  1085. }
  1086. if (message.length == 2) {
  1087. if (!Number.isNaN(Number.parseInt(message[1]))) {
  1088. if (Number.parseInt(message[1]) > 0) {
  1089. ID = Number.parseInt(message[1]);
  1090. room.clearBan(ID);
  1091. if (banList.length != banList.filter((array) => array[1] != ID)) {
  1092. room.sendChat(banList.filter((array) => array[1] == ID)[0][0] + " has been unbanned from the room !");
  1093. }
  1094. setTimeout(() => { banList = banList.filter((array) => array[1] != ID); }, 20);
  1095. }
  1096. }
  1097. }
  1098. }
  1099. }
  1100. else if (["!bb", "!bye", "!cya", "!gn"].includes(message[0].toLowerCase())) {
  1101. room.kickPlayer(player.id, "Bye !", false);
  1102. }
  1103. if (teamR.length != 0 && teamB.length != 0 && inChooseMode) {
  1104. if (player.id == teamR[0].id || player.id == teamB[0].id) { // we care if it's one of the captains choosing
  1105. if (teamR.length <= teamB.length && player.id == teamR[0].id) { // we care if it's red turn && red cap talking
  1106. if (["top", "auto"].includes(message[0].toLowerCase())) {
  1107. room.setPlayerTeam(teamS[0].id, Team.RED);
  1108. redCaptainChoice = "top";
  1109. clearTimeout(timeOutCap);
  1110. room.sendChat(player.name + " chose Top !");
  1111. return false;
  1112. }
  1113. else if (["random", "rand"].includes(message[0].toLowerCase())) {
  1114. var r = getRandomInt(teamS.length);
  1115. room.setPlayerTeam(teamS[r].id, Team.RED);
  1116. redCaptainChoice = "random";
  1117. clearTimeout(timeOutCap);
  1118. room.sendChat(player.name + " chose Random !");
  1119. return false;
  1120. }
  1121. else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
  1122. room.setPlayerTeam(teamS[teamS.length - 1].id, Team.RED);
  1123. redCaptainChoice = "bottom";
  1124. clearTimeout(timeOutCap);
  1125. room.sendChat(player.name + " chose Bottom !");
  1126. return false;
  1127. }
  1128. else if (!Number.isNaN(Number.parseInt(message[0]))) {
  1129. if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
  1130. room.sendChat("[PV] Your number is invalid !", player.id);
  1131. return false;
  1132. }
  1133. else {
  1134. room.setPlayerTeam(teamS[Number.parseInt(message[0]) - 1].id, Team.RED);
  1135. room.sendChat(player.name + " chose " + teamS[Number.parseInt(message[0]) - 1].name + " !");
  1136. return false;
  1137. }
  1138. }
  1139. }
  1140. if (teamR.length > teamB.length && player.id == teamB[0].id) { // we care if it's red turn && red cap talking
  1141. if (["top", "auto"].includes(message[0].toLowerCase())) {
  1142. room.setPlayerTeam(teamS[0].id, Team.BLUE);
  1143. blueCaptainChoice = "top";
  1144. clearTimeout(timeOutCap);
  1145. room.sendChat(player.name + " chose Top !");
  1146. return false;
  1147. }
  1148. else if (["random", "rand"].includes(message[0].toLowerCase())) {
  1149. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE);
  1150. blueCaptainChoice = "random";
  1151. clearTimeout(timeOutCap);
  1152. room.sendChat(player.name + " chose Random !");
  1153. return false;
  1154. }
  1155. else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
  1156. room.setPlayerTeam(teamS[teamS.length - 1].id, Team.BLUE);
  1157. blueCaptainChoice = "bottom";
  1158. clearTimeout(timeOutCap);
  1159. room.sendChat(player.name + " chose Bottom !");
  1160. return false;
  1161. }
  1162. else if (!Number.isNaN(Number.parseInt(message[0]))) {
  1163. if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
  1164. room.sendChat("[PV] Your number is invalid !", player.id);
  1165. return false;
  1166. }
  1167. else {
  1168. room.setPlayerTeam(teamS[Number.parseInt(message[0]) - 1].id, Team.BLUE);
  1169. room.sendChat(player.name + " chose " + teamS[Number.parseInt(message[0]) - 1].name + " !");
  1170. return false;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. }
  1176. if (message[0][0] == "!") {
  1177. return false;
  1178. }
  1179. if (getMute(player)) {
  1180. room.sendChat("You are muted.", player.id);
  1181. return false;
  1182. }
  1183. if (slowMode > 0) {
  1184. if (!player.admin) {
  1185. if (!SMSet.has(player.id)) {
  1186. SMSet.add(player.id);
  1187. setTimeout((number) => { SMSet.delete(number); }, slowMode * 1000, player.id);
  1188. }
  1189. else {
  1190. return false;
  1191. }
  1192. }
  1193. }
  1194. }
  1195.  
  1196. room.onPlayerActivity = function(player) {
  1197. setActivity(player, 0);
  1198. }
  1199.  
  1200. room.onPlayerBallKick = function(player) {
  1201. if (lastPlayersTouched[0] == null || player.id != lastPlayersTouched[0].id) {
  1202. !activePlay ? activePlay = true : null;
  1203. lastTeamTouched = player.team;
  1204. lastPlayersTouched[1] = lastPlayersTouched[0];
  1205. lastPlayersTouched[0] = player;
  1206. }
  1207. }
  1208.  
  1209. /* GAME MANAGEMENT */
  1210.  
  1211. room.onGameStart = function(byPlayer) {
  1212. game = new Game(Date.now(), room.getScores(), []);
  1213. countAFK = true;
  1214. activePlay = false;
  1215. goldenGoal = false;
  1216. endGameVariable = false;
  1217. lastPlayersTouched = [null, null];
  1218. Rposs = 0;
  1219. Bposs = 0;
  1220. GKList = [];
  1221. allReds = [];
  1222. allBlues = [];
  1223. if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) {
  1224. for (var i = 0; i < maxTeamSize; i++) {
  1225. allReds.push(teamR[i]);
  1226. allBlues.push(teamB[i]);
  1227. }
  1228. }
  1229. for (var i = 0; i < extendedP.length; i++) {
  1230. extendedP[i][eP.GK] = 0;
  1231. extendedP[i][eP.ACT] = 0;
  1232. room.getPlayer(extendedP[i][eP.ID]) == null ? extendedP.splice(i, 1) : null;
  1233. }
  1234. deactivateChooseMode();
  1235. }
  1236.  
  1237. room.onGameStop = function(byPlayer) {
  1238. if (byPlayer.id == 0 && endGameVariable) {
  1239. updateTeams();
  1240. if (inChooseMode) {
  1241. if (players.length == 2 * maxTeamSize) {
  1242. inChooseMode = false;
  1243. resetBtn();
  1244. for (var i = 0; i < maxTeamSize; i++) {
  1245. setTimeout(() => { randomBtn(); }, 400*i);
  1246. }
  1247. setTimeout(() => { room.startGame(); }, 2000);
  1248. }
  1249. else {
  1250. if (lastWinner == Team.RED) {
  1251. blueToSpecBtn();
  1252. }
  1253. else if (lastWinner == Team.BLUE) {
  1254. redToSpecBtn();
  1255. blueToRedBtn();
  1256. }
  1257. else {
  1258. resetBtn();
  1259. }
  1260. setTimeout(() => { topBtn(); }, 500);
  1261. }
  1262. }
  1263. else {
  1264. if (players.length == 2) {
  1265. if (lastWinner == Team.BLUE) {
  1266. room.setPlayerTeam(teamB[0].id, Team.RED);
  1267. room.setPlayerTeam(teamR[0].id, Team.BLUE);
  1268. }
  1269. setTimeout(() => { room.startGame(); }, 2000);
  1270. }
  1271. else if (players.length == 3 || players.length >= 2 * maxTeamSize + 1) {
  1272. if (lastWinner == Team.RED) {
  1273. blueToSpecBtn();
  1274. }
  1275. else {
  1276. redToSpecBtn();
  1277. blueToRedBtn();
  1278. }
  1279. setTimeout(() => { topBtn(); }, 200);
  1280. setTimeout(() => { room.startGame(); }, 2000);
  1281. }
  1282. else if (players.length == 4) {
  1283. resetBtn();
  1284. setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500);
  1285. setTimeout(() => { room.startGame(); }, 2000);
  1286. }
  1287. else if (players.length == 5 || players.length >= 2 * maxTeamSize + 1) {
  1288. if (lastWinner == Team.RED) {
  1289. blueToSpecBtn();
  1290. }
  1291. else {
  1292. redToSpecBtn();
  1293. blueToRedBtn();
  1294. }
  1295. setTimeout(() => { topBtn(); }, 200);
  1296. activateChooseMode();
  1297. }
  1298. else if (players.length == 6) {
  1299. resetBtn();
  1300. setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500); }, 500);
  1301. setTimeout(() => { room.startGame(); }, 2000);
  1302. }
  1303. }
  1304. }
  1305. }
  1306.  
  1307. room.onGamePause = function(byPlayer) {
  1308. }
  1309.  
  1310. room.onGameUnpause = function (byPlayer) {
  1311. if (teamR.length == 4 && teamB.length == 4 && inChooseMode || (teamR.length == teamB.length && teamS.length < 2 && inChooseMode)) {
  1312. deactivateChooseMode();
  1313. }
  1314. }
  1315.  
  1316. room.onTeamGoal = function(team) {
  1317. activePlay = false;
  1318. countAFK = false;
  1319. const scores = room.getScores();
  1320. game.scores = scores;
  1321. if (lastPlayersTouched[0] != null && lastPlayersTouched[0].team == team) {
  1322. if (lastPlayersTouched[1] != null && lastPlayersTouched[1].team == team) {
  1323. room.sendChat("🤾 " + getTime(scores) + " Goal by " + lastPlayersTouched[0].name + " ! Assist by " + lastPlayersTouched[1].name + ". Goal speed : " + ballSpeed.toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1324. game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], lastPlayersTouched[1]));
  1325. }
  1326. else {
  1327. room.sendChat("🤾 " + getTime(scores) + " Goal by " + lastPlayersTouched[0].name + " ! Goal speed : " + ballSpeed.toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1328. game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], null));
  1329. }
  1330. }
  1331. else {
  1332. room.sendChat("😂 " + getTime(scores) + " Own Goal by " + lastPlayersTouched[0].name + " ! Goal speed : " + ballSpeed.toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1333. game.goals.push(new Goal(scores.time, team, null, null));
  1334. }
  1335. if (scores.scoreLimit != 0 && (scores.red == scores.scoreLimit || scores.blue == scores.scoreLimit && scores.blue > 0 || goldenGoal == true)) {
  1336. endGame(team);
  1337. goldenGoal = false;
  1338. setTimeout(() => { room.stopGame(); }, 1000);
  1339. }
  1340. }
  1341.  
  1342. room.onPositionsReset = function() {
  1343. countAFK = true;
  1344. lastPlayersTouched = [null, null];
  1345. }
  1346.  
  1347. /* MISCELLANEOUS */
  1348.  
  1349. room.onRoomLink = function(url) {
  1350. }
  1351.  
  1352. room.onPlayerAdminChange = function (changedPlayer, byPlayer) {
  1353. if (getMute(changedPlayer) && changedPlayer.admin) {
  1354. room.sendChat(changedPlayer.name + " has been unmuted.");
  1355. setMute(changedPlayer, false);
  1356. }
  1357. if (byPlayer.id != 0 && localStorage.getItem(getAuth(byPlayer)) && JSON.parse(localStorage.getItem(getAuth(byPlayer)))[Ss.RL] == "admin") {
  1358. room.sendChat("You don't have permission to name a player admin !", byPlayer.id);
  1359. room.setPlayerAdmin(changedPlayer.id, false);
  1360. }
  1361. }
  1362.  
  1363. room.onStadiumChange = function(newStadiumName, byPlayer) {
  1364. }
  1365.  
  1366. room.onGameTick = function() {
  1367. checkTime();
  1368. getLastTouchOfTheBall();
  1369. getStats();
  1370. handleInactivity();
  1371. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement