Advertisement
Guest User

Untitled

a guest
Oct 29th, 2019
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 103.65 KB | None | 0 0
  1. // Stats: "Auth" : '["0-Games", "1-Wins", "2-Losses", "3-Winrate", "4-Goals", "5-Assists", "6-GK", "7-CS", "8-CS%", "9-Streak, ""10-Role", "11-Nick"]'
  2. // Streak : "streak" : '["0-streakNumber", "1-["0-playerName", "1-playerID", "2-playerStreak"]"]'
  3.  
  4. /* VARIABLES */
  5.  
  6. /* ROOM */
  7.  
  8. const roomName = "🍥 REAL SOCCER 4v4 ES/EU | AutoBOT ! 🍥";
  9. const botName = "ESP Referee";
  10. const maxPlayers = 17;
  11. const roomPublic = true;
  12. const token = "";
  13. const geo = [{"code": "ES", "lat": 42.1, "lon": 4.2}];
  14. if (typeof token !== 'undefined') var room = HBInit({ roomName: roomName, token: token, maxPlayers: maxPlayers, public: roomPublic, playerName: botName, geo: geo[0] });
  15. else var room = HBInit({ roomName: roomName, maxPlayers: maxPlayers, public: roomPublic, playerName: botName, geo: geo[0] });
  16. const scoreLimitClassic = 3;
  17. const scoreLimitBig = 3;
  18. const timeLimitClassic = 3;
  19. const timeLimitBig = 5;
  20. const password = 'test' // Contraseña para cuando se llene la sala
  21.  
  22. room.setTeamsLock(true);
  23. var masterPassword = 10000 + getRandomInt(90000);
  24. var adminPassword = 10000 + getRandomInt(90000);
  25.  
  26. while (adminPassword == masterPassword) {
  27. adminPassword = 10000 + getRandomInt(90000);
  28. }
  29.  
  30. /* STADIUM */
  31.  
  32. const playerRadius = 15;
  33. var ballRadius = 9.8;
  34. const triggerDistance = playerRadius + ballRadius + 0.01;
  35. var aloneMap = '{"name":"Classic Training","width":420,"height":200,"spawnDistance":170,"bg":{"type":"grass","width":370,"height":170,"kickOffRadius":75,"cornerRadius":0},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":-370,"y":-64,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":170,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":370,"y":-64,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":75,"trait":"kickOffBarrier"},{"x":0,"y":-75,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"}],"segments":[{"v0":0,"v1":1,"trait":"ballArea"},{"v0":4,"v1":5,"trait":"ballArea"},{"v0":8,"v1":9,"trait":"kickOffBarrier"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":10,"v1":11,"trait":"kickOffBarrier"}],"goals":[],"discs":[{"pos":[-370,64],"trait":"goalPost","color":"FFCCCC"},{"pos":[-370,-64],"trait":"goalPost","color":"FFCCCC"},{"pos":[370,64],"trait":"goalPost","color":"CCCCFF"},{"pos":[370,-64],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-170,"trait":"ballArea"},{"normal":[0,-1],"dist":-170,"trait":"ballArea"},{"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}],"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"]}}}';
  36. var classicMap = '';
  37. var bigMap = '{"name":"RSHL Real Soccer","width":1300,"height":670,"spawnDistance":500,"bg":{"type":"grass","width":1150,"height":600,"kickOffRadius":180,"cornerRadius":0},"playerPhysics":{"bCoef":.5,"invMass":.5,"damping":.96,"acceleration":.12,"kickingAcceleration":.07,"kickingDamping":.96,"kickStrength":5.65},"vertexes":[{"x":0,"y":700,"trait":"kickOffBarrier"},{"x":0,"y":180,"trait":"kickOffBarrier"},{"x":0,"y":-180,"trait":"kickOffBarrier"},{"x":0,"y":-700,"trait":"kickOffBarrier"},{"x":1150,"y":255,"trait":"line"},{"x":840,"y":255,"trait":"line"},{"x":1150,"y":-255,"trait":"line"},{"x":840,"y":-255,"trait":"line"},{"x":1150,"y":155,"trait":"line"},{"x":1030,"y":155,"trait":"line"},{"x":1150,"y":-155,"trait":"line"},{"x":1030,"y":-155,"trait":"line"},{"x":840,"y":-135,"trait":"line","curve":-130},{"x":840,"y":135,"trait":"line","curve":-130},{"x":-1150,"y":-255,"trait":"line","curve":-90,"color":"97AC86"},{"x":-840,"y":-255,"trait":"line"},{"x":-1150,"y":255,"trait":"line"},{"x":-840,"y":255,"trait":"line"},{"x":-1150,"y":-155,"trait":"line"},{"x":-1030,"y":-155,"trait":"line"},{"x":-1150,"y":155,"trait":"line"},{"x":-1030,"y":155,"trait":"line"},{"x":-840,"y":135,"trait":"line","curve":-130},{"x":-840,"y":-135,"trait":"line","curve":-130},{"x":935,"y":4,"trait":"line"},{"x":935,"y":-4,"trait":"line"},{"x":-935,"y":4,"trait":"line"},{"x":-935,"y":-4,"trait":"line"},{"x":-1150,"y":525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1075,"y":600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1075,"y":-600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1150,"y":-525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1075,"y":600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1150,"y":525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1150,"y":-525,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":1075,"y":-600,"bCoef":0,"cMask":["wall"],"trait":"line"},{"x":-1150,"y":127,"trait":"line","color":"ffffff"},{"x":-1214,"y":124,"trait":"line","color":"ffffff","curve":5},{"x":-1150,"y":-127,"trait":"line","color":"ffffff"},{"x":-1214,"y":-124,"trait":"line","color":"ffffff","curve":5},{"x":1150,"y":127,"trait":"line","color":"ffffff"},{"x":1214,"y":124,"trait":"line","color":"ffffff","curve":-5},{"x":1150,"y":-127,"trait":"line","color":"ffffff"},{"x":1214,"y":-124,"trait":"line","color":"ffffff","curve":-5},{"x":0,"y":-4,"trait":"line"},{"x":0,"y":4,"trait":"line"},{"x":0,"y":-4,"trait":"line"},{"x":0,"y":4,"trait":"line"},{"x":-1214,"y":124,"trait":"line","color":"ffffff"},{"x":-1250,"y":150,"trait":"line","color":"ffffff","pos":[-1250,150]},{"x":-1214,"y":-124,"trait":"line","color":"ffffff"},{"x":-1250,"y":-150,"trait":"line","color":"ffffff","pos":[-1250,-150]},{"x":1214,"y":124,"trait":"line","color":"ffffff"},{"x":1250,"y":150,"trait":"line","color":"ffffff"},{"x":1214,"y":-124,"trait":"line","color":"ffffff"},{"x":1250,"y":-150,"trait":"line","color":"ffffff"},{"x":-1185,"y":155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":-1185,"y":255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":1185,"y":155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":1185,"y":255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":-1185,"y":-155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":-1185,"y":-255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":-40,"color":"BEB86C"},{"x":1185,"y":-155,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":1185,"y":-255,"bCoef":-4.5,"cMask":["ball"],"trait":"line","curve":40,"color":"BEB86C"},{"x":1158,"y":-607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":1187,"y":-578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":-60,"color":"BEB86C"},{"x":1158,"y":607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":1187,"y":578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":60,"color":"BEB86C"},{"x":-1158,"y":607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":-1187,"y":578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":-60,"color":"BEB86C"},{"x":-1158,"y":-607,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":0,"color":"BEB86C"},{"x":-1187,"y":-578,"bCoef":-2.45,"cMask":["ball"],"trait":"line","curve":60,"color":"BEB86C"},{"x":-1190,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1190,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1190,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1190,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1180,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":-255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":-155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":255,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1190,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":1180,"y":155,"bCoef":-1,"cMask":["ball"],"trait":"line","color":"000000","curve":0},{"x":-1148,"y":-525,"trait":"line","curve":-90,"color":"5E844D"},{"x":1148,"y":-525,"trait":"line","color":"5E844D"},{"x":-1148,"y":525,"trait":"line","curve":-90,"color":"5E844D"},{"x":1148,"y":525,"trait":"line","color":"5E844D"},{"x":-1150,"y":-260,"trait":"line","curve":-90,"color":"5E844D"},{"x":-810,"y":-600,"trait":"line","color":"5E844D","curve":-90},{"x":-1150,"y":260,"trait":"line","curve":90,"color":"5E844D"},{"x":-810,"y":600,"trait":"line","color":"5E844D","curve":90},{"x":-840,"y":-1150,"trait":"line","color":"5E844D","curve":-100},{"x":1150,"y":-260,"trait":"line","curve":90,"color":"5E844D"},{"x":810,"y":-600,"trait":"line","color":"5E844D","curve":90,"_selected":true},{"x":1150,"y":260,"trait":"line","curve":-90,"color":"5E844D"},{"x":810,"y":600,"trait":"line","color":"5E844D","curve":-90}],"segments":[{"v0":37,"v1":39,"curve":5,"color":"ffffff","trait":"reargoalNetleft","x":-1210},{"v0":41,"v1":43,"curve":-5,"color":"ffffff","trait":"reargoalNetright"},{"v0":4,"v1":5,"trait":"line","y":250},{"v0":5,"v1":7,"trait":"line","x":840},{"v0":6,"v1":7,"trait":"line","y":-250},{"v0":8,"v1":9,"trait":"line","y":150},{"v0":9,"v1":11,"trait":"line","x":1030},{"v0":10,"v1":11,"trait":"line","y":-150},{"v0":12,"v1":13,"curve":-130,"trait":"line","x":840},{"v0":14,"v1":15,"trait":"line","y":-250},{"v0":15,"v1":17,"trait":"line","x":-840},{"v0":16,"v1":17,"trait":"line","y":250},{"v0":18,"v1":19,"trait":"line","y":-150},{"v0":19,"v1":21,"trait":"line","x":-1030},{"v0":20,"v1":21,"trait":"line","y":150},{"v0":22,"v1":23,"curve":-130,"trait":"line","x":-840},{"v0":24,"v1":25,"curve":-180,"trait":"line","x":935},{"v0":26,"v1":27,"curve":-180,"trait":"line","x":-935},{"v0":24,"v1":25,"curve":180,"trait":"line","x":935},{"v0":26,"v1":27,"curve":180,"trait":"line","x":-935},{"v0":24,"v1":25,"curve":90,"trait":"line","x":935},{"v0":26,"v1":27,"curve":90,"trait":"line","x":-935},{"v0":24,"v1":25,"curve":-90,"trait":"line","x":935},{"v0":26,"v1":27,"curve":-90,"trait":"line","x":-935},{"v0":24,"v1":25,"trait":"line","x":935},{"v0":26,"v1":27,"trait":"line","x":-935},{"v0":28,"v1":29,"curve":90,"bCoef":0,"cMask":["wall"],"trait":"line"},{"v0":30,"v1":31,"curve":90,"bCoef":0,"cMask":["wall"],"trait":"line"},{"v0":32,"v1":33,"curve":90,"bCoef":0,"cMask":["wall"],"trait":"line"},{"v0":34,"v1":35,"curve":90,"bCoef":0,"cMask":["wall"],"trait":"line"},{"v0":36,"v1":37,"curve":5,"color":"ffffff","trait":"sidegoalNet"},{"v0":38,"v1":39,"curve":-5,"color":"ffffff","trait":"sidegoalNet"},{"v0":40,"v1":41,"curve":-5,"color":"ffffff","trait":"sidegoalNet"},{"v0":42,"v1":43,"curve":5,"color":"ffffff","trait":"sidegoalNet"},{"v0":44,"v1":45,"curve":-180,"trait":"line"},{"v0":46,"v1":47,"curve":180,"trait":"line"},{"v0":44,"v1":45,"curve":-90,"trait":"line"},{"v0":46,"v1":47,"curve":90,"trait":"line"},{"v0":48,"v1":49,"color":"ffffff","trait":"line"},{"v0":50,"v1":51,"color":"ffffff","trait":"line"},{"v0":52,"v1":53,"color":"ffffff","trait":"line"},{"v0":54,"v1":55,"color":"ffffff","trait":"line"},{"v0":56,"v1":57,"curve":40,"vis":true,"color":"BEB86C","bCoef":-4.7,"cMask":["ball"],"trait":"line","x":-1220},{"v0":58,"v1":59,"curve":-40,"vis":true,"color":"BEB86C","bCoef":-4.7,"cMask":["ball"],"trait":"line","x":1220},{"v0":60,"v1":61,"curve":-40,"vis":true,"color":"BEB86C","bCoef":-4.7,"cMask":["ball"],"trait":"line","x":-1220},{"v0":62,"v1":63,"curve":40,"vis":true,"color":"BEB86C","bCoef":-4.7,"cMask":["ball"],"trait":"line","x":1220},{"v0":64,"v1":65,"curve":-60,"vis":true,"color":"BEB86C","bCoef":-2.45,"cMask":["ball"],"trait":"line"},{"v0":66,"v1":67,"curve":60,"vis":true,"color":"BEB86C","bCoef":-2.45,"cMask":["ball"],"trait":"line"},{"v0":68,"v1":69,"curve":-60,"vis":true,"color":"BEB86C","bCoef":-2.45,"cMask":["ball"],"trait":"line"},{"v0":70,"v1":71,"curve":60,"vis":true,"color":"BEB86C","bCoef":-2.45,"cMask":["ball"],"trait":"line"},{"v0":0,"v1":1,"trait":"kickOffBarrier"},{"v0":1,"v1":2,"curve":180,"cGroup":["blueKO"],"trait":"kickOffBarrier"},{"v0":1,"v1":2,"curve":-180,"cGroup":["redKO"],"trait":"kickOffBarrier"},{"v0":2,"v1":3,"trait":"kickOffBarrier"},{"v0":72,"v1":73,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":74,"v1":75,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":76,"v1":77,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":78,"v1":79,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":80,"v1":81,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":82,"v1":83,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":84,"v1":85,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":86,"v1":87,"curve":0,"vis":true,"color":"000000","bCoef":-1,"cMask":["ball"],"trait":"line"},{"v0":88,"v1":89,"color":"5E844D","trait":"line","y":-475},{"v0":90,"v1":91,"color":"5E844D","trait":"line","y":-475},{"v0":92,"v1":93,"curve":-90,"color":"5E844D","trait":"line","y":-475},{"v0":94,"v1":95,"curve":90,"color":"5E844D","trait":"line","y":-475},{"v0":97,"v1":98,"curve":90,"color":"5E844D","trait":"line","y":-475},{"v0":99,"v1":100,"curve":-90,"color":"5E844D","trait":"line","y":-475}],"goals":[{"p0":[-1160,-124],"p1":[-1160,124],"team":"red"},{"p0":[1160,124],"p1":[1160,-124],"team":"blue"}],"discs":[{"pos":[-1150,127],"color":"FF0000","bCoef":.5,"trait":"goalPost"},{"pos":[-1150,-127],"color":"FF0000","bCoef":.5,"trait":"goalPost"},{"pos":[1150,127],"color":"0000FF","bCoef":.5,"trait":"goalPost"},{"pos":[1150,-127],"color":"0000FF","bCoef":.5,"trait":"goalPost"},{"pos":[-1250,150],"color":"FF0000","trait":"stanchion"},{"pos":[-1250,-150],"color":"FF0000","trait":"stanchion"},{"pos":[1250,150],"color":"0000FF","trait":"stanchion","x":1250},{"pos":[1250,-150],"color":"0000FF","trait":"stanchion","x":1250},{"radius":2,"invMass":0,"pos":[-1150,-600],"color":"FFFFFF","bCoef":-.1,"cMask":["ball"],"trait":"goalPost"},{"radius":2,"invMass":0,"pos":[-1150,600],"color":"FFFFFF","bCoef":-.1,"cMask":["ball"],"trait":"goalPost"},{"radius":2,"invMass":0,"pos":[1150,-600],"color":"FFFFFF","bCoef":-.1,"cMask":["ball"],"trait":"goalPost"},{"radius":2,"invMass":0,"pos":[1150,600],"color":"FFFFFF","bCoef":-.1,"cMask":["ball"],"trait":"goalPost"}],"planes":[{"normal":[0,1],"dist":-635,"bCoef":0,"trait":"ballArea"},{"normal":[0,-1],"dist":-635,"bCoef":0,"trait":"ballArea"},{"normal":[0,1],"dist":-670,"bCoef":0},{"normal":[0,-1],"dist":-670,"bCoef":0},{"normal":[1,0],"dist":-1300,"bCoef":0},{"normal":[-1,0],"dist":-1300,"bCoef":.1},{"normal":[1,0],"dist":-1214,"bCoef":0,"cMask":["ball"]},{"normal":[-1,0],"dist":-1214,"bCoef":0,"cMask":["ball"]}],"traits":{"ballArea":{"vis":false,"bCoef":0,"cMask":["ball"]},"goalPost":{"radius":5,"invMass":0,"bCoef":2},"stanchion":{"radius":3,"invMass":0,"bCoef":3,"cMask":["none"]},"cornerflag":{"radius":3,"invMass":0,"bCoef":.5,"color":"FFFF00","cGroup":[]},"reargoalNetleft":{"vis":true,"bCoef":.1,"cMask":["ball","red","blue"],"curve":10,"color":"C7E6BD"},"reargoalNetright":{"vis":true,"bCoef":.1,"cMask":["ball","red","blue"],"curve":-10,"color":"C7E6BD"},"sidegoalNet":{"vis":true,"bCoef":1,"cMask":["ball","red","blue"],"color":"C7E6BD"},"kickOffBarrier":{"vis":false,"bCoef":.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]},"line":{"vis":true,"cMask":[],"color":"C7E6BD"},"tunnel":{"vis":true,"cMask":["red","blue"],"color":"000000"},"advertising":{"vis":true,"cMask":["red","blue"],"color":"333333"},"teambench":{"vis":true,"cMask":[],"color":"000000"},"manager":{"radius":15,"vis":true,"cMask":["red","blue"],"invMass":0,"color":"333333"},"physio":{"radius":15,"vis":true,"cMask":["red","blue"],"invMass":0,"color":"666666"},"redsubs":{"radius":15,"vis":true,"cMask":["red","blue"],"invMass":0,"color":"E56E56"},"bluesubs":{"radius":15,"vis":true,"cMask":["red","blue"],"invMass":0,"color":"5689E5"}},"ballPhysics":{"invMass":1.05,"radius":9.8}}';
  38. var penaltyMap = '{"name":"HBF Penalty","width":500,"height":620,"spawnDistance":250,"bg":{"type":"grass","width":350,"height":600,"kickOffRadius":1,"cornerRadius":0},"playerPhysics":{"bCoef":.5,"invMass":.5,"damping":.96,"acceleration":.12,"kickingAcceleration":.07,"kickingDamping":.96,"kickStrength":5.65},"ballPhysics":{"radius":9.8,"bCoef":.5,"invMass":1,"damping":.99,"color":"FFFFFF","cMask":["all"],"cGroup":["ball"]},"vertexes":[{"x":275,"y":-110,"trait":"goalNet"},{"x":215,"y":-110,"trait":"goalNet"},{"x":275,"y":110,"trait":"goalNet"},{"x":215,"y":110,"trait":"goalNet"},{"x":315,"y":150,"trait":"cord"},{"x":315,"y":-150,"trait":"cord"},{"x":215,"y":150,"trait":"line"},{"x":85,"y":150,"trait":"line"},{"x":215,"y":-150,"trait":"line"},{"x":85,"y":-150,"trait":"line"},{"x":215,"y":260,"trait":"line"},{"x":-95,"y":260,"trait":"line"},{"x":215,"y":-260,"trait":"line"},{"x":-95,"y":-260,"trait":"line"},{"x":-95,"y":130,"trait":"line"},{"x":-95,"y":-130,"trait":"line"},{"x":-350,"y":-520,"trait":"hline"},{"x":213,"y":-520,"trait":"hline"},{"x":-350,"y":520,"trait":"hline"},{"x":213,"y":520,"trait":"hline"},{"x":-95,"y":598,"trait":"hline"},{"x":213,"y":290,"trait":"hline"},{"x":-95,"y":-598,"trait":"hline"},{"x":213,"y":-290,"trait":"hline"},{"x":265,"y":570,"trait":"cLauncher"},{"x":235,"y":600,"trait":"cLauncher"},{"x":235,"y":610,"trait":"stop"},{"x":275,"y":570,"trait":"stop"},{"x":265,"y":-570,"trait":"cLauncher"},{"x":235,"y":-600,"trait":"cLauncher"},{"x":235,"y":-610,"trait":"stop"},{"x":275,"y":-570,"trait":"stop"},{"x":255,"y":160,"trait":"stop"},{"x":255,"y":250,"trait":"stop"},{"x":260,"y":250,"trait":"stop"},{"x":250,"y":250,"trait":"stop"},{"x":260,"y":160,"trait":"stop"},{"x":250,"y":160,"trait":"stop"},{"x":255,"y":-160,"trait":"stop"},{"x":255,"y":-250,"trait":"stop"},{"x":260,"y":-250,"trait":"stop"},{"x":250,"y":-250,"trait":"stop"},{"x":260,"y":-160,"trait":"stop"},{"x":250,"y":-160,"trait":"stop"},{"x":215,"y":-580,"trait":"line"},{"x":195,"y":-600,"trait":"line"},{"x":215,"y":580,"trait":"line"},{"x":195,"y":600,"trait":"line"},{"x":0,"y":4,"trait":"line","color":"6A8F59","vis":true},{"x":0,"y":-4,"trait":"line"},{"x":0,"y":-257,"trait":"line"},{"x":0,"y":-7,"trait":"line"},{"x":0,"y":7,"trait":"line"},{"x":0,"y":257,"trait":"line"},{"x":0,"y":263,"trait":"line"},{"x":0,"y":597,"trait":"line"},{"x":0,"y":-597,"trait":"line"},{"x":0,"y":-263,"trait":"line"},{"x":215,"y":-600,"bCoef":-.1,"trait":"line","color":"C7E6BD"},{"x":215,"y":600,"bCoef":-.1,"trait":"line","color":"C7E6BD"}],"segments":[{"v0":0,"v1":1,"curve":-10,"trait":"goalNet"},{"v0":2,"v1":3,"curve":10,"trait":"goalNet"},{"v0":0,"v1":2,"curve":10,"trait":"goalNet"},{"v0":2,"v1":4,"trait":"cord"},{"v0":0,"v1":5,"trait":"cord"},{"v0":6,"v1":7,"trait":"line"},{"v0":8,"v1":9,"trait":"line"},{"v0":7,"v1":9,"trait":"line"},{"v0":10,"v1":11,"trait":"line"},{"v0":12,"v1":13,"trait":"line"},{"v0":11,"v1":13,"trait":"line"},{"v0":14,"v1":15,"curve":130,"trait":"line"},{"v0":16,"v1":17,"trait":"hline"},{"v0":18,"v1":19,"trait":"hline"},{"v0":20,"v1":21,"curve":100,"trait":"hline"},{"v0":22,"v1":23,"curve":-100,"trait":"hline"},{"v0":24,"v1":25,"curve":-70,"trait":"cLauncher"},{"v0":25,"v1":26,"trait":"stop"},{"v0":24,"v1":27,"trait":"stop"},{"v0":28,"v1":29,"curve":70,"trait":"cLauncher"},{"v0":29,"v1":30,"trait":"stop"},{"v0":28,"v1":31,"trait":"stop"},{"v0":32,"v1":33,"curve":-30,"trait":"gLauncher"},{"v0":34,"v1":35,"trait":"stop"},{"v0":36,"v1":37,"trait":"stop"},{"v0":38,"v1":39,"curve":30,"trait":"gLauncher"},{"v0":40,"v1":41,"trait":"stop"},{"v0":42,"v1":43,"trait":"stop"},{"v0":44,"v1":45,"curve":90,"trait":"line"},{"v0":46,"v1":47,"curve":-90,"trait":"line"},{"v0":48,"v1":49,"curve":90,"trait":"line"},{"v0":48,"v1":49,"curve":-90,"trait":"line"},{"v0":48,"v1":49,"curve":180,"trait":"line"},{"v0":48,"v1":49,"curve":-180,"trait":"line"},{"v0":45,"v1":47,"trait":"blueLimit"},{"v0":50,"v1":51,"trait":"mline"},{"v0":52,"v1":53,"trait":"mline"},{"v0":54,"v1":55,"trait":"mline"},{"v0":56,"v1":57,"trait":"mline"},{"v0":58,"v1":59,"vis":true,"color":"C7E6BD","bCoef":-.1,"trait":"line"}],"goals":[{"p0":[225,-110],"p1":[225,110],"team":"blue"},{"p0":[215,-112],"p1":[-10,-10],"team":"red"},{"p0":[-10,-10],"p1":[-10,10],"team":"red"},{"p0":[-10,10],"p1":[215,112],"team":"red"}],"discs":[{"pos":[215,-110],"trait":"goalPost"},{"pos":[215,110],"trait":"goalPost"},{"radius":3,"pos":[315,150],"trait":"cord"},{"radius":3,"pos":[315,-150],"trait":"cord"}],"planes":[{"normal":[0,1],"dist":-600,"bCoef":0},{"normal":[0,-1],"dist":-600,"bCoef":0},{"normal":[1,0],"dist":-350,"bCoef":0},{"normal":[-1,0],"dist":-285,"bCoef":0},{"normal":[-1,0],"dist":-20,"bCoef":0,"cMask":["red"]},{"normal":[-1,0],"dist":-250,"trait":"blueLimit"}],"traits":{"ballArea":{"vis":false,"bCoef":-1,"cMask":["ball"]},"goalPost":{"radius":5,"invMass":0,"bCoef":.5,"cMask":["all"],"color":"FFFFFF"},"goalNet":{"vis":true,"bCoef":.1,"cMask":["all"],"color":"FFFFFF"},"kickOffBarrier":{"vis":false,"bCoef":.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]},"line":{"vis":true,"cMask":[],"color":"C7E6BD"},"hline":{"vis":true,"cMask":[],"color":"5E844D"},"mline":{"vis":true,"cMask":[],"color":"6A8F59"},"stop":{"vis":true,"cMask":["ball"],"bCoef":-.001,"color":"000000"},"cord":{"vis":true,"cMask":[],"color":"DCDCDC"},"cLauncher":{"color":"BEB86C","vis":true,"bCoef":-2.75,"cMask":["ball"]},"gLauncher":{"color":"BEB86C","vis":true,"bCoef":-4.75,"cMask":["ball"]},"cFlag":{"radius":2,"invMass":0,"color":"FFFF00","bCoef":-.1,"cMask":["ball"]},"blueLimit":{"vis":false,"bCoef":0,"cMask":["blue"]}}}';
  39.  
  40. /* OPTIONS */
  41.  
  42. var afkLimit = 13;
  43. var drawTimeLimit = 10;//infinity if you want to use a no penalties
  44. var maxTeamSize = 4;
  45. var slowMode = 3;
  46.  
  47. /* PLAYERS */
  48.  
  49. const Team = { SPECTATORS: 0, RED: 1, BLUE: 2 };
  50. var extendedP = [];
  51. const eP = { ID: 0, AUTH: 1, CONN: 2, AFK: 3, ACT: 4, GK: 5, MUTE: 6, WARN: 7, RT: 8 };
  52. const Ss = { GA: 0, WI: 1, LS: 2, WR: 3, GL: 4, AS: 5, GK: 6, CS: 7, CP: 8, ST: 9, RL: 10, NK: 11};
  53. var players;
  54. var teamR;
  55. var teamB;
  56. var teamS;
  57. var teamROrder = [];
  58. var teamBOrder = [];
  59. var teamSOrder = [];
  60.  
  61. /* GAME */
  62.  
  63. var lastTeamTouched;
  64. var lastPlayersTouched;
  65. var countAFK = false;
  66. var activePlay = false;
  67. var goldenGoal = false;
  68. var SMSet = new Set();
  69. var banList = [];
  70.  
  71. /* STATS */
  72.  
  73. var game;
  74. var GKList = ["", ""];
  75. var Rposs = 0;
  76. var Bposs = 0;
  77. var ballProperties = [0, { "x": 0, "y": 0 }, { "x": 0, "y": 0 }];
  78. var lastWinner = Team.SPECTATORS;
  79. var streak = [0, []];
  80. var allBlues = [];
  81. var allReds = [];
  82.  
  83. /* BALANCE & CHOOSE */
  84.  
  85. var chooseMode = false;
  86. var redCaptainChoice = "";
  87. var blueCaptainChoice = "";
  88. var chooseTime = 20;
  89. var timeOutCap;
  90.  
  91. /* REAL SOCCER */
  92.  
  93. var isBallOutsideStadium = false;
  94. var timeOutside = 0;
  95. var checkAddTime = false;
  96. var ballSituation = "O";
  97. const stadiumW = 1150 + ballRadius;
  98. const stadiumH = 600 + ballRadius;
  99. var throwDone = [];
  100. var playersNotInLine = [];
  101. const GKLine = 840;
  102. const distCK = 340;
  103. const greenLine = 525;
  104. const throwInterval = 10 * 2 * playerRadius;
  105. var correctThrowPlace = true;
  106. var warningChange = false;
  107. var boostUsedRecent = false;
  108. var boostTimeout;
  109. var penaltyMode = false;
  110. var gamePenalty;
  111. var turnPenalty = [1, 0];
  112. var penaltyScores = [-1, -1];
  113. var ballKickCounter = 0;
  114.  
  115. /* AUXILIARY */
  116.  
  117. var checkTimeVariable = false;
  118. var statNumber = 0;
  119. var endGameVariable = false;
  120. var resettingTeams = false;
  121. var capLeft = false;
  122. var statInterval = 6;
  123. var discordInterval = 5;
  124. var logWebhook = "https://discordapp.com/api/webhooks/518539639955390484/Ts13q6bZ5mqMsbePEwO0iTGSxusdbcc_VqORFbVAuOW9BqcZNbdB5eCZmUWVNHpdYw4S";
  125. var recWebhook = "https://discordapp.com/api/webhooks/536189129290154004/9w81CA4gLHR8VA4Sf1Sl0JJ_FkAb_3K_sJaB-03cUbbDE_S2iEDh6PTQHfbytnux_wpR";
  126. var randomUrl;
  127.  
  128. loadMap(aloneMap, 0, 0);
  129. if (localStorage.getItem("streak") == null) localStorage.setItem("streak", JSON.stringify(streak));
  130.  
  131. /* OBJECTS */
  132.  
  133. function Goal(time, team, striker, assist) {
  134. this.time = time;
  135. this.team = team;
  136. this.striker = striker;
  137. this.assist = assist;
  138. }
  139.  
  140. function Game(date, scores, goals, rec) {
  141. this.date = date;
  142. this.scores = scores;
  143. this.goals = goals;
  144. this.rec = rec;
  145. }
  146.  
  147. /* FUNCTIONS */
  148.  
  149. /* AUXILIARY FUNCTIONS */
  150.  
  151. function getRandomInt(max) {
  152. return Math.floor(Math.random() * Math.floor(max));
  153. }
  154.  
  155. function getTime(scores) {
  156. 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() + "]"
  157. }
  158.  
  159. function pointDistance(p1, p2) {
  160. var d1 = p1.x - p2.x;
  161. var d2 = p1.y - p2.y;
  162. return Math.sqrt(d1 * d1 + d2 * d2);
  163. }
  164.  
  165. function setTeam(player, add, team) {
  166. if (add) room.setPlayerTeam(player.id, team);
  167. else setRealTeam(player, team);
  168. }
  169.  
  170. /*function saveStats() {
  171. var a = document.createElement("a");
  172. document.body.appendChild(a);
  173. a.style = "display: none";
  174. a.id = "locSto";
  175. var d = new Date();
  176. var s = (("0" + d.getDate()).slice(-2) + "" + ("0" + (d.getMonth() + 1)).slice(-2) + "" + (d.getYear() + 1900).toString().substring(2) + "-" + ("0" + d.getHours()).slice(-2) + "" + ("0" + d.getMinutes()).slice(-2) + "" + ("0" + d.getSeconds()).slice(-2)).toString();
  177. var data = [];
  178. Object.keys(localStorage).forEach((key) => {
  179. if (key.length == 43) data.push([key].concat(JSON.parse(localStorage.getItem(key))));
  180. });
  181. data.push(["streak"].concat(JSON.parse(localStorage.getItem('streak'))));
  182. var fileName = `room1_${s}.json`;
  183. var json = JSON.stringify(data),
  184. blob = new Blob([json], { type: "octet/stream" });
  185. randomUrl = window.URL.createObjectURL(blob);
  186. a.href = randomUrl;
  187. a.download = fileName;
  188. console.log("get_update");
  189. room.sendChat("✅ Stats were saved successfully !");
  190. }*/
  191.  
  192. /* BUTTONS */
  193.  
  194. function topBtn() {
  195. if (teamS.length > 0) {
  196. if (teamR.length == teamB.length && teamS.length > 1) {
  197. setTeam(teamS[0], true, Team.RED);
  198. if (room.getScores() != null) room.sendChat("@" + teamS[0].name + ", you've entered the field !", teamS[0].id);
  199. setTeam(teamS[1], true, Team.BLUE);
  200. }
  201. else if (teamR.length < teamB.length) setTeam(teamS[0], true, Team.RED);
  202. else setTeam(teamS[0], true, Team.BLUE);
  203. }
  204. }
  205.  
  206. function randomBtn() {
  207. if (teamS.length > 0) {
  208. if (teamR.length == teamB.length && teamS.length > 1) {
  209. var r = getRandomInt(teamS.length);
  210. setTeam(teamS[r], true, Team.RED);
  211. teamS = teamS.filter((spec) => spec.id != teamS[r].id);
  212. setTeam(teamS[getRandomInt(teamS.length)], true, Team.BLUE);
  213. }
  214. else if (teamR.length < teamB.length) setTeam(teamS[getRandomInt(teamS.length)], true, Team.RED);
  215. else setTeam(teamS[getRandomInt(teamS.length)], true, Team.BLUE);
  216. }
  217. }
  218.  
  219. function blueToSpecBtn() {
  220. resettingTeams = true;
  221. setTimeout(() => { resettingTeams = false; }, 10);
  222. for (i = 0; i < teamB.length; i++) {
  223. setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
  224. setRealTeam(teamB[teamB.length - 1 - i], Team.SPECTATORS);
  225. }
  226. }
  227.  
  228. function redToSpecBtn() {
  229. resettingTeams = true;
  230. setTimeout(() => { resettingTeams = false; }, 10);
  231. for (i = 0; i < teamR.length; i++) {
  232. setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
  233. setRealTeam(teamR[teamR.length - 1 - i], Team.SPECTATORS);
  234. }
  235. }
  236.  
  237. function resetBtn() {
  238. resettingTeams = true;
  239. setTimeout(() => { resettingTeams = false; }, 10);
  240. if (teamR.length <= teamB.length) {
  241. for (i = 0; i < teamR.length; i++) {
  242. setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
  243. setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
  244. }
  245. for (i = teamR.length; i < teamB.length; i++) setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
  246. }
  247. else {
  248. for (i = 0; i < teamB.length; i++) {
  249. setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
  250. setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
  251. }
  252. for (i = teamB.length; i < teamR.length; i++) setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
  253. }
  254. }
  255.  
  256. function blueToRedBtn() {
  257. resettingTeams = true;
  258. setTimeout(() => { resettingTeams = false; }, 10);
  259. for (i = 0; i < teamB.length; i++) setTeam(teamB[i], true, Team.RED);
  260. }
  261.  
  262. function orderTeamsBtn() {
  263. resettingTeams = true;
  264. setTimeout(() => { resettingTeams = false; }, 10);
  265. resetBtn();
  266. for (i = 0; i < teamROrder.length; i++) setTeam(teamROrder[i], true, Team.RED);
  267. for (i = 0; i < teamBOrder.length; i++) setTeam(teamBOrder[i], true, Team.BLUE);
  268. }
  269.  
  270. /* GAME FUNCTIONS */
  271.  
  272. function checkTime() {
  273. const scores = room.getScores();
  274. game.scores = scores;
  275. if (Math.abs(scores.time - scores.timeLimit) <= 0.01 && scores.timeLimit != 0) {
  276. if (scores.red != scores.blue) {
  277. if (checkTimeVariable == false) {
  278. checkTimeVariable = true;
  279. setTimeout(() => { checkTimeVariable = false; }, 3000);
  280. scores.red > scores.blue ? endGame(Team.RED) : endGame(Team.BLUE);
  281. setTimeout(() => { room.stopGame(); }, 2000);
  282. }
  283. return;
  284. }
  285. goldenGoal = true;
  286. room.sendChat("⚽ First goal wins !");
  287. }
  288. if (Math.abs(drawTimeLimit * 60 - scores.time - 60) <= 0.01 && players.length > 2) {
  289. if (checkTimeVariable == false) {
  290. checkTimeVariable = true;
  291. setTimeout(() => { checkTimeVariable = false; }, 10);
  292. room.sendChat("⌛ 60 seconds left until draw !");
  293. }
  294. }
  295. if (Math.abs(scores.time - drawTimeLimit * 60) <= 0.01 && players.length > 2) {
  296. if (checkTimeVariable == false) {
  297. checkTimeVariable = true;
  298. setTimeout(() => { checkTimeVariable = false; }, 10);
  299. if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) penaltyMode = false;//estaba en true
  300. endGame(Team.SPECTATORS);
  301. room.stopGame();
  302. // if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) loadMap(penaltyMap, 0, 0);
  303. goldenGoal = false;
  304. }
  305. }
  306. }
  307.  
  308. function endGame(winner) {
  309. Rposs = Rposs / (Rposs + Bposs);
  310. Bposs = 1 - Rposs;
  311. var scores;
  312. endGameVariable = true;
  313. lastWinner = winner;
  314. if (!penaltyMode) {
  315. if (players.length >= 2 * maxTeamSize - 1) activateChooseMode();
  316. if (penaltyScores[0] == -1) {
  317. scores = room.getScores();
  318. game.scores = scores;
  319. }
  320. }
  321. if (winner == Team.RED) {
  322. (!penaltyMode && 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) ? streak[0]++ : streak = [0, []];
  323. room.sendChat("🔴 Red Team won " + game.scores.red + "-" + game.scores.blue + "" + (penaltyScores[0] != -1 || penaltyScores[1] != -1 ? "[" + penaltyScores[0] + "-" + penaltyScores[1] + "]" : "") + " ! Current streak : " + streak[0] + " 🏆");
  324. }
  325. else if (winner == Team.BLUE) {
  326. (!penaltyMode && 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) ? streak = [1, []] : streak = [0, []];
  327. room.sendChat("🔵 Blue Team won " + game.scores.blue + "-" + game.scores.red + "" + (penaltyScores[0] != -1 || penaltyScores[1] != -1 ? "[" + penaltyScores[1] + "-" + penaltyScores[0] + "]" : "") + " ! Current streak : " + streak[0] + " 🏆");
  328. }
  329. else {
  330. /* if (teamR.length == maxTeamSize && teamB.length == maxTeamSize && penaltyScores[0] == penaltyScores[1]) {
  331. gamePenalty = game;
  332. penaltyScores = [0, 0];
  333. endGameVariable = false;
  334. turnPenalty = [Team.RED, 0];
  335. room.sendChat("Penalty Time !");
  336. return;
  337. }*/
  338. //else {
  339. streak = [0, []];
  340. room.sendChat("💤 Draw ! 💤");
  341. //}
  342. }
  343. room.sendChat("⭐ Possession : 🔴 " + (Rposs * 100).toPrecision(3).toString() + "% : " + (Bposs * 100).toPrecision(3).toString() + "% 🔵");
  344. game.scores.red == 0 ? (game.scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " and " + GKList[1].name + " kept a CS ! ") : room.sendChat("🏆 " + GKList[1].name + " kept a CS ! ")) : game.scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " kept a CS ! ") : null;
  345. updateStats();
  346. }
  347.  
  348. function quickRestart() {
  349. room.stopGame();
  350. setTimeout(() => { room.startGame(); }, 2000);
  351. }
  352.  
  353. function resumeGame() {
  354. setTimeout(() => { room.startGame(); }, 2000);
  355. setTimeout(() => { room.pauseGame(false); }, 1000);
  356. }
  357.  
  358. function activateChooseMode() {
  359. chooseMode = true;
  360. }
  361.  
  362. function deactivateChooseMode() {
  363. if (chooseMode) room.sendChat("Choose Mode ended !");
  364. chooseMode = false;
  365. clearTimeout(timeOutCap);
  366. redCaptainChoice = "";
  367. blueCaptainChoice = "";
  368. }
  369.  
  370. function loadMap(map, scoreLim, timeLim) {
  371. if (map == classicMap) {
  372. (classicMap != '') ? room.setCustomStadium(classicMap) : room.setDefaultStadium("Classic");
  373. }
  374. else if (map == bigMap) {
  375. (bigMap != '.') ? room.setCustomStadium(bigMap) : room.setDefaultStadium("Big");
  376. }
  377. else {
  378. room.setCustomStadium(map);
  379. }
  380. room.setScoreLimit(scoreLim);
  381. room.setTimeLimit(timeLim);
  382. }
  383.  
  384. /* PLAYER FUNCTIONS */
  385.  
  386. function updateTeams() {
  387. players = room.getPlayerList().filter((player) => player.id != 0 && !getAFK(player));
  388. teamR = players.filter(p => p.team == Team.RED && getRealTeam(p) == Team.RED).concat(players.filter(p => getRealTeam(p) == Team.RED && p.team != Team.RED));
  389. teamROrder = teamROrder.filter((player) => teamR.find((p) => p.id == player.id) != null).concat(teamR.filter((player) => teamROrder.find((p) => p.id == player.id) == null));
  390. teamB = players.filter(p => p.team == Team.BLUE && getRealTeam(p) == Team.BLUE).concat(players.filter(p => getRealTeam(p) == Team.BLUE && p.team != Team.BLUE));
  391. teamBOrder = teamBOrder.filter((player) => teamB.find((p) => p.id == player.id) != null).concat(teamB.filter((player) => teamBOrder.find((p) => p.id == player.id) == null));
  392. teamS = players.filter(p => p.team == Team.SPECTATORS && getRealTeam(p) == Team.SPECTATORS);
  393. }
  394.  
  395. function handleInactivity() {
  396. if (countAFK && (teamR.length + teamB.length) > 1) {
  397. for (i = 0; i < teamR.length; i++) {
  398. if (teamR[i].team == Team.RED) setActivity(teamR[i], getActivity(teamR[i]) + 1);
  399. }
  400. for (i = 0; i < teamB.length; i++) {
  401. if (teamB[i].team == Team.BLUE) setActivity(teamB[i], getActivity(teamB[i]) + 1);
  402. }
  403. }
  404. for (i = 0; i < extendedP.length; i++) {
  405. if (extendedP[i][eP.ACT] == 60 * (2 / 3 * afkLimit)) 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]);
  406. if (extendedP[i][eP.ACT] >= 60 * afkLimit) {
  407. extendedP[i][eP.ACT] = 0;
  408. if (room.getScores().time <= afkLimit - 0.5) setTimeout(() => { !chooseMode ? quickRestart() : room.stopGame(); }, 10);
  409. room.kickPlayer(extendedP[i][eP.ID], "AFK", false);
  410. }
  411. }
  412. }
  413.  
  414. function getAuth(player) {
  415. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AUTH] : null;
  416. }
  417.  
  418. function getAFK(player) {
  419. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AFK] : null;
  420. }
  421.  
  422. function setAFK(player, value) {
  423. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.AFK] = value);
  424. }
  425.  
  426. function getActivity(player) {
  427. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.ACT] : null;
  428. }
  429.  
  430. function setActivity(player, value) {
  431. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.ACT] = value);
  432. }
  433.  
  434. function getGK(player) {
  435. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.GK] : null;
  436. }
  437.  
  438. function setGK(player, value) {
  439. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.GK] = value);
  440. }
  441.  
  442. function getMute(player) {
  443. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.MUTE] : null;
  444. }
  445.  
  446. function setMute(player, value) {
  447. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.MUTE] = value);
  448. }
  449.  
  450. function getWarning(player) {
  451. return extendedP.filter((a) => a[0] == player.id) != null && extendedP.filter((a) => a[0] == player.id).length > 0 ? extendedP.filter((a) => a[0] == player.id)[0][eP.WARN] : null;
  452. }
  453.  
  454. function setWarning(player, value) {
  455. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.WARN] = value);
  456. }
  457.  
  458. function getRealTeam(player) {
  459. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.RT] : null;
  460. }
  461.  
  462. function setRealTeam(player, value) {
  463. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.RT] = value);
  464. }
  465.  
  466. /* BALANCE & CHOOSE FUNCTIONS */
  467.  
  468. function updateRoleOnPlayerIn() {
  469. updateTeams();
  470. if (chooseMode) {
  471. if (players.length == 6) loadMap(bigMap, scoreLimitBig, timeLimitBig);
  472. getSpecList(teamR.length <= teamB.length ? Team.RED : Team.BLUE);
  473. }
  474. balanceTeams();
  475. }
  476.  
  477. function updateRoleOnPlayerOut() {
  478. updateTeams();
  479. if (room.getScores() != null && !penaltyMode) {
  480. var scores = room.getScores();
  481. if (players.length >= 2 * maxTeamSize && scores.time >= (5 / 6) * game.scores.timeLimit && teamR.length != teamB.length) {
  482. if ((teamR.length < teamB.length && scores.blue - scores.red == 2) || (teamB.length < teamR.length && scores.red - scores.blue == 2)) {
  483. endGame((teamR.length < teamB.length && scores.blue - scores.red == 2) ? Team.BLUE : Team.RED);
  484. room.sendChat("🤖 Ragequit detected. Game ended 🤖");
  485. setTimeout(() => { room.stopGame(); }, 100);
  486. return;
  487. }
  488. }
  489. }
  490. if (penaltyMode && !chooseMode) {
  491. if (players.length <= 2 * maxTeamSize - 1) {
  492. penaltyMode = false;
  493. game = gamePenalty;
  494. resetBtn();
  495. penaltyScores = [-1, 0];
  496. setTimeout(() => { penaltyScores = [-1, -1]; }, 110);
  497. teamROrder.forEach((p) => setTeam(p, true, Team.RED));
  498. teamBOrder.forEach((p) => setTeam(p, true, Team.BLUE));
  499. extendedP.forEach((p) => { if (room.getPlayer(p[eP.ID]) != null) p[eP.RT] = room.getPlayer(p[eP.ID]).team });
  500. endGame(Team.SPECTATORS);
  501. setTimeout(() => { room.stopGame(); }, 100);
  502. return;
  503. }
  504. if (teamR.length < maxTeamSize || teamB.length < maxTeamSize) {
  505. activateChooseMode();
  506. room.stopGame();
  507. }
  508. }
  509. if (chooseMode) {
  510. if (players.length == 5) loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  511. if (teamR.length == 0 || teamB.length == 0) {
  512. teamR.length == 0 ? setTeam(teamS[0], true, Team.RED) : setTeam(teamS[0], true, Team.BLUE);
  513. return;
  514. }
  515. if (Math.abs(teamR.length - teamB.length) == teamS.length) {
  516. room.sendChat("🤖 No choices left, let me handle this situation... 🤖");
  517. deactivateChooseMode();
  518. var b = teamS.length;
  519. if (teamR.length > teamB.length) {
  520. for (i = 0; i < b; i++) setTeam(teamS[i], !penaltyMode, Team.BLUE);
  521. }
  522. else {
  523. for (i = 0; i < b; i++) setTeam(teamS[i], !penaltyMode, Team.RED);
  524. }
  525. if (penaltyMode) setTimeout(() => { penaltyPutPlayers(); }, 5);
  526. resumeGame();
  527. return;
  528. }
  529. if (streak[0] == 0 && room.getScores() == null && !penaltyMode && Math.abs(teamR.length - teamB.length) == 2) {
  530. room.sendChat("🤖 Balancing teams... 🤖");
  531. teamR.length > teamB.length ? setTeam(teamR[teamR.length - 1], true, Team.SPECTATORS) : setTeam(teamB[teamB.length - 1], true, Team.SPECTATORS);
  532. }
  533. if (teamR.length == teamB.length && teamS.length < 2) {
  534. deactivateChooseMode();
  535. resumeGame();
  536. return;
  537. }
  538. if (capLeft >= 1) {
  539. choosePlayer();
  540. capLeft == Team.RED ? redCaptainChoice = "" : blueCaptainChoice = "";
  541. }
  542. else {
  543. if (teamR.length <= teamB.length && redCaptainChoice != "") {
  544. if (redCaptainChoice == "top") {
  545. setTeam(teamS[0], !penaltyMode, Team.RED);
  546. if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
  547. }
  548. else if (redCaptainChoice == "random") {
  549. var r = getRandomInt(teamS.length);
  550. setTeam(teamS[r], !penaltyMode, Team.RED);
  551. if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
  552. }
  553. else {
  554. setTeam(teamS[teamS.length - 1], !penaltyMode, Team.RED);
  555. if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
  556. }
  557. return;
  558. }
  559. else if (teamB.length < teamR.length && blueCaptainChoice != "") {
  560. if (blueCaptainChoice == "top") {
  561. setTeam(teamS[0], !penaltyMode, Team.BLUE);
  562. if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
  563. }
  564. else if (blueCaptainChoice == "random") {
  565. var r = getRandomInt(teamS.length);
  566. setTeam(teamS[r], !penaltyMode, Team.BLUE);
  567. if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
  568. }
  569. else {
  570. setTeam(teamS[teamS.length - 1], !penaltyMode, Team.BLUE);
  571. if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
  572. }
  573. return;
  574. }
  575. getSpecList(teamR.length <= teamB.length ? Team.RED : Team.BLUE);
  576. }
  577. }
  578. balanceTeams();
  579. }
  580.  
  581. function updateOnTeamChange(changedPlayer, byPlayer) {
  582. if (changedPlayer.id == 0) {
  583. room.setPlayerTeam(0, Team.SPECTATORS);
  584. return;
  585. }
  586. if (getAFK(changedPlayer) && changedPlayer.team != Team.SPECTATORS) {
  587. setTeam(changedPlayer, true, Team.SPECTATORS);
  588. room.sendChat(changedPlayer.name + " is AFK !");
  589. return;
  590. }
  591. if (warningChange) return;
  592. if (penaltyMode && teamROrder.concat(teamBOrder).map(x => x.id).includes(changedPlayer.id)) return;
  593. if (!penaltyMode) setRealTeam(changedPlayer, changedPlayer.team);
  594. updateTeams();
  595. if (room.getScores() != null && !penaltyMode) {
  596. var scores = room.getScores();
  597. if (changedPlayer.team != Team.SPECTATORS && scores.time <= (3 / 4) * scores.timeLimit && Math.abs(scores.blue - scores.red) < 2) {
  598. (changedPlayer.team == Team.RED) ? allReds.push(changedPlayer) : allBlues.push(changedPlayer);
  599. }
  600. }
  601. if (changedPlayer.team == Team.SPECTATORS) setActivity(changedPlayer, 0);
  602. if (chooseMode && resettingTeams == false && byPlayer.id == 0) {
  603. if (Math.abs(teamR.length - teamB.length) == teamS.length) {
  604. deactivateChooseMode();
  605. var b = teamS.length;
  606. if (teamR.length > teamB.length) {
  607. for (i = 0; i < b; i++) setTeam(teamS[i], true, Team.BLUE);
  608. }
  609. else {
  610. for (i = 0; i < b; i++) setTeam(teamS[i], true, Team.RED);
  611. }
  612. if (penaltyMode) setTimeout(() => { penaltyPutPlayers(); }, 5);
  613. resumeGame();
  614. return;
  615. }
  616. else if ((teamR.length == maxTeamSize && teamB.length == maxTeamSize) || (teamR.length == teamB.length && teamS.length < 2)) {
  617. deactivateChooseMode();
  618. if (penaltyMode) setTimeout(() => { penaltyPutPlayers(); }, 5);
  619. resumeGame();
  620. }
  621. else if (teamR.length <= teamB.length && redCaptainChoice != "") {
  622. if (redCaptainChoice == "top") {
  623. setTeam(teamS[0], !penaltyMode, Team.RED);
  624. if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
  625. }
  626. else if (redCaptainChoice == "random") {
  627. var r = getRandomInt(teamS.length);
  628. setTeam(teamS[r], !penaltyMode, Team.RED);
  629. if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
  630. }
  631. else {
  632. setTeam(teamS[teamS.length - 1], !penaltyMode, Team.RED);
  633. if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
  634. }
  635. }
  636. else if (teamB.length < teamR.length && blueCaptainChoice != "") {
  637. if (blueCaptainChoice == "top") {
  638. setTeam(teamS[0], !penaltyMode, Team.BLUE);
  639. if (penaltyMode) updateOnTeamChange(teamS[0], room.getPlayer(0));
  640. }
  641. else if (blueCaptainChoice == "random") {
  642. var r = getRandomInt(teamS.length);
  643. setTeam(teamS[r], !penaltyMode, Team.BLUE);
  644. if (penaltyMode) updateOnTeamChange(teamS[r], room.getPlayer(0));
  645. }
  646. else {
  647. setTeam(teamS[teamS.length - 1], !penaltyMode, Team.BLUE);
  648. if (penaltyMode) updateOnTeamChange(teamS[teamS.length - 1], room.getPlayer(0));
  649. }
  650. }
  651. else choosePlayer();
  652. }
  653. }
  654.  
  655. function balanceTeams() {
  656. if (!chooseMode) {
  657. if (players.length == 1) {
  658. quickRestart();
  659. loadMap(aloneMap, 0, 0);
  660. if (teamR.length == 0) setTeam(players[0], true, Team.RED);
  661. }
  662. else if (Math.abs(teamR.length - teamB.length) == teamS.length && teamS.length > 0) {
  663. const n = Math.abs(teamR.length - teamB.length);
  664. if (players.length == 2) {
  665. quickRestart();
  666. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  667. }
  668. if (teamR.length > teamB.length) {
  669. for (i = 0; i < n; i++) setTeam(teamS[i], true, Team.BLUE);
  670. }
  671. else {
  672. for (i = 0; i < n; i++) setTeam(teamS[i], true, Team.RED);
  673. }
  674. }
  675. else if (Math.abs(teamR.length - teamB.length) > teamS.length) {
  676. const n = Math.abs(teamR.length - teamB.length);
  677. if (players.length == 1) {
  678. quickRestart();
  679. loadMap(aloneMap, 0, 0);
  680. setTeam(players[0], true, Team.RED);
  681. return;
  682. }
  683. else if (players.length == 5) {
  684. quickRestart();
  685. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  686. }
  687. if (players.length == maxTeamSize * 2 - 1) {
  688. allReds = [];
  689. allBlues = [];
  690. }
  691. if (teamR.length > teamB.length) {
  692. for (i = 0; i < n; i++) setTeam(teamR[teamR.length - 1 - i], true, Team.SPECTATORS);
  693. }
  694. else {
  695. for (i = 0; i < n; i++) setTeam(teamB[teamB.length - 1 - i], true, Team.SPECTATORS);
  696. }
  697. }
  698. else if (Math.abs(teamR.length - teamB.length) < teamS.length && teamR.length != teamB.length) {
  699. room.pauseGame(true);
  700. activateChooseMode();
  701. choosePlayer();
  702. }
  703. else if (teamS.length >= 2 && teamR.length == teamB.length && teamR.length < maxTeamSize) {
  704. if (teamR.length == 2) {
  705. quickRestart();
  706. loadMap(bigMap, scoreLimitBig, timeLimitBig);
  707. }
  708. setTimeout (() => { topBtn(); }, 10);
  709. }
  710. }
  711. }
  712.  
  713. function choosePlayer() {
  714. clearTimeout(timeOutCap);
  715. if (teamR.length <= teamB.length && teamR.length != 0) {
  716. if (teamROrder[0].id != teamR[0].id || penaltyMode) room.sendChat(teamROrder[0].name + " is currently choosing a player !");
  717. room.sendChat("[PV] To choose a player, enter his number in the list given or use 'top', 'random' or 'bottom'.", teamROrder[0].id);
  718. 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, teamROrder[0]); }, chooseTime * 1000, teamROrder[0]);
  719. }
  720. else if (teamB.length < teamR.length && teamB.length != 0) {
  721. if (teamBOrder[0].id != teamB[0].id || penaltyMode) room.sendChat(teamBOrder[0].name + " is currently choosing a player !");
  722. room.sendChat("[PV] To choose a player, enter his number in the list given or use 'top', 'random' or 'bottom'.", teamBOrder[0].id);
  723. 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, teamBOrder[0]); }, chooseTime * 1000, teamBOrder[0]);
  724. }
  725. if (teamR.length != 0 && teamB.length != 0) getSpecList(teamR.length <= teamB.length ? Team.RED : Team.BLUE);
  726. }
  727.  
  728. function getSpecList(team, player = null) {
  729. var cstm = "[PV] Spectators : ";
  730. for (i = 0; i < teamS.length; i++) {
  731. if (140 - cstm.length < (teamS[i].name + "[" + (i + 1) + "], ").length) {
  732. if (team == Team.RED && teamR.length > 0) room.sendChat(cstm, teamROrder[0].id);
  733. else if (team == Team.BLUE && teamB.length > 0) room.sendChat(cstm, teamBOrder[0].id);
  734. else if (team == Team.SPECTATORS && player != null) room.sendChat(cstm, player.id);
  735. cstm = "... ";
  736. }
  737. cstm += teamS[i].name + "[" + (i + 1) + "], ";
  738. }
  739. if (cstm == "[PV] Spectators : ") {
  740. if (team == Team.RED && teamR.length > 0) room.sendChat(cstm, teamROrder[0].id);
  741. else if (team == Team.BLUE && teamB.length > 0) room.sendChat(cstm, teamBOrder[0].id);
  742. else if (team == Team.SPECTATORS && player != null) room.sendChat(cstm, player.id);
  743. return;
  744. }
  745. cstm = cstm.substring(0, cstm.length - 2) + ".";
  746. if (team == Team.RED && teamR.length > 0) room.sendChat(cstm, teamROrder[0].id);
  747. else if (team == Team.BLUE && teamB.length > 0) room.sendChat(cstm, teamBOrder[0].id);
  748. else if (team == Team.SPECTATORS && player != null) room.sendChat(cstm, player.id);
  749. }
  750.  
  751. /* STATS FUNCTIONS */
  752.  
  753. function getLastTouchOfTheBall() {
  754. updateTeams();
  755. for (i = 0; i < players.length; i++) {
  756. if (players[i].position != null) {
  757. if (pointDistance(players[i].position, room.getBallPosition()) < triggerDistance) {
  758. if (!activePlay) activePlay = true;
  759. if (lastPlayersTouched[0] == null || (lastTeamTouched == players[i].team && lastPlayersTouched[0] != null && lastPlayersTouched[0].id != players[i].id)) {
  760. if (lastPlayersTouched[0] != null) lastPlayersTouched[1] = lastPlayersTouched[0];
  761. lastPlayersTouched[0] = players[i];
  762. }
  763. lastTeamTouched = players[i].team;
  764. }
  765. }
  766. }
  767. }
  768.  
  769. function getStats() {
  770. if (activePlay) {
  771. updateTeams();
  772. if (!penaltyMode && !isBallOutsideStadium) lastTeamTouched == Team.RED ? Rposs++ : Bposs++;
  773. ballProperties[2] = ballProperties[1];
  774. ballProperties[1] = room.getBallPosition();
  775. ballProperties[0] = (pointDistance(ballProperties[1], ballProperties[2]) * 60 * 60 * 60) / 15000;
  776. var k = [-1, Infinity];
  777. for (i = 0; i < teamR.length; i++) {
  778. if (teamR[i].position != null && teamR[i].position.x < k[1]) {
  779. k[0] = teamR[i];
  780. k[1] = teamR[i].position.x;
  781. }
  782. }
  783. if (k[0] != -1 && !penaltyMode) setGK(k[0], getGK(k[0]) + 1);
  784. k = [-1, -Infinity];
  785. for (i = 0; i < teamB.length; i++) {
  786. if (teamB[i].position != null && teamB[i].position.x > k[1]) {
  787. k[0] = teamB[i];
  788. k[1] = teamB[i].position.x;
  789. }
  790. }
  791. if (k[0] != -1 && !penaltyMode) setGK(k[0], getGK(k[0]) + 1);
  792. findGK();
  793. }
  794. }
  795.  
  796. function updateStats() {
  797. if (!penaltyMode && 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) {
  798. var stats;
  799. var streakTime = JSON.parse(localStorage.getItem("streak"));
  800. if (lastWinner == Team.RED) {
  801. var k = true;
  802. for (i = 0; i < allReds.length; i++) {
  803. for (j = 0; j < streak[1].length; j++) {
  804. if (allReds[i].id == streak[1][j][1]) {
  805. streak[1][j][2]++;
  806. k = false;
  807. break;
  808. }
  809. }
  810. if (k) streak[1].push([allReds[i].name, allReds[i].id, 1]);
  811. }
  812. streak[1].sort((a, b) => { return b[2] - a[2]; });
  813. }
  814. else if (lastWinner == Team.BLUE) {
  815. for (i = 0; i < allBlues.length; i++) streak[1].push([allBlues[i].name, allBlues[i].id, 1]);
  816. }
  817. if (streak[0] > streakTime[0]) {
  818. room.sendChat(`🔥 New streak record ! It is now ${streak[0]} with team [${streak[1][0][0]}, ${streak[1][1][0]}, ${streak[1][2][0]}, ${streak[1][3][0]}]`);
  819. localStorage.setItem("streak", JSON.stringify(streak));
  820. }
  821. for (i = 0; i < allReds.length; i++) {
  822. localStorage.getItem(getAuth(allReds[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allReds[i]))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", allReds[i].name];
  823. stats[Ss.GA]++;
  824. lastWinner == Team.RED ? stats[Ss.WI]++ : lastWinner == Team.BLUE ? stats[Ss.LS]++ : stats[Ss.DR]++;
  825. stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
  826. if (lastWinner == Team.RED) {
  827. var index = 0;
  828. for (j = 0; j < streak[1].length; j++) {
  829. if (streak[1][j][1] == allReds[i].id) index = j;
  830. }
  831. if (streak[1][index][2] > stats[Ss.ST]) stats[Ss.ST] = streak[1][index][2];
  832. }
  833. localStorage.setItem(getAuth(allReds[i]), JSON.stringify(stats));
  834. }
  835. for (i = 0; i < allBlues.length; i++) {
  836. localStorage.getItem(getAuth(allBlues[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allBlues[i]))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", allBlues[i].name];
  837. stats[Ss.GA]++;
  838. lastWinner == Team.BLUE ? stats[Ss.WI]++ : lastWinner == Team.RED ? stats[Ss.LS]++ : stats[Ss.DR]++;
  839. stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
  840. if (lastWinner == Team.BLUE) {
  841. if (stats[Ss.ST] == 0) stats[Ss.ST] = 1;
  842. }
  843. localStorage.setItem(getAuth(allBlues[i]), JSON.stringify(stats));
  844. }
  845. for (i = 0; i < game.goals.length; i++) {
  846. if (game.goals[i].striker != null) {
  847. if ((allBlues.concat(allReds)).findIndex((player) => player.id == game.goals[i].striker.id) != -1) {
  848. stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].striker)));
  849. stats[Ss.GL]++;
  850. localStorage.setItem(getAuth(game.goals[i].striker), JSON.stringify(stats));
  851. }
  852. }
  853. if (game.goals[i].assist != null) {
  854. if ((allBlues.concat(allReds)).findIndex((player) => player.name == game.goals[i].assist.name) != -1) {
  855. stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].assist)));
  856. stats[Ss.AS]++;
  857. localStorage.setItem(getAuth(game.goals[i].assist), JSON.stringify(stats));
  858. }
  859. }
  860. }
  861. if (allReds.findIndex((player) => player.id == GKList[0].id) != -1) {
  862. stats = JSON.parse(localStorage.getItem(getAuth(GKList[0])));
  863. stats[Ss.GK]++;
  864. if (game.scores.blue == 0) stats[Ss.CS]++;
  865. stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
  866. localStorage.setItem(getAuth(GKList[0]), JSON.stringify(stats));
  867. }
  868. if (allBlues.findIndex((player) => player.id == GKList[1].id) != -1) {
  869. stats = JSON.parse(localStorage.getItem(getAuth(GKList[1])));
  870. stats[Ss.GK]++;
  871. if (game.scores.red == 0) stats[Ss.CS]++;
  872. stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
  873. localStorage.setItem(getAuth(GKList[1]), JSON.stringify(stats));
  874. }
  875. }
  876. }
  877.  
  878. function findGK() {
  879. var tab = [[-1, ""], [-1, ""]];
  880. for (i = 0; i < extendedP.length; i++) {
  881. if (room.getPlayer(extendedP[i][eP.ID]) != null && extendedP[i][eP.RT] == Team.RED) {
  882. if (tab[0][0] < extendedP[i][eP.GK]) {
  883. tab[0][0] = extendedP[i][eP.GK];
  884. tab[0][1] = room.getPlayer(extendedP[i][eP.ID]);
  885. }
  886. }
  887. else if (room.getPlayer(extendedP[i][eP.ID]) != null && extendedP[i][eP.RT] == Team.BLUE) {
  888. if (tab[1][0] < extendedP[i][eP.GK]) {
  889. tab[1][0] = extendedP[i][eP.GK];
  890. tab[1][1] = room.getPlayer(extendedP[i][eP.ID]);
  891. }
  892. }
  893. }
  894. GKList = [tab[0][1], tab[1][1]];
  895. }
  896.  
  897. function showRankings(stat, text, player = null) {
  898. var tableau = [];
  899. Object.keys(localStorage).forEach(function (key) {
  900. if (key.length == 43) tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[stat])]);
  901. });
  902. if (tableau.length < 5) {
  903. if (player != null) room.sendChat("[PV] Not enough games played yet !", player.id);
  904. return;
  905. }
  906. tableau.sort(function (a, b) {
  907. return b[1] - a[1];
  908. });
  909. if (player == null) room.sendChat(text + "> #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]);
  910. else room.sendChat("[PV] " + text + "> #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);
  911. }
  912.  
  913. setInterval(() => {
  914. if (statNumber % 5 == 0) showRankings(Ss.GA, "Games");
  915. if (statNumber % 5 == 1) showRankings(Ss.WI, "Wins");
  916. if (statNumber % 5 == 2) showRankings(Ss.GL, "Goals");
  917. if (statNumber % 5 == 3) showRankings(Ss.AS, "Assists");
  918. if (statNumber % 5 == 4) showRankings(Ss.CS, "CS");
  919. statNumber++;
  920. }, statInterval * 60 * 1000);
  921.  
  922. setTimeout(() => {
  923. setInterval(() => {
  924. //room.sendChat("💬 This host was created by Gouiri[FR] and edited by Gimenez20[GI] 👊");
  925. //room.sendChat("💬 Do you search team to play our leagues? You can enjoy with our leagues (Big 4v4-3def | Real Soccer) 👊");
  926. //room.sendChat("💬 TS3: hbpt.ts.io, Forum: https://haxball.pt/ , Discord: https://discord.gg/3MhhZPN 👊");
  927. room.sendChat("💬 Join our Discord: https://discord.gg/3MhhZPN 👊");
  928. }, discordInterval * 60 * 1000); }, 10000);
  929.  
  930. /*setInterval(() => {
  931. saveStats();
  932. }, 60 * 60 * 1000);*/
  933.  
  934.  
  935. /* RS FUNCTIONS */
  936.  
  937. function isOutsideStadium(ballPosition) {
  938. return (ballPosition.x > stadiumW || ballPosition.x < -stadiumW || ballPosition.y > stadiumH || ballPosition.y < -stadiumH);
  939. }
  940.  
  941. function boostUsed(ballPosition) {
  942. return ((Math.abs(ballPosition.x) > 1175 - ballRadius && Math.abs(ballPosition.x) < 1195 + ballRadius && Math.abs(ballPosition.y) > 155 - ballRadius && Math.abs(ballPosition.y) < 255 + ballRadius) || ((Math.abs(ballPosition.x) > 1158 - ballRadius && Math.abs(ballPosition.x) < 1187 + ballRadius && Math.abs(ballPosition.y) > 578 - ballRadius && Math.abs(ballPosition.y) < 607 + ballRadius)))
  943. }
  944.  
  945. function checkBallPosition() {
  946. if (activePlay) {
  947. var ballPosition = room.getBallPosition();
  948. if (boostUsed(ballPosition)) {
  949. clearTimeout(boostTimeout);
  950. boostUsedRecent = true;
  951. boostTimeout = setTimeout(() => { boostUsedRecent = false; }, 300);
  952. }
  953. if (isOutsideStadium(ballPosition)) {
  954. if (!isBallOutsideStadium) {
  955. isBallOutsideStadium = true;
  956. if (ballPosition.y > -127 && ballPosition.y < 127) return;
  957. if (ballPosition.x > stadiumW && lastTeamTouched == Team.RED || ballPosition.x < -stadiumW && lastTeamTouched == Team.BLUE) {
  958. room.sendChat("GK");
  959. ballSituation = "G";
  960. }
  961. else if (ballPosition.x > stadiumW && lastTeamTouched == Team.BLUE || ballPosition.x < -stadiumW && lastTeamTouched == Team.RED) {
  962. room.sendChat("CK");
  963. ballSituation = "C";
  964. }
  965. else {
  966. if (lastTeamTouched == Team.RED) {
  967. room.sendChat("B");
  968. ballSituation = Team.BLUE;
  969. throwDone = [false, ballPosition, null];
  970. }
  971. if (lastTeamTouched == Team.BLUE) {
  972. room.sendChat("R");
  973. ballSituation = Team.RED;
  974. throwDone = [false, ballPosition, null];
  975. }
  976. }
  977. }
  978. else {
  979. if ((ballSituation == Team.RED || ballSituation == Team.BLUE) && pointDistance(ballPosition, throwDone[1]) > throwInterval && !throwDone[0] && correctThrowPlace) {
  980. correctThrowPlace = false;
  981. if (ballPosition.x > throwDone[1].x) {
  982. if (ballSituation == Team.RED) room.sendChat("BACK");
  983. if (ballSituation == Team.BLUE) room.sendChat("FURTHER");
  984. }
  985. else {
  986. if (ballSituation == Team.RED) room.sendChat("FURTHER");
  987. if (ballSituation == Team.BLUE) room.sendChat("BACK");
  988. }
  989. }
  990. if ((ballSituation == Team.RED || ballSituation == Team.BLUE) && pointDistance(ballPosition, throwDone[1]) < throwInterval && !correctThrowPlace) {
  991. room.sendChat("OK");
  992. correctThrowPlace = true;
  993. }
  994. }
  995. }
  996. else {
  997. if (isBallOutsideStadium) {
  998. playersNotInLine.forEach((p) => { if (room.getPlayer(p.id) != null) setWarning(p, getWarning(p) + 1); warningHandle(p); });
  999. playersNotInLine = [];
  1000. correctThrowPlace = true;
  1001. ballSituation = "O";
  1002. }
  1003. isBallOutsideStadium = false;
  1004. }
  1005. }
  1006. }
  1007.  
  1008. function warningHandle(player) {
  1009. if (getWarning(player) == 1) room.sendChat("First line violation : Warning to " + player.name);
  1010. else if (getWarning(player) == 2) {
  1011. warningChange = true;
  1012. setTimeout(() => { warningChange = false; }, 10);
  1013. room.sendChat("Second line violation : 3 seconds suspension to " + player.name);
  1014. setTeam(player, true, Team.SPECTATORS);
  1015. setTimeout((p) => { warningChange = true; setTimeout(() => { warningChange = false; }, 10); setTeam(p, true, getRealTeam(p)); }, 3 * 1000, player);
  1016. }
  1017. else {
  1018. warningChange = true;
  1019. setTimeout(() => { warningChange = false; }, 10);
  1020. room.sendChat("Multiple line violations : 5 seconds suspension to " + player.name);
  1021. setTeam(player, true, Team.SPECTATORS);
  1022. setTimeout((p) => { warningChange = true; setTimeout(() => { warningChange = false; }, 10); setTeam(p, true, getRealTeam(p)); }, 5 * 1000, player);
  1023. }
  1024. }
  1025.  
  1026. function checkPlayersLine() {
  1027. playersNotInLine = [];
  1028. updateTeams();
  1029. var ballPosition = room.getBallPosition();
  1030. if (ballSituation == Team.RED || ballSituation == Team.BLUE) {
  1031. for (i = 0; i < players.length; i++) {
  1032. if (throwDone[0] && players[i].team != lastTeamTouched && players[i].team != ballSituation && players[i].team != Team.SPECTATORS) {
  1033. if ((players[i].position.y > greenLine - playerRadius || players[i].position.y < -greenLine + playerRadius) && pointDistance(ballPosition, players[i].position) < 270) {
  1034. playersNotInLine.push(players[i]);
  1035. }
  1036. }
  1037. }
  1038. }
  1039. else {
  1040. if (ballPosition.x < 0) {
  1041. if (ballSituation == "G" && lastTeamTouched == Team.RED && boostUsedRecent && Math.abs(ballPosition.y) < 350) {
  1042. for (i = 0; i < players.length; i++) {
  1043. if (players[i].team == Team.BLUE && Math.abs(players[i].position.x) > 840 - playerRadius && players[i].position.x * ballPosition.x > 0) playersNotInLine.push(players[i]);
  1044. }
  1045. }
  1046. else if (ballSituation == "C" && lastTeamTouched == Team.BLUE && boostUsedRecent && Math.abs(ballPosition.y) > 350) {
  1047. for (i = 0; i < players.length; i++) {
  1048. if (players[i].team == Team.RED && pointDistance({ "x": 1150, "y": 600 }, { "x": Math.abs(players[i].position.x), "y": Math.abs(players[i].position.y) }) < 340 + playerRadius) {
  1049. playersNotInLine.push(players[i]);
  1050. }
  1051. }
  1052. }
  1053. }
  1054. else {
  1055. if (ballSituation == "G" && lastTeamTouched == Team.BLUE && boostUsedRecent && Math.abs(ballPosition.y) < 350) {
  1056. for (i = 0; i < players.length; i++) {
  1057. if (players[i].team == Team.RED && Math.abs(players[i].position.x) > 840 - playerRadius && players[i].position.x * ballPosition.x > 0) playersNotInLine.push(players[i]);
  1058. }
  1059. }
  1060. else if (ballSituation == "C" && lastTeamTouched == Team.RED && boostUsedRecent && Math.abs(ballPosition.y) > 350) {
  1061. for (i = 0; i < players.length; i++) {
  1062. if (players[i].team == Team.BLUE && pointDistance({ "x": 1150, "y": 600 }, { "x": Math.abs(players[i].position.x), "y": Math.abs(players[i].position.y) }) < 340 + playerRadius) {
  1063. playersNotInLine.push(players[i]);
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070.  
  1071. function checkPenalty() {
  1072. if (penaltyMode && room.getScores().red + room.getScores().blue == 0) {
  1073. var ballPosition = room.getBallPosition();
  1074. if (ballPosition.x > 10 && ballProperties[0] < 2 || ballKickCounter > 1) {
  1075. if (!checkTimeVariable) {
  1076. checkTimeVariable = true;
  1077. ballKickCounter = 0;
  1078. setTimeout(() => { checkTimeVariable = false; }, 510);
  1079. if (turnPenalty[1] == 3) {
  1080. if (turnPenalty[0] == Team.RED) {
  1081. turnPenalty[0] = Team.BLUE;
  1082. turnPenalty[1] = 0;
  1083. room.sendChat("Blue Turn ! Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
  1084. }
  1085. else if (turnPenalty[0] == Team.BLUE) {
  1086. if (penaltyScores[0] == penaltyScores[1]) {
  1087. room.sendChat("Draw ! Restarting another series.");
  1088. turnPenalty[0] = Team.RED;
  1089. turnPenalty[1] = 0;
  1090. }
  1091. else endPenaltyMode();
  1092. }
  1093. }
  1094. else {
  1095. turnPenalty[1]++;
  1096. if (penaltyScores[1] > penaltyScores[0] || (turnPenalty[0] == Team.BLUE && penaltyScores[0] - penaltyScores[1] > maxTeamSize - turnPenalty[1])) {
  1097. endPenaltyMode();
  1098. }
  1099. room.sendChat("Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
  1100. }
  1101. setTimeout(() => { room.stopGame(); }, 100);
  1102. }
  1103. }
  1104. }
  1105. }
  1106.  
  1107. function endPenaltyMode() {
  1108. penaltyMode = false;
  1109. game = gamePenalty;
  1110. resetBtn();
  1111. penaltyScores[0] > penaltyScores[1] ? teamROrder.forEach((p) => setTeam(p, true, Team.RED)) : teamBOrder.forEach((p) => setTeam(p, true, Team.BLUE));
  1112. extendedP.forEach((p) => { if (room.getPlayer(p[eP.ID]) != null) p[eP.RT] = room.getPlayer(p[eP.ID]).team });
  1113. endGame((penaltyScores[0] > penaltyScores[1] ? Team.RED : Team.BLUE));
  1114. setTimeout(() => { room.stopGame(); }, 1500);
  1115. }
  1116.  
  1117. function penaltyPutPlayers() {
  1118. findGK();
  1119. resetBtn();
  1120. if (turnPenalty[0] == Team.RED) {
  1121. setTeam(teamROrder[turnPenalty[1]], true, Team.RED);
  1122. setTeam(GKList[1], true, Team.BLUE);
  1123. }
  1124. else {
  1125. setTeam(teamBOrder[turnPenalty[1]], true, Team.RED);
  1126. setTeam(GKList[0], true, Team.BLUE);
  1127. }
  1128. }
  1129.  
  1130. /* EVENTS */
  1131.  
  1132. /* PLAYER MOVEMENT */
  1133.  
  1134. room.onPlayerJoin = function (player) {
  1135. if (player.conn && extendedP) {
  1136. extendedP.forEach(p => {
  1137. if (player.conn === p[2]) {
  1138. room.kickPlayer(p[0], 'No entres dos veces a la sala', false);
  1139. }
  1140. });
  1141. }
  1142.  
  1143. fetch(logWebhook, { method: 'POST', body: JSON.stringify({ "content": "JOIN\n" + player.name + "[" + player.auth + "]", "username": roomName.replace(/[\W_]+/g, " ").substring(1,33) }), headers: { 'Content-Type': 'application/json' } }).then(res => res);
  1144. extendedP.push([player.id, player.auth, player.conn, false, 0, 0, false, 0, Team.SPECTATORS]);
  1145. updateRoleOnPlayerIn();
  1146. //room.sendChat("[PV] 👋 Welcome " + player.name + " ! Type '!help' to see the commands. Join our TS3: hbpt.ts.io, Discord: https://discord.gg/3MhhZPN ", player.id);
  1147. //room.sendChat("[PV] 👋 Register in our forum and get informed to our leagues (Big 4v4-3def ::: Real Soccer): https://haxball.pt/ ", player.id);
  1148. room.sendChat("[PV] 👋 Welcome " + player.name + " ! Type '!help' to see the commands. Join our Discord: https://discord.gg/3MhhZPN ", player.id);
  1149. room.sendChat("[PV] 👋 Discord Support: https://discord.gg/3MhhZPN ", player.id);
  1150. if (localStorage.getItem(player.auth) != null && JSON.parse(localStorage.getItem(player.auth))[Ss.RL] != "player") {
  1151. room.setPlayerAdmin(player.id, true);
  1152. room.sendChat((JSON.parse(localStorage.getItem(player.auth))[Ss.RL] == "master" ? "Master " : "Admin ") + player.name + " has connected to the room !");
  1153. }
  1154.  
  1155. if (players.length == maxPlayers - 2) { // Poner contraseña
  1156. room.setPassword(password)
  1157. }
  1158. }
  1159.  
  1160. room.onPlayerTeamChange = function (changedPlayer, byPlayer) {
  1161. updateOnTeamChange(changedPlayer, byPlayer);
  1162. }
  1163.  
  1164. room.onPlayerLeave = function (player) {
  1165. fetch(logWebhook, { method: 'POST', body: JSON.stringify({ "content": "LEAVE\n" + player.name + "[" + getAuth(player) + "]", "username": roomName.replace(/[\W_]+/g, " ").substring(1, 33) }), headers: { 'Content-Type': 'application/json' } }).then(res => res);
  1166. if ((teamR.findIndex((red) => red.id == player.id) == 0 && chooseMode && teamR.length <= teamB.length) || (teamB.findIndex((blue) => blue.id == player.id) == 0 && chooseMode && teamB.length < teamR.length)) {
  1167. choosePlayer();
  1168. capLeft = (teamR.findIndex((red) => red.id == player.id) == 0 && chooseMode && teamR.length <= teamB.length) ? Team.RED : Team.BLUE;
  1169. setTimeout(() => { capLeft = false; }, 10);
  1170. }
  1171. setActivity(player, 0);
  1172. setRealTeam(player, Team.SPECTATORS);
  1173. updateRoleOnPlayerOut();
  1174.  
  1175. if (players.length == maxPlayers - 3) { // Quitar contraseña
  1176. room.setPassword(null)
  1177. }
  1178. }
  1179.  
  1180. room.onPlayerKicked = function (kickedPlayer, reason, ban, byPlayer) {
  1181. if (ban) banList.push([kickedPlayer.name, kickedPlayer.id]);
  1182. }
  1183.  
  1184. /* PLAYER ACTIVITY */
  1185.  
  1186. room.onPlayerChat = function (player, message) {
  1187. // fetch(logWebhook, { method: 'POST', body: JSON.stringify({ "content": "CHAT\n" + player.name + " : " + message, "username": roomName.replace(/[\W_]+/g, " ") }), headers: { 'Content-Type': 'application/json' } }).then(res => res);
  1188. adminMessage = message;
  1189. message = message.split(/ +/);
  1190. if (player.team != Team.SPECTATORS) {
  1191. setActivity(player, 0);
  1192. }
  1193. if (["!help"].includes(message[0].toLowerCase())) {
  1194. room.sendChat("[PV] Player commands : !me, !discord, !ts3, !streak, !games, !wins, !goals, !assists, !cs, !mutes, !bans, !spec.", player.id);
  1195. if (player.admin) room.sendChat("[PV] Admin : !mute <duration = 3> #<id>, !unmute all/#<id>, !clearbans <number>, !slow <duration>, !endslow", player.id);
  1196. }
  1197. else if (["!afk"].includes(message[0].toLowerCase())) {
  1198. if (player.admin) {
  1199. if (players.length != 1 && player.team != Team.SPECTATORS) {
  1200. if (player.team == Team.RED && streak[0] > 0 && room.getScores() == null) setTeam(player, true,Team.SPECTATORS);
  1201. else {
  1202. room.sendChat("[PV] You can't go AFK while you're in a team !", player.id);
  1203. return false;
  1204. }
  1205. }
  1206. else if (players.length == 1 && !getAFK(player)) setTeam(player, true, Team.SPECTATORS);
  1207. setAFK(player, !getAFK(player));
  1208. room.sendChat(player.name + (getAFK(player) ? " is now AFK !" : " is not AFK anymore !"));
  1209. getAFK(player) ? updateRoleOnPlayerOut() : updateRoleOnPlayerIn();
  1210. }
  1211. }
  1212. else if (["!ts3"].includes(message[0].toLowerCase())) {
  1213. room.sendChat("Join our TS3: hbpt.ts.io , to play in our leagues (Big 4v4-3def ::: Real Soccer) ");
  1214. }
  1215. else if (["!discord"].includes(message[0].toLowerCase())) {
  1216. room.sendChat("Join our discord: https://discord.gg/3MhhZPN , to support/suggestions");
  1217. }
  1218. else if (["!save"].includes(message[0].toLowerCase())) {
  1219. if (player.admin) {
  1220. saveStats();
  1221. }
  1222. }
  1223. else if (["!afks", "!afklist"].includes(message[0].toLowerCase())) {
  1224. var cstm = "[PV] AFK List : ";
  1225. for (i = 0; i < extendedP.length; i++) {
  1226. if (room.getPlayer(extendedP[i][eP.ID]) != null && getAFK(room.getPlayer(extendedP[i][eP.ID]))) {
  1227. if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + ", ").length) {
  1228. room.sendChat(cstm, player.id);
  1229. cstm = "... ";
  1230. }
  1231. cstm += room.getPlayer(extendedP[i][eP.ID]).name + ", ";
  1232. }
  1233. }
  1234. if (cstm == "[PV] AFK List : ") {
  1235. room.sendChat("[PV] There's nobody in the AFK List !", player.id);
  1236. return false;
  1237. }
  1238. cstm = cstm.substring(0, cstm.length - 2) + ".";
  1239. room.sendChat(cstm, player.id);
  1240. }
  1241. else if (["!streak"].includes(message[0].toLowerCase())) {
  1242. var streakTime = JSON.parse(localStorage.getItem("streak"));
  1243. room.sendChat(`[PV] ⭐ Current streak is ${streak[0]}` + (streak[1].length != 0 ? ` : [${streak[1][0][0]}, ${streak[1][1][0]}, ${streak[1][2][0]}, ${streak[1][3][0]}] |` : " |") + ` 👑 Best streak is ${streakTime[0]}` + (streakTime[1].length != 0 ? ` : [${streakTime[1][0][0]}, ${streakTime[1][1][0]}, ${streakTime[1][2][0]}, ${streakTime[1][3][0]}]` : "."), player.id);
  1244. }
  1245. else if (["!me"].includes(message[0].toLowerCase())) {
  1246. var stats;
  1247. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0];
  1248. room.sendChat("[PV] " + player.name + "> Game: " + stats[Ss.GA] + ", Win: " + stats[Ss.WI] + ", 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] + "%, Streak: " + stats[Ss.ST], player.id);
  1249. }
  1250. else if (["!spec", "!specs"].includes(message[0].toLowerCase())) {
  1251. getSpecList(Team.SPECTATORS, player);
  1252. }
  1253. else if (["!games"].includes(message[0].toLowerCase())) {
  1254. showRankings(Ss.GA, "Games", player);
  1255. }
  1256. else if (["!wins"].includes(message[0].toLowerCase())) {
  1257. showRankings(Ss.WI, "Wins", player);
  1258. }
  1259. else if (["!goals"].includes(message[0].toLowerCase())) {
  1260. showRankings(Ss.GL, "Goals", player);
  1261. }
  1262. else if (["!assists"].includes(message[0].toLowerCase())) {
  1263. showRankings(Ss.AS, "Assists", player);
  1264. }
  1265. else if (["!cs"].includes(message[0].toLowerCase())) {
  1266. showRankings(Ss.CS, "CS", player);
  1267. }
  1268. else if (["!claim"].includes(message[0].toLowerCase())) {
  1269. if (message[1] == masterPassword || message[1] == adminPassword) {
  1270. room.setPlayerAdmin(player.id, true);
  1271. var stats;
  1272. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", 0, "player", player.name];
  1273. if (message[1] == masterPassword && stats[Ss.RL] != "master") {
  1274. stats[Ss.RL] = "master";
  1275. room.sendChat(player.name + " is now a room master !");
  1276. localStorage.setItem(getAuth(player), JSON.stringify(stats));
  1277. }
  1278. else if (message[1] == adminPassword && stats[Ss.RL] == "player") {
  1279. stats[Ss.RL] = "admin";
  1280. room.sendChat(player.name + " is now a room admin !");
  1281. localStorage.setItem(getAuth(player), JSON.stringify(stats));
  1282. }
  1283. }
  1284. }
  1285. else if (["!setadmin", "!admin"].includes(message[0].toLowerCase())) {
  1286. if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
  1287. if (message.length >= 2 && message[1][0] == "#") {
  1288. message[1] = message[1].substring(1, message[1].length);
  1289. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  1290. var stats;
  1291. 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.00", 0, 0, 0, 0, "0.00", 0, "player", room.getPlayer(Number.parseInt(message[1])).name];
  1292. if (stats[Ss.RL] == "player") {
  1293. stats[Ss.RL] = "admin";
  1294. localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
  1295. room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, true);
  1296. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " is now an administrator of the room !");
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. else if (["!setplayer", "!removeadmin"].includes(message[0].toLowerCase())) {
  1303. if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
  1304. if (message.length >= 2 && message[1][0] == "#") {
  1305. message[1] = message[1].substring(1, message[1].length);
  1306. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  1307. var stats;
  1308. 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.00", 0, 0, 0, 0, "0.00", 0, "player", room.getPlayer(Number.parseInt(message[1])).name];
  1309. if (stats[Ss.RL] == "admin") {
  1310. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " is not an administrator of the room anymore !");
  1311. stats[Ss.RL] = "player";
  1312. localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
  1313. room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, false);
  1314. }
  1315. }
  1316. }
  1317. }
  1318. }
  1319. else if (["!mutes", "!mutelist"].includes(message[0].toLowerCase())) {
  1320. var cstm = "[PV] Mute List : ";
  1321. for (i = 0; i < extendedP.length; i++) {
  1322. if (room.getPlayer(extendedP[i][eP.ID]) != null && getMute(room.getPlayer(extendedP[i][eP.ID]))) {
  1323. if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ").length) {
  1324. room.sendChat(cstm, player.id);
  1325. cstm = "... ";
  1326. }
  1327. cstm += room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ";
  1328. }
  1329. }
  1330. if (cstm == "[PV] Mute List : ") {
  1331. room.sendChat("[PV] There's nobody in the Mute List !", player.id);
  1332. return false;
  1333. }
  1334. cstm = cstm.substring(0, cstm.length - 2) + ".";
  1335. room.sendChat(cstm, player.id);
  1336. }
  1337. else if (["!mute"].includes(message[0].toLowerCase())) {
  1338. if (player.admin) {
  1339. updateTeams();
  1340. var timeOut;
  1341. if (!Number.isNaN(Number.parseInt(message[1])) && message.length > 1) {
  1342. if (Number.parseInt(message[1]) > 0) timeOut = Number.parseInt(message[1]) * 60 * 1000;
  1343. else timeOut = 3 * 60 * 1000;
  1344. if (message[2].length > 1 && message[2][0] == "#") {
  1345. message[2] = message[2].substring(1, message[2].length);
  1346. if (!Number.isNaN(Number.parseInt(message[2])) && room.getPlayer(Number.parseInt(message[2])) != null) {
  1347. if (room.getPlayer(Number.parseInt(message[2])).admin || getMute(room.getPlayer(Number.parseInt(message[2])))) return false;
  1348. setTimeout(function (player) {
  1349. setMute(player, false);
  1350. }, timeOut, room.getPlayer(Number.parseInt(message[2])));
  1351. setMute(room.getPlayer(Number.parseInt(message[2])), true);
  1352. room.sendChat(room.getPlayer(Number.parseInt(message[2])).name + " has been muted for " + (timeOut / 60000) + " minutes!");
  1353. }
  1354. }
  1355. }
  1356. else if (Number.isNaN(Number.parseInt(message[1]))) {
  1357. if (message[1].length > 1 && message[1][0] == "#") {
  1358. message[1] = message[1].substring(1, message[1].length);
  1359. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  1360. if (room.getPlayer(Number.parseInt(message[1])).admin || getMute(room.getPlayer(Number.parseInt(message[1])))) return false;
  1361. setTimeout(function (player) {
  1362. setMute(player, false);
  1363. }, 3 * 60 * 1000, room.getPlayer(Number.parseInt(message[1])));
  1364. setMute(room.getPlayer(Number.parseInt(message[1])), true);
  1365. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been muted for 3 minutes!");
  1366. }
  1367. }
  1368. }
  1369. }
  1370. }
  1371. else if (["!unmute"].includes(message[0].toLowerCase())) {
  1372. if (player.admin && message.length >= 2) {
  1373. if (message[1] == "all") {
  1374. extendedP.forEach((ePlayer) => {
  1375. ePlayer[eP.MUTE] = false;
  1376. });
  1377. room.sendChat("Mutes cleared.");
  1378. }
  1379. else if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1380. setMute(room.getPlayer(Number.parseInt(message[1])), false);
  1381. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
  1382. }
  1383. else if (Number.isNaN(Number.parseInt(message[1]))) {
  1384. if (message[1].length > 1 && message[1][0] == "#") {
  1385. message[1] = message[1].substring(1, message[1].length);
  1386. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1387. setMute(room.getPlayer(Number.parseInt(message[1])), false);
  1388. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. else if (["!slow"].includes(message[0].toLowerCase())) {
  1395. if (player.admin) {
  1396. if (message.length == 1) {
  1397. slowMode = 2;
  1398. room.sendChat("2 seconds slow mode enabled !");
  1399. }
  1400. else if (message.length == 2) {
  1401. if (!Number.isNaN(Number.parseInt(message[1]))) {
  1402. if (Number.parseInt(message[1]) > 0) {
  1403. slowMode = Number.parseInt(message[1]);
  1404. room.sendChat(slowMode + " seconds slow mode enabled !");
  1405. return false;
  1406. }
  1407. }
  1408. slowMode = 2;
  1409. room.sendChat("2 seconds slow mode enabled !");
  1410. }
  1411. }
  1412. }
  1413. else if (["!endslow"].includes(message[0].toLowerCase())) {
  1414. if (player.admin) {
  1415. if (slowMode != 0) room.sendChat("Slow mode terminated.");
  1416. slowMode = 0;
  1417. }
  1418. }
  1419. else if (["!banlist", "!bans"].includes(message[0].toLowerCase())) {
  1420. if (banList.length == 0) {
  1421. room.sendChat("[PV] There's nobody in the Ban List !", player.id);
  1422. return false;
  1423. }
  1424. var cstm = "[PV] Ban List : ";
  1425. for (i = 0; i < banList.length; i++) {
  1426. if (140 - cstm.length < (banList[i][0] + "[" + (banList[i][1]) + "], ").length) {
  1427. room.sendChat(cstm, player.id);
  1428. cstm = "... ";
  1429. }
  1430. cstm += banList[i][0] + "[" + (banList[i][1]) + "], ";
  1431. }
  1432. cstm = cstm.substring(0, cstm.length - 2) + ".";
  1433. room.sendChat(cstm, player.id);
  1434. }
  1435. else if (["!clearbans"].includes(message[0].toLowerCase())) {
  1436. if (player.admin) {
  1437. /*if (message.length == 1) {
  1438. room.clearBans();
  1439. room.sendChat("Bans cleared !");
  1440. banList = [];
  1441. }*/
  1442. if (message.length == 2) {
  1443. if (!Number.isNaN(Number.parseInt(message[1]))) {
  1444. if (Number.parseInt(message[1]) > 0) {
  1445. ID = Number.parseInt(message[1]);
  1446. room.clearBan(ID);
  1447. if (banList.length != banList.filter((array) => array[1] != ID)) room.sendChat(banList.filter((array) => array[1] == ID)[0][0] + " has been unbanned from the room !");
  1448. setTimeout(() => {
  1449. banList = banList.filter((array) => array[1] != ID);
  1450. }, 20);
  1451. }
  1452. }
  1453. }
  1454. }
  1455. }
  1456. else if (["!bb", "!bye", "!cya", "!gn"].includes(message[0].toLowerCase())) room.kickPlayer(player.id, "Bye !", false);
  1457. if (teamR.length != 0 && teamB.length != 0 && chooseMode) {
  1458. if (player.id == teamROrder[0].id || player.id == teamBOrder[0].id) {
  1459. var playerChosen;
  1460. if (teamR.length <= teamB.length && player.id == teamROrder[0].id) {
  1461. if (["top", "auto"].includes(message[0].toLowerCase())) {
  1462. setTeam(teamS[0], true, Team.RED);
  1463. redCaptainChoice = "top";
  1464. clearTimeout(timeOutCap);
  1465. room.sendChat(player.name + " chose Top !");
  1466. return false;
  1467. }
  1468. else if (["random", "rand"].includes(message[0].toLowerCase())) {
  1469. setTeam(teamS[getRandomInt(teamS.length)], true, Team.RED);
  1470. redCaptainChoice = "random";
  1471. clearTimeout(timeOutCap);
  1472. room.sendChat(player.name + " chose Random !");
  1473. return false;
  1474. }
  1475. else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
  1476. setTeam(teamS[teamS.length - 1], true, Team.RED);
  1477. redCaptainChoice = "bottom";
  1478. clearTimeout(timeOutCap);
  1479. room.sendChat(player.name + " chose Bottom !");
  1480. return false;
  1481. }
  1482. else if (!Number.isNaN(Number.parseInt(message[0]))) {
  1483. if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
  1484. room.sendChat("[PV] Your number is invalid !", player.id);
  1485. return false;
  1486. }
  1487. else {
  1488. playerChosen = teamS[Number.parseInt(message[0]) - 1];
  1489. setTeam(playerChosen, true, Team.RED);
  1490. room.sendChat(player.name + " chose " + playerChosen.name + " !");
  1491. return false;
  1492. }
  1493. }
  1494. }
  1495. if (teamR.length > teamB.length && player.id == teamBOrder[0].id) {
  1496. if (["top", "auto"].includes(message[0].toLowerCase())) {
  1497. setTeam(teamS[0], true, Team.BLUE);
  1498. blueCaptainChoice = "top";
  1499. clearTimeout(timeOutCap);
  1500. room.sendChat(player.name + " chose Top !");
  1501. return false;
  1502. }
  1503. else if (["random", "rand"].includes(message[0].toLowerCase())) {
  1504. setTeam(teamS[getRandomInt(teamS.length)], true, Team.BLUE);
  1505. blueCaptainChoice = "random";
  1506. clearTimeout(timeOutCap);
  1507. room.sendChat(player.name + " chose Random !");
  1508. return false;
  1509. }
  1510. else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
  1511. setTeam(teamS[teamS.length - 1], true, Team.BLUE);
  1512. blueCaptainChoice = "bottom";
  1513. clearTimeout(timeOutCap);
  1514. room.sendChat(player.name + " chose Bottom !");
  1515. return false;
  1516. }
  1517. else if (!Number.isNaN(Number.parseInt(message[0]))) {
  1518. if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
  1519. room.sendChat("[PV] Your number is invalid !", player.id);
  1520. return false;
  1521. }
  1522. else {
  1523. playerChosen = teamS[Number.parseInt(message[0]) - 1];
  1524. setTeam(playerChosen, true, Team.BLUE);
  1525. room.sendChat(player.name + " chose " + playerChosen.name + " !");
  1526. return false;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. if (message[0][0] == "!") return false;
  1533. if (getMute(player)) {
  1534. room.sendChat("[PV] You are muted.", player.id);
  1535. return false;
  1536. }
  1537. if (slowMode > 0) {
  1538. if (!player.admin) {
  1539. if (!SMSet.has(player.id)) {
  1540. SMSet.add(player.id);
  1541. setTimeout((number) => {
  1542. SMSet.delete(number);
  1543. }, slowMode * 1000, player.id);
  1544. }
  1545. else {
  1546. room.sendChat("[PV] " + slowMode + " seconds slow mode enabled ! Don't spam chat.", player.id)
  1547. return false;
  1548. }
  1549. }
  1550. }
  1551.  
  1552. if (player.admin) {
  1553. // Si el usuario es admin, mandar un announcement
  1554. var adminChatColor = 0x33FFE0; // Formato: 0xCOLOR (sustituye COLOR por el color en HEXADECIMAL, ejemplo azul es 33FFE0)
  1555.  
  1556. room.sendAnnouncement(`${player.name}: ${adminMessage}`, null, adminChatColor, 'bold', null);
  1557. return false;
  1558. }
  1559. }
  1560.  
  1561. room.onPlayerActivity = function (player) {
  1562. setActivity(player, 0);
  1563. }
  1564.  
  1565. room.onPlayerBallKick = function (player) {
  1566. if (lastPlayersTouched[0] == null || player.id != lastPlayersTouched[0].id) {
  1567. if (!activePlay) activePlay = true;
  1568. lastTeamTouched = player.team;
  1569. lastPlayersTouched[1] = lastPlayersTouched[0];
  1570. lastPlayersTouched[0] = player;
  1571. }
  1572. if (isBallOutsideStadium) {
  1573. var ballPosition = room.getBallPosition();
  1574. if (ballPosition.y > 0) {
  1575. if (player.position.y > ballPosition.y) {
  1576. throwDone[0] = true;
  1577. throwDone[2] = ballPosition;
  1578. correctThrowPlace = true;
  1579. }
  1580. }
  1581. if (ballPosition.y < 0) {
  1582. if (player.position.y < ballPosition.y) {
  1583. throwDone[0] = true;
  1584. throwDone[2] = ballPosition;
  1585. correctThrowPlace = true;
  1586. }
  1587. }
  1588. checkPlayersLine();
  1589. }
  1590. if (penaltyMode && player.team == Team.RED) ballKickCounter++;
  1591. }
  1592.  
  1593. /* GAME MANAGEMENT */
  1594.  
  1595. room.onGameStart = function (byPlayer) {
  1596. if (!penaltyMode) {
  1597. endGameVariable = false;
  1598. if (teamR.length != teamB.length && players.length > 1) {
  1599. room.stopGame();
  1600. balanceTeams();
  1601. return;
  1602. }
  1603. game = new Game(Date.now(), room.getScores(), [], []);
  1604. playersNotInLine = [];
  1605. countAFK = true;
  1606. activePlay = false;
  1607. goldenGoal = false;
  1608. lastPlayersTouched = [null, null];
  1609. teamROrder = teamR;
  1610. teamBOrder = teamB;
  1611. Rposs = 0;
  1612. Bposs = 0;
  1613. GKList = [];
  1614. allReds = [];
  1615. allBlues = [];
  1616. timeOutside = 0;
  1617. isTimeAddedShown = false;
  1618. throwDone = [];
  1619. correctThrowPlace = true;
  1620. penaltyScores = [-1, -1];
  1621. turnPenalty = [1, 0];
  1622. if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) {
  1623. for (i = 0; i < maxTeamSize; i++) {
  1624. allReds.push(teamR[i]);
  1625. allBlues.push(teamB[i]);
  1626. }
  1627. }
  1628. for (i = 0; i < extendedP.length; i++) {
  1629. extendedP[i][eP.GK] = 0;
  1630. extendedP[i][eP.ACT] = 0;
  1631. extendedP[i][eP.WARN] = 0;
  1632. if (room.getPlayer(extendedP[i][eP.ID]) == null) extendedP.splice(i, 1);
  1633. }
  1634. deactivateChooseMode();
  1635. }
  1636. ballKickCounter = 0;
  1637. }
  1638.  
  1639. room.onGameStop = function (byPlayer) {
  1640. if (players.length > 5) orderTeamsBtn();
  1641. if (byPlayer.id == 0 && endGameVariable) {
  1642. updateTeams();
  1643. if (penaltyScores[0] != penaltyScores[1]) {
  1644. if (players.length < 6) setTimeout(() => { loadMap(classicMap, scoreLimitClassic, timeLimitClassic); }, 10);
  1645. else setTimeout(() => { loadMap(bigMap, scoreLimitBig, timeLimitBig); }, 10);
  1646. }
  1647. if (chooseMode) {
  1648. if (players.length == 2 * maxTeamSize) {
  1649. chooseMode = false;
  1650. streak = [0, []];
  1651. resetBtn();
  1652. for (i = 0; i < maxTeamSize; i++) setTimeout(() => { randomBtn(); }, 450 * i);
  1653. setTimeout(() => { room.startGame(); }, 2000);
  1654. }
  1655. else {
  1656. if (lastWinner == Team.RED) blueToSpecBtn();
  1657. else if (lastWinner == Team.BLUE) {
  1658. redToSpecBtn();
  1659. blueToRedBtn();
  1660. }
  1661. else resetBtn();
  1662. setTimeout(() => { topBtn(); }, 25);
  1663. }
  1664. }
  1665. else {
  1666. if (players.length == 2) {
  1667. if (lastWinner == Team.BLUE) {
  1668. setTeam(teamB[0], true, Team.RED);
  1669. setTeam(teamR[0], true, Team.BLUE);
  1670. }
  1671. setTimeout(() => { room.startGame(); }, 2000);
  1672. }
  1673. else if (players.length == 3 || players.length >= 2 * maxTeamSize + 1) {
  1674. if (lastWinner == Team.RED) blueToSpecBtn();
  1675. else {
  1676. redToSpecBtn();
  1677. blueToRedBtn();
  1678. }
  1679. setTimeout(() => { topBtn(); }, 25);
  1680. setTimeout(() => { room.startGame(); }, 2000);
  1681. }
  1682. else if (players.length == 4) {
  1683. resetBtn();
  1684. setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500);
  1685. setTimeout(() => { room.startGame(); }, 2000);
  1686. }
  1687. else if (players.length == 5 || players.length >= 2 * maxTeamSize + 1) {
  1688. if (lastWinner == Team.RED) blueToSpecBtn();
  1689. else {
  1690. redToSpecBtn();
  1691. blueToRedBtn();
  1692. }
  1693. setTimeout(() => { topBtn(); }, 25);
  1694. activateChooseMode();
  1695. }
  1696. else if (players.length == 6) {
  1697. resetBtn();
  1698. setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500); }, 500);
  1699. setTimeout(() => { room.startGame(); }, 2000);
  1700. }
  1701. }
  1702. }
  1703. else if (byPlayer.id == 0 && penaltyMode && !chooseMode) {
  1704. penaltyPutPlayers();
  1705. setTimeout(() => { room.startGame(); }, 2000);
  1706. }
  1707. }
  1708.  
  1709. room.onGamePause = function (byPlayer) {
  1710. }
  1711.  
  1712. room.onGameUnpause = function (byPlayer) {
  1713. if (teamR.length == maxTeamSize && teamB.length == maxTeamSize && chooseMode || (teamR.length == teamB.length && teamS.length < 2 && chooseMode)) {
  1714. deactivateChooseMode();
  1715. }
  1716. }
  1717.  
  1718. room.onTeamGoal = function (team) {
  1719. if (!penaltyMode) {
  1720. activePlay = false;
  1721. countAFK = false;
  1722. const scores = room.getScores();
  1723. game.scores = scores;
  1724. if (lastPlayersTouched[0] != null && lastPlayersTouched[0].team == team) {
  1725. if (lastPlayersTouched[1] != null && lastPlayersTouched[1].team == team) {
  1726. room.sendChat("⚽ " + getTime(scores) + " Goal by " + lastPlayersTouched[0].name + " ! Assist by " + lastPlayersTouched[1].name + ". Goal speed : " + ballProperties[0].toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1727. game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], lastPlayersTouched[1]));
  1728. }
  1729. else {
  1730. room.sendChat("⚽ " + getTime(scores) + " Goal by " + lastPlayersTouched[0].name + " ! Goal speed : " + ballProperties[0].toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1731. game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], null));
  1732. }
  1733. }
  1734. else {
  1735. room.sendChat("😂 " + getTime(scores) + " Own Goal by " + lastPlayersTouched[0].name + " ! Goal speed : " + ballProperties[0].toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1736. game.goals.push(new Goal(scores.time, team, null, null));
  1737. }
  1738. if (scores.scoreLimit != 0 && (scores.red == scores.scoreLimit || scores.blue == scores.scoreLimit && scores.blue > 0 || goldenGoal == true)) {
  1739. endGame(team);
  1740. goldenGoal = false;
  1741. setTimeout(() => { room.stopGame(); }, 1000);
  1742. }
  1743. }
  1744. else {
  1745. if (team == Team.RED) {
  1746. if (turnPenalty[0] == Team.RED) penaltyScores[0]++;
  1747. else penaltyScores[1]++;
  1748. }
  1749. if (turnPenalty[1] == 3) {
  1750. if (turnPenalty[0] == Team.RED) {
  1751. turnPenalty[0] = Team.BLUE;
  1752. turnPenalty[1] = 0;
  1753. room.sendChat("Blue Turn ! Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
  1754. }
  1755. else if (turnPenalty[0] == Team.BLUE) {
  1756. if (penaltyScores[0] == penaltyScores[1]) {
  1757. room.sendChat("Draw ! Restarting another series.");
  1758. turnPenalty[0] = Team.RED;
  1759. turnPenalty[1] = 0;
  1760. }
  1761. else endPenaltyMode();
  1762. }
  1763. }
  1764. else {
  1765. turnPenalty[1]++;
  1766. if (penaltyScores[1] > penaltyScores[0] || (turnPenalty[0] == Team.BLUE && penaltyScores[0] - penaltyScores[1] > maxTeamSize - turnPenalty[1])) {
  1767. endPenaltyMode();
  1768. }
  1769. room.sendChat("Score : " + penaltyScores[0] + "-" + penaltyScores[1]);
  1770. }
  1771. setTimeout(() => { room.stopGame(); }, 500);
  1772. }
  1773. }
  1774.  
  1775. room.onPositionsReset = function () {
  1776. countAFK = true;
  1777. lastPlayersTouched = [null, null];
  1778. playersNotInLine = [];
  1779. }
  1780.  
  1781. /* MISCELLANEOUS */
  1782.  
  1783. room.onRoomLink = function (url) {
  1784. console.log(url);
  1785. console.log("masterPassword : " + masterPassword);
  1786. console.log("adminPassword : " + adminPassword);
  1787. }
  1788.  
  1789. room.onPlayerAdminChange = function (changedPlayer, byPlayer) {
  1790. if (getMute(changedPlayer) && changedPlayer.admin) {
  1791. room.sendChat(changedPlayer.name + " has been unmuted.");
  1792. setMute(changedPlayer, false);
  1793. }
  1794. if (byPlayer.id != 0 && localStorage.getItem(getAuth(byPlayer)) && JSON.parse(localStorage.getItem(getAuth(byPlayer)))[Ss.RL] == "admin") {
  1795. room.sendChat("You don't have permission to name a player admin !", byPlayer.id);
  1796. room.setPlayerAdmin(changedPlayer.id, false);
  1797. }
  1798. if (byPlayer.id != 0 && localStorage.getItem(getAuth(changedPlayer)) && (JSON.parse(localStorage.getItem(getAuth(changedPlayer)))[Ss.RL] == "admin" || JSON.parse(localStorage.getItem(getAuth(byPlayer)))[Ss.RL] == "master") && changedPlayer.admin == false) {
  1799. room.sendChat("You don't have permission to change rights !", byPlayer.id);
  1800. room.setPlayerAdmin(changedPlayer.id, true);
  1801. }
  1802. }
  1803.  
  1804. room.onStadiumChange = function (newStadiumName, byPlayer) {
  1805. }
  1806.  
  1807. room.onGameTick = function () {
  1808. if (!penaltyMode) {
  1809. checkTime();
  1810. checkBallPosition();
  1811. }
  1812. getStats();
  1813. handleInactivity();
  1814. getLastTouchOfTheBall();
  1815. checkPenalty();
  1816. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement