Advertisement
Guest User

meme

a guest
May 1st, 2019
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.20 KB | None | 0 0
  1. var roomName = "[NARS] REAL SOCCER 24/7";
  2. var maxPlayers = 20;
  3. var roomPublic = false;
  4. var playerName = "NARS REF";
  5.  
  6. /* STADIUM */
  7. //Wartości dotyczą boiska na którym rozgrywany jest mecz - wartości domyślne to oficjalna mapa RS
  8. var stadiumWidth = 1150;
  9. var stadiumHeight = 600;
  10. var radiusBall = 9.8;
  11. var throwInLeeway = 350;
  12. var greenLine = 510;
  13.  
  14. /* SETTINGS */
  15.  
  16. var triggerDistance = radiusBall + 15 + 0.01;
  17. var outLineY = stadiumWidth - (radiusBall / 2) + 6;
  18. stadiumWidth += (radiusBall / 2) + 6;
  19. stadiumHeight += (radiusBall / 2) + 6;
  20.  
  21. var Team = {
  22. SPECTATORS: 0,
  23. RED: 1,
  24. BLUE: 2
  25. };
  26. var lastScores = 0;
  27. var lastTeamTouched = 0;
  28. var lineBallPosition;
  29. var exitingPos = null;
  30. var previousBallPos;
  31. var assistingTouch = "";
  32. var lastPlayerTouched = "";
  33. var lat = 40;
  34. var long = -74;
  35. var backMSG = false;
  36. var lastCall;
  37. var isBallUp = false;
  38. var crossed = false;
  39. var isTimeAddedShown = false;
  40. var lineCrossedPlayers = [{name: "temp", times: 0}];
  41. var isBallKickedOutside = false;
  42. var previousPlayerTouched;
  43. var timeOutside = 0;
  44. var room = HBInit({ roomName: roomName, maxPlayers: maxPlayers, public: roomPublic, playerName: playerName,token: "thr1.AAAAAFyRjgZMy18R2w9YjQ.-FYMqQV18YE", geo: {"code": "CA", "lat": lat, "lon": long }});
  45. var RSHLMap = `{ "name" : "Real Soccer 1.3D by RawR", "width" : 1300, "height" : 670, "spawnDistance" : 500, "bg" : { "type" : "grass", "width" : 1150, "height" : 600, "kickOffRadius" : 180, "cornerRadius" : 0 },"playerPhysics" : {"bCoef" : 0.5,"invMass" : 0.5,"damping" : 0.96,"acceleration" : 0.12,"kickingAcceleration" : 0.07,"kickingDamping" : 0.96,"kickStrength" : 5.65},"vertexes" : [/* 0 */ { "x" : 0, "y" : 700, "trait" : "kickOffBarrier" },/* 1 */ { "x" : 0, "y" : 180, "trait" : "kickOffBarrier" },/* 2 */ { "x" : 0, "y" : -180, "trait" : "kickOffBarrier" },/* 3 */ { "x" : 0, "y" : -700, "trait" : "kickOffBarrier" }, /* 4 */ { "x" : 1150, "y" : 255, "trait" : "line" },/* 5 */ { "x" : 840, "y" : 255, "trait" : "line" },/* 6 */ { "x" : 1150, "y" : -255, "trait" : "line" }, /* 7 */ { "x" : 840, "y" : -255, "trait" : "line" }, /* 8 */ { "x" : 1150, "y" : 155, "trait" : "line" }, /* 9 */ { "x" : 1030, "y" : 155, "trait" : "line" }, /* 10 */ { "x" : 1150, "y" : -155, "trait" : "line" }, /* 11 */ { "x" : 1030, "y" : -155, "trait" : "line" }, /* 12 */ { "x" : 840, "y" : -135, "trait" : "line", "curve" : -130 }, /* 13 */ { "x" : 840, "y" : 135, "trait" : "line", "curve" : -130 }, /* 14 */ { "x" : -1150, "y" : -255, "trait" : "line", "curve" : -90, "color" : "97AC86" }, /* 15 */ { "x" : -840, "y" : -255, "trait" : "line" }, /* 16 */ { "x" : -1150, "y" : 255, "trait" : "line" }, /* 17 */ { "x" : -840, "y" : 255, "trait" : "line" }, /* 18 */ { "x" : -1150, "y" : -155, "trait" : "line" }, /* 19 */ { "x" : -1030, "y" : -155, "trait" : "line" }, /* 20 */ { "x" : -1150, "y" : 155, "trait" : "line" }, /* 21 */ { "x" : -1030, "y" : 155, "trait" : "line" }, /* 22 */ { "x" : -840, "y" : 135, "trait" : "line", "curve" : -130 }, /* 23 */ { "x" : -840, "y" : -135, "trait" : "line", "curve" : -130 }, /* 24 */ { "x" : 935, "y" : 4, "trait" : "line" }, /* 25 */ { "x" : 935, "y" : -4, "trait" : "line" }, /* 26 */ { "x" : -935, "y" : 4, "trait" : "line" }, /* 27 */ { "x" : -935, "y" : -4, "trait" : "line" }, /* 28 */ { "x" : -1150, "y" : 525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 29 */ { "x" : -1075, "y" : 600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line", "_selected" : true }, /* 30 */ { "x" : -1075, "y" : -600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 31 */ { "x" : -1150, "y" : -525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 32 */ { "x" : 1075, "y" : 600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 33 */ { "x" : 1150, "y" : 525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 34 */ { "x" : 1150, "y" : -525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 35 */ { "x" : 1075, "y" : -600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" }, /* 36 */ { "x" : -1150, "y" : 127, "trait" : "line", "color" : "ffffff" }, /* 37 */ { "x" : -1214, "y" : 124, "trait" : "line", "color" : "ffffff", "curve" : 5 }, /* 38 */ { "x" : -1150, "y" : -127, "trait" : "line", "color" : "ffffff" }, /* 39 */ { "x" : -1214, "y" : -124, "trait" : "line", "color" : "ffffff", "curve" : 5 }, /* 40 */ { "x" : 1150, "y" : 127, "trait" : "line", "color" : "ffffff" }, /* 41 */ { "x" : 1214, "y" : 124, "trait" : "line", "color" : "ffffff", "curve" : -5 }, /* 42 */ { "x" : 1150, "y" : -127, "trait" : "line", "color" : "ffffff" }, /* 43 */ { "x" : 1214, "y" : -124, "trait" : "line", "color" : "ffffff", "curve" : -5 }, /* 44 */ { "x" : 0, "y" : -4, "trait" : "line" }, /* 45 */ { "x" : 0, "y" : 4, "trait" : "line" }, /* 46 */ { "x" : 0, "y" : -4, "trait" : "line" }, /* 47 */ { "x" : 0, "y" : 4, "trait" : "line" }, /* 48 */ { "x" : -1214, "y" : 124, "trait" : "line", "color" : "ffffff" }, /* 49 */ { "x" : -1250, "y" : 150, "trait" : "line", "color" : "ffffff", "pos" : [-1250,150 ] }, /* 50 */ { "x" : -1214, "y" : -124, "trait" : "line", "color" : "ffffff" }, /* 51 */ { "x" : -1250, "y" : -150, "trait" : "line", "color" : "ffffff", "pos" : [-1250,-150 ] }, /* 52 */ { "x" : 1214, "y" : 124, "trait" : "line", "color" : "ffffff" }, /* 53 */ { "x" : 1250, "y" : 150, "trait" : "line", "color" : "ffffff" }, /* 54 */ { "x" : 1214, "y" : -124, "trait" : "line", "color" : "ffffff" }, /* 55 */ { "x" : 1250, "y" : -150, "trait" : "line", "color" : "ffffff" }, /* 56 */ { "x" : -1185, "y" : 155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" }, /* 57 */ { "x" : -1185, "y" : 255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" }, /* 58 */ { "x" : 1185, "y" : 155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" }, /* 59 */ { "x" : 1185, "y" : 255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" }, /* 60 */ { "x" : -1185, "y" : -155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" }, /* 61 */ { "x" : -1185, "y" : -255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" }, /* 62 */ { "x" : 1185, "y" : -155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" }, /* 63 */ { "x" : 1185, "y" : -255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" }, /* 64 */ { "x" : 1158, "y" : -607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" }, /* 65 */ { "x" : 1187, "y" : -578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : -60, "color" : "BEB86C" }, /* 66 */ { "x" : 1158, "y" : 607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" }, /* 67 */ { "x" : 1187, "y" : 578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 60, "color" : "BEB86C" }, /* 68 */ { "x" : -1158, "y" : 607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" }, /* 69 */ { "x" : -1187, "y" : 578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : -60, "color" : "BEB86C" }, /* 70 */ { "x" : -1158, "y" : -607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" }, /* 71 */ { "x" : -1187, "y" : -578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 60, "color" : "BEB86C" }, /* 72 */ { "x" : -1190, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 73 */ { "x" : -1180, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 74 */ { "x" : -1190, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 75 */ { "x" : -1180, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 76 */ { "x" : -1190, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 77 */ { "x" : -1180, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 78 */ { "x" : -1190, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 79 */ { "x" : -1180, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 80 */ { "x" : 1190, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 81 */ { "x" : 1180, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 82 */ { "x" : 1190, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 83 */ { "x" : 1180, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 84 */ { "x" : 1190, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 85 */ { "x" : 1180, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 86 */ { "x" : 1190, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 87 */ { "x" : 1180, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 }, /* 88 */ { "x" : -1148, "y" : -525, "trait" : "line", "curve" : -90, "color" : "5E844D" }, /* 89 */ { "x" : 1148, "y" : -525, "trait" : "line", "color" : "5E844D" }, /* 90 */ { "x" : -1148, "y" : 525, "trait" : "line", "curve" : -90, "color" : "5E844D" }, /* 91 */ { "x" : 1148, "y" : 525, "trait" : "line", "color" : "5E844D" }, /* 92 */ { "x" : -1150, "y" : -260, "trait" : "line", "curve" : -100, "color" : "5E844D" }, /* 93 */ { "x" : -840, "y" : -600, "trait" : "line", "color" : "5E844D", "curve" : -100 }, /* 94 */ { "x" : -1150, "y" : 260, "trait" : "line", "curve" : 100, "color" : "5E844D" }, /* 95 */ { "x" : -840, "y" : 600, "trait" : "line", "color" : "5E844D", "curve" : 100 }, /* 96 */ { "x" : -840, "y" : -1150, "trait" : "line", "color" : "5E844D", "curve" : -100 }, /* 97 */ { "x" : 1150, "y" : -260, "trait" : "line", "curve" : 100, "color" : "5E844D" }, /* 98 */ { "x" : 840, "y" : -600, "trait" : "line", "color" : "5E844D", "curve" : 100 }, /* 99 */ { "x" : 1150, "y" : 260, "trait" : "line", "curve" : -100, "color" : "5E844D" }, /* 100 */ { "x" : 840, "y" : 600, "trait" : "line", "color" : "5E844D", "curve" : -100 } ], "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" : -100, "color" : "5E844D", "trait" : "line", "y" : -475 }, { "v0" : 94, "v1" : 95, "curve" : 100, "color" : "5E844D", "trait" : "line", "y" : -475 }, { "v0" : 97, "v1" : 98, "curve" : 100, "color" : "5E844D", "trait" : "line", "y" : -475 }, { "v0" : 99, "v1" : 100, "curve" : -100, "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" : 0.5, "trait" : "goalPost" }, { "pos" : [-1150,-127 ], "color" : "FF0000", "bCoef" : 0.5, "trait" : "goalPost" }, { "pos" : [1150,127 ], "color" : "0000FF", "bCoef" : 0.5, "trait" : "goalPost" }, { "pos" : [1150,-127 ], "color" : "0000FF", "bCoef" : 0.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" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" }, { "radius" : 2, "invMass" : 0, "pos" : [-1150,600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" }, { "radius" : 2, "invMass" : 0, "pos" : [1150,-600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" }, { "radius" : 2, "invMass" : 0, "pos" : [1150,600 ], "color" : "FFFFFF", "bCoef" : -0.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" : 0.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" : 0.5, "color" : "FFFF00", "cGroup" : [ ] }, "reargoalNetleft" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["ball","red","blue" ], "curve" : 10, "color" : "C7E6BD" }, "reargoalNetright" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["ball","red","blue" ], "curve" : -10, "color" : "C7E6BD" }, "sidegoalNet" : { "vis" : true, "bCoef" : 1, "cMask" : ["ball","red","blue" ], "color" : "C7E6BD" }, "kickOffBarrier" : { "vis" : false, "bCoef" : 0.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}}`;
  46. room.setCustomStadium(RSHLMap);
  47. room.setScoreLimit(3);
  48. room.setTimeLimit(7);
  49.  
  50. function clonekick(player){
  51. players = room.getPlayerList();
  52. for (i = 0; i < players.length-1; i++){
  53. if (player.name == players[i].name){
  54. room.kickPlayer(player.id,"There is already a user with this name",false);
  55. }
  56. }
  57. }
  58.  
  59. var boldedNumbers = '𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗';
  60. var circledNumbers = '🄋⓵⓶⓷⓸⓹⓺⓻⓼⓽';
  61.  
  62. function boldedNumber(num){
  63. var result = '';
  64. var reversedDigits = [];
  65. do{
  66. reversedDigits.push(num % 10);
  67. num = Math.floor(num / 10);
  68. }while(num > 0);
  69. for (var i = reversedDigits.length; i-- > 0; ){
  70. result += boldedNumbers.substr(reversedDigits[i]*2, 2);
  71. }
  72.  
  73. return result;
  74. }
  75.  
  76. function circledNumber(num){
  77. var result = '';
  78. var reversedDigits = [];
  79. do{
  80. reversedDigits.push(num % 10);
  81. num = Math.floor(num / 10);
  82. }while(num > 0);
  83. for (var i = reversedDigits.length; i-- > 0; ){
  84. if(reversedDigits[i] == 0){
  85. result += circledNumbers.substr(reversedDigits[i], 2);
  86. }else{
  87. result += circledNumbers.substr(1+reversedDigits[i], 1);
  88. }
  89. }
  90.  
  91. return result;
  92. }
  93.  
  94.  
  95. /*
  96. Functions
  97. */
  98. // If there are no admins left in the room give admin to one of the remaining players.
  99. function updateAdmins() {
  100. // Get all players except the host (id = 0 is always the host)
  101. var players = room.getPlayerList().filter((player) => player.id != 0 );
  102. if ( players.length == 0 ){room.stopGame();} // No players left, do nothing.
  103. if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  104. room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  105. }
  106.  
  107. function initPlayerStats(player){
  108. }
  109.  
  110.  
  111.  
  112. /*
  113. for commands
  114. */
  115.  
  116. function swapFun(player){
  117. if (player.admin == true){
  118. if (room.getScores() == null) {
  119. players = room.getPlayerList();
  120. for (i = 0; i < players.length; i++){
  121. if (players[i].team == 1){
  122. room.setPlayerTeam(players[i].id, 2);
  123. }
  124. else if (players[i].team == 2){
  125. room.setPlayerTeam(players[i].id, 1);
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132.  
  133. function pushMuteFun(player, message){ // !mute Anddy
  134. // Prevent somebody to talk in the room (uses the nickname, not the id)
  135. // need to be admin
  136. if (player.admin == true){
  137. if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
  138. }
  139. }
  140.  
  141.  
  142. function gotMutedFun(player){
  143. if (mutedPlayers.includes(player.name)){
  144. return true;
  145. }
  146. }
  147.  
  148. function unmuteFun(player, message){ // !unmute Anddy
  149. // Allow somebody to talk if he has been muted
  150. // need to be admin
  151. if (player.admin == true){
  152. pos = mutedPlayers.indexOf(message.substr(9));
  153. mutedPlayers.splice(pos, 1);
  154. }
  155. }
  156.  
  157. function confirmFun(player, message){ // !confirm aaa
  158. // Prevent somebody to talk in the room (uses the nickname, not the id)
  159. // need to be admin
  160. let password = message.substr(9);
  161. let account = accounts.find(a => a.password === password);
  162. if (account !== undefined) {
  163. account.playerId = player.id;
  164. room.sendChat("[" + player.name + "] " + account.username + " has confirmed");
  165. confirmedPlayers.add(player.id);
  166. if (stats.hasOwnProperty(account.username)){}
  167. else {stats[account.username] = [0, 0, 0, 0, 0, 0, 1000, "D", "D", "D", "D", "D"];}
  168. }
  169. return false;
  170. }
  171.  
  172. function chatasbotFun(player, message){
  173. messagetext = message.substr(11)
  174. room.sendChat(messagetext);
  175. return false;
  176. }
  177.  
  178. function adminFun(player, message){ // !admin Andis
  179. // Gives admin to the person who type this password
  180.  
  181. room.setPlayerAdmin(player.id, true);
  182. return false; // The message won't be displayed
  183. }
  184.  
  185. function resignFun(player, message){
  186. room.setPlayerAdmin(player.id, false);
  187. updateAdmins();
  188. }
  189.  
  190.  
  191. function helpFun() { // !help
  192. room.sendChat('💬 Available commands: "!confirm", "!afk", "afks", "!confirmed_players", "!stats Nickname", "!elohelp", "!eloranking", "!ranking",');
  193. room.sendChat('💬 "!8ball", "!poss", "!resetstats", "!adminhelp", "!gkhelp", "!rankhelp", "!bb"');
  194. }
  195.  
  196. function adminHelpFun() {
  197. room.sendChat('💬 Available commands: "!mute Player", "!unmute Player", ' +
  198. '"!clearbans", "!rr", "!kickafks", "!resign", "!swap" (to switch reds and blues).');
  199. }
  200.  
  201.  
  202. function gkHelpFun() { // !gkhelp
  203. room.sendChat('💬 The most backward player at the kick off will be set as gk ! (write "!gk" if the bot was wrong).')
  204. }
  205. function rankHelpFun() { // !gkhelp
  206. room.sendChat("💬 Get points by doing good things in this room ! Goal: 2 pts, assist: 1 pts, win: 3 pts, cs: 3 pts, lose: -3 pts, og: -2 pts.")
  207. }
  208. function eloHelpFun() {
  209. room.sendChat("💬 Get points by winning matches ! Points are calculated using elo system.")
  210. }
  211.  
  212.  
  213. function statsFun(player, message){
  214. if (stats.hasOwnProperty(message.substr(7))){
  215. sendStats(message.substr(7));
  216. } else{ return false;}
  217. }
  218.  
  219. function resetStatsAdminFun (player, message){ // !reset876
  220. playername = message.substr(10);
  221. stats[playername] = [0, 0, 0, 0, 0, 0, 1000, "D", "D", "D", "D", "D"];
  222. return false;
  223. }
  224.  
  225. function clearbansFun(player){ // !clear
  226. if (player.admin == true){ room.clearBans(); room.sendChat("💎 Bans has been reseted.");}
  227. }
  228.  
  229. function resetFun(player){
  230. if (player.admin == true){
  231. room.stopGame();
  232. room.startGame();
  233. }
  234. }
  235.  
  236. function gkFun(player){ // !gk
  237.  
  238. if (room.getScores() != null && room.getScores().time < 60){
  239. if (player.team == 1) {
  240. gk[0] = player;
  241. }
  242. else if (player.team == 2){
  243. gk[1] = player;
  244. }
  245. }
  246. return;
  247. }
  248.  
  249.  
  250. function closeFun(player){
  251. if (player.name == "Waffleaaa"){ // artificially generate an error in order to close the room
  252. stats.crash();
  253. }
  254. }
  255.  
  256. function leaveFun(player){
  257. room.kickPlayer(player.id, "ggs!", false);
  258. }
  259.  
  260.  
  261. /*
  262. For ranking
  263. */
  264.  
  265. function rankingCalc(player){
  266. var name = player;
  267. players = Object.keys(stats);
  268. account = players.find(a => a === name)
  269. if (account !== undefined){
  270. return stats[name][0] * 2 + stats[name][1] * 1 +
  271. stats[name][2] * 3 + stats[name][5] * 3 -
  272. stats[name][3] * 3 - stats[name][4] * 2;
  273. }
  274. else {return 0;}
  275. }
  276.  
  277. function ranking(){
  278.  
  279. var overall = [];
  280. players = Object.keys(stats);
  281. for (var i = 0; i < players.length; i++) {
  282. score = rankingCalc(players[i])
  283. // Goal: 2 pts, Assist: 1 pts, Win: 3 pts, CS: 3 pts, Lose: -3 pts, OG: -2 pts
  284. overall.push({name: players[i], value: score});
  285. }
  286. overall.sort(function(a,b){
  287. return b.value - a.value;
  288. })
  289. let top15 = overall.splice(0, 15);
  290. let pos = 1;
  291. if (top15.length) {
  292. room.sendChat("💎 Ranking [TOP15]: ");
  293. }
  294. while (top15.length) {
  295. let tmp = top15.splice(0, 5);
  296. let message = tmp.map(e => `${pos++}) ${e.name}: ${e.value}`).join(", ");
  297. room.sendChat(message);
  298. }
  299. }
  300.  
  301. function eloCalc(player){
  302. var name = player;
  303. return stats[name][6];
  304. }
  305.  
  306. function eloranking(){
  307.  
  308. var overall = [];
  309. players = Object.keys(stats);
  310. for (var i = 0; i < players.length; i++) {
  311. score = eloCalc(players[i])
  312. // Goal: 2 pts, Assist: 1 pts, Win: 3 pts, CS: 3 pts, Lose: -3 pts, OG: -2 pts
  313. overall.push({name: players[i], value: score});
  314. }
  315. overall.sort(function(a,b){
  316. return b.value - a.value;
  317. })
  318. let top15 = overall.splice(0, 15);
  319. let pos = 1;
  320. if (top15.length) {
  321. room.sendChat("💎 ELO Ranking [TOP15]: ");
  322. }
  323. while (top15.length) {
  324. let tmp = top15.splice(0, 5);
  325. let message = tmp.map(e => `${pos++}) ${e.name}: ${e.value}`).join(", ");
  326. room.sendChat(message);
  327. }
  328. }
  329.  
  330.  
  331. function sendStats(name){
  332. ps = stats[name]; // stands for playerstats
  333. /* if (ps[7] == parseInt(0)) {ps[7] = "L"} else {ps[7] = "W"}
  334. if (ps[8] == parseInt(0)) {ps[8] = "L"} else {ps[8] = "W"}
  335. if (ps[9] == parseInt(0)) {ps[9] = "L"} else {ps[9] = "W"}
  336. if (ps[10] == parseInt(0)) {ps[10] = "L"} else {ps[10] = "W"}
  337. if (ps[11] == parseInt(0)) {ps[11] = "L"} else {ps[11] = "W"} */
  338. room.sendChat(name + ": Goals: " + ps[0] + ", Assists: " + ps[1]
  339. + ", OG: " + ps[4] + ", CS: " + ps[5] + ", Wins: " + ps[2] + ", Losses: " + ps[3] + ", 💎 ELO: " + ps[6]);
  340. if (ps[7] !== "D" && ps[8] !== "D" && ps[9] !== "D" && ps[10] !== "D" && ps[11] !== "D"){room.sendChat(name + ": 🥇 Last 5 W/L: " + ps[7] + " - " + ps[8] + " - " + ps[9] + " - " + ps[10] + " - " + ps[11]);}
  341. if (ps[7] !== "D" && ps[8] !== "D" && ps[9] !== "D" && ps[10] !== "D" && ps[11] == "D"){room.sendChat(name + ": 🥇 Last 4 W/L: " + ps[7] + " - " + ps[8] + " - " + ps[9] + " - " + ps[10]);}
  342. if (ps[7] !== "D" && ps[8] !== "D" && ps[9] !== "D" && ps[10] == "D" && ps[11] == "D"){room.sendChat(name + ": 🥇 Last 3 W/L: " + ps[7] + " - " + ps[8] + " - " + ps[9]);}
  343. if (ps[7] !== "D" && ps[8] !== "D" && ps[9] == "D" && ps[10] == "D" && ps[11] == "D"){room.sendChat(name + ": 🥇 Last 2 W/L: " + ps[7] + " - " + ps[8]);}
  344. if (ps[7] !== "D" && ps[8] == "D" && ps[9] == "D" && ps[10] == "D" && ps[11] == "D"){room.sendChat(name + ": 🥇 Last W/L: " + ps[7]);}
  345. }
  346.  
  347.  
  348. function whichTeam(){ // gives the players in the red or blue team
  349. var players = room.getPlayerList();
  350. var redTeam = players.filter(player => player.team == 1);
  351. var blueTeam = players.filter(player => player.team == 2);
  352. return [redTeam, blueTeam]
  353. }
  354. function afkFun(player, message){ // !classic
  355. if (afkPlayerIDs.has(player.id)){
  356. afkPlayerIDs.delete(player.id);
  357. room.sendChat("💎 " + player.name + " is back! and ready for play!");}
  358. else {afkPlayerIDs.add(player.id); room.setPlayerTeam(player.id, 0);room.sendChat("💎 " + player.name + " is now AFK!");}
  359. }
  360.  
  361. function afksFun(player, message){ // !huge
  362. afkPlayers_list = room.getPlayerList().filter((x) => afkPlayerIDs.has(x.id));
  363. afkPlayers_list_string = afkPlayers_list.map(x => x.name).join(", ");
  364. if (afkPlayers_list == "") {
  365. room.sendChat("💎 No AFK players in the room!");
  366. }
  367. else {
  368. room.sendChat("💎 AFK players: " + afkPlayers_list_string);
  369. }
  370. }
  371.  
  372. function kickafksFun(player, message){ // !huge
  373. if (player.admin == true){
  374. afksPlayers = room.getPlayerList().filter((x) => afkPlayerIDs.has(x.id));
  375. for(var i=0;i<afksPlayers.length;i++){room.kickPlayer(afksPlayers[i].id,"AFK!",false);}
  376. }
  377. }
  378.  
  379. function saveStatsFun(){
  380. var val = JSON.stringify(stats);
  381. window.localStorage.setItem("stats", val);
  382. return false;
  383. }
  384.  
  385. function getAverageRank(team){
  386. average = 0;
  387. for (var i = 0; i < team.length; i++) {
  388. if (team[i].name !== undefined){
  389. average += rankingCalc(team[i].name);}
  390. }
  391. return average / team.length;
  392. }
  393.  
  394.  
  395.  
  396. function getRatingDelta(redTeam, blueTeam, redGameResult, blueGameResult) {
  397.  
  398. redAverage = getAverageRank(redTeam);
  399. blueAverage = getAverageRank(blueTeam);
  400.  
  401. var redChanceToWin = 1 / ( 1 + Math.pow(10, (blueAverage - redAverage) / 400));
  402. var blueChanceToWin = 1 - redChanceToWin;
  403.  
  404. return [Math.round(32 * (redGameResult - redChanceToWin)), Math.round(32 * (blueGameResult - blueChanceToWin))];
  405. }
  406.  
  407. function updateElo(redTeam, blueTeam, redGameResult, blueGameResult){
  408. if (redTeam.length == blueTeam.length && redTeam.length == '4' && blueTeam.length == '4'){
  409. [redDelta, blueDelta] = getRatingDelta(redTeam, blueTeam, redGameResult, blueGameResult)
  410. for (var i = 0; i < redTeam.length; i++) {
  411. let account3 = accounts.find(a => a.playerId === redTeam[i].id);
  412. if (account3 !== undefined) {stats[account3.username][6] += redDelta;} else{};
  413. let account4 = accounts.find(a => a.playerId === blueTeam[i].id);
  414. if (account4 !== undefined) {stats[account4.username][6] += blueDelta;} else{};
  415. }
  416. return redDelta;
  417. }
  418. return 0;
  419. }
  420.  
  421.  
  422. function confirmedPlayersFun(player, message){ // !huge
  423. confirmedPlayers_list = room.getPlayerList().filter((x) => confirmedPlayers.has(x.id));
  424. confirmedPlayers_list_string = confirmedPlayers_list.map(x => x.name).join(", ");
  425. if (confirmedPlayers_list == "") {
  426. room.sendChat("💎 Their is no confirmed players currently!");
  427. }
  428. else {
  429. room.sendChat("💎 Confirmed players: " + confirmedPlayers_list_string);
  430. }
  431. }
  432.  
  433.  
  434. function eightballFun(player, message){
  435. var myArray = ['Hell to the no.', 'Maybe.', 'Pfft.', 'The future is bleak.', 'Certainly not.', 'Ahaha! Really?!?', 'The future is uncertain.', 'Possibly.', 'I hope not.', 'Never!', 'Never, ever, ever.', 'Hell, yes.', 'Not in your wildest dreams.', 'Yes!', 'I hope so.'];
  436. var rand = myArray[(Math.random() * myArray.length) | 0]
  437. var myArray2 = ['😀','😁','😂','😃','😄','😅','😆','😉','😊','😋','😎','😍','😘','😏','😣','😥','😮','😯','😪','😫','😴','😌','😛','😜','😝'];
  438. var randimage = myArray2[(Math.random() * myArray2.length) | 0]
  439. room.sendChat(randimage + " " + rand);
  440. }
  441.  
  442. function setpasswordFun(player, message){ //!set_password !confirm
  443. if (player.admin == true){
  444. code = message.substr(14)
  445. room.setPassword(code);
  446. room.sendChat("💎 Room locked.");
  447. return false;
  448. }
  449. }
  450.  
  451. function clearpasswordFun(player, message){ //!clear_password
  452. if (player.admin == true){
  453. room.setPassword();
  454. room.sendChat("💎 Room unlocked.");
  455. return false;
  456. }
  457. }
  458.  
  459.  
  460. function backaccountFun(player, message){ //!back876 waffle 10 2 3 2 1 1 1000
  461. if (player.admin == true){
  462. var playername = message.substring(message.lastIndexOf(":") + 1,message.lastIndexOf(";"));
  463. var index = message.substr( message.lastIndexOf(";") + 1 ).split(" ");
  464. var goals = index[1]
  465. var assists = index[2]
  466. var wins = index[3]
  467. var losses = index[4]
  468. var og = index[5]
  469. var cs = index[6]
  470. var elo = index[7]
  471. var ws1 = index[8]
  472. var ws2 = index[9]
  473. var ws3 = index[10]
  474. var ws4 = index[11]
  475. var ws5 = index[12]
  476. stats[playername] = [parseInt(goals), parseInt(assists), parseInt(wins), parseInt(losses), parseInt(og), parseInt(cs), parseInt(elo), ws1, ws2, ws3, ws4, ws5]; // goals, assists, wins, losses, og, cs, elo
  477. saveStatsFun();
  478. return false;
  479. }
  480. }
  481.  
  482. function addaccountFun(player, message){ //!addaccount Waffle aaa
  483. var playername = message.substring(message.lastIndexOf(":") + 1,message.lastIndexOf(";"));
  484. var index = message.substr( message.lastIndexOf(";") + 1 ).split(" ");
  485. var password = index[index.length - 1]
  486. accounts.push({username: playername,password: password});
  487. if (stats.hasOwnProperty(playername)){}
  488. else {stats[playername] = [0, 0, 0, 0, 0, 0, 1000, "D", "D", "D", "D", "D"];}
  489. saveStatsFun();
  490. return false;
  491. }
  492.  
  493. /* function pmFun(player, message){ //!pm
  494. var pm = message.substr(4);
  495. var index = message.split(" ").slice(1);
  496. var playerID = index[0]
  497. var message2 = message.substr(4).substr(playerID);
  498. var message3 = "[PM FROM " + player.name + "(ID:" + player.id + ")]: " + message2;
  499. console.log(playerID);
  500. console.log(index);
  501. console.log(message);
  502. console.log(message2);
  503. console.log(message3);
  504. room.sendChat(message3, parseInt(playerID))
  505. var players = room.getPlayerList().filter((player) => player.id != 0 );
  506. if ( players.find((player => player.id === playerID))) {room.sendChat("User ID is not found!, Check # for getting ID.", player.id)}
  507. else {room.sendChat("PM Sent!", player.id)};
  508. return false;
  509. } */
  510.  
  511.  
  512. function isGk(){ // gives the mosts backward players before the first kickOff
  513. var players = room.getPlayerList();
  514. var min = players[0];
  515. min.position = {x: room.getBallPosition().x + 60}
  516. var max = min;
  517.  
  518. for (var i = 0; i < players.length; i++) {
  519. if (players[i].position != null){
  520. if (min.position.x > players[i].position.x) min = players[i];
  521. if (max.position.x < players[i].position.x) max = players[i];
  522. }
  523. }
  524. return [min, max]
  525. }
  526.  
  527.  
  528.  
  529.  
  530.  
  531. function updateWinLoseStats(winners, losers){
  532. for (var i = 0; i < winners.length; i++) {
  533. let account = accounts.find(a => a.playerId === winners[i].id);
  534. if (account !== undefined) {stats[account.username][2] += 1;} else{};
  535. }
  536. for (var i = 0; i < losers.length; i++) {
  537. let account1 = accounts.find(a => a.playerId === losers[i].id);
  538. if (account1 !== undefined) {stats[account1.username][3] += 1;} else{};
  539. }
  540. }
  541.  
  542. function updateWinLoseStreakStats(winners, losers){
  543. if (redTeam.length == blueTeam.length && redTeam.length == '4' && blueTeam.length == '4'){
  544. for (var i = 0; i < winners.length; i++) {
  545. let account = accounts.find(a => a.playerId === winners[i].id);
  546. if (account !== undefined) {
  547. if (stats[account.username][10] == "W"){ stats[account.username][11] = "W"; } else if (stats[account.username][10] == "L"){ stats[account.username][11] = "L"; } else{};
  548. if (stats[account.username][9] == "W"){ stats[account.username][10] = "W"; } else if (stats[account.username][9] == "L"){ stats[account.username][10] = "L"; } else{};
  549. if (stats[account.username][8] == "W"){ stats[account.username][9] = "W"; } else if (stats[account.username][8] == "L"){ stats[account.username][9] = "L"; } else{};
  550. if (stats[account.username][7] == "W"){ stats[account.username][8] = "W"; } else if (stats[account.username][7] == "L"){ stats[account.username][8] = "L"; } else{};
  551. stats[account.username][7] = "W";} else{};
  552. }
  553. for (var i = 0; i < losers.length; i++) {
  554. let account1 = accounts.find(a => a.playerId === losers[i].id);
  555. if (account1 !== undefined) {
  556. if (stats[account1.username][10] == "W"){ stats[account1.username][11] = "W"; } else if (stats[account1.username][10] == "L"){ stats[account1.username][11] = "L"; } else{};
  557. if (stats[account1.username][9] == "W"){ stats[account1.username][10] = "W"; } else if (stats[account1.username][9] == "L"){ stats[account1.username][10] = "L"; } else{};
  558. if (stats[account1.username][8] == "W"){ stats[account1.username][9] = "W"; } else if (stats[account1.username][8] == "L"){ stats[account1.username][9] = "L"; } else{};
  559. if (stats[account1.username][7] == "W"){ stats[account1.username][8] = "W"; } else if (stats[account1.username][7] == "L"){ stats[account1.username][8] = "L"; } else{};
  560. stats[account1.username][7] = "L";} else{};
  561. }
  562. }
  563. }
  564.  
  565. function initBallCarrying(redTeam, blueTeam){
  566. var ballCarrying = new Map();
  567. var playing = redTeam.concat(blueTeam);
  568. for (var i = 0; i < playing.length; i++) {
  569. ballCarrying.set(playing[i].name, [0, playing[i].team]); // secs, team, %
  570. }
  571. return ballCarrying;
  572. }
  573.  
  574.  
  575.  
  576. function updateTeamPoss(value){
  577. if (value[1] == 1) redPoss += value[0];
  578. if (value[1] == 2) bluePoss += value[0];
  579. }
  580.  
  581. var bluePoss;
  582. var redPoss;
  583. var timeOnHalves;
  584. function teamPossFun(){
  585. if (room.getScores() == null) return false;
  586. bluePoss = 0;
  587. redPoss = 0
  588. ballCarrying.forEach(updateTeamPoss);
  589. var redPossPercent = Math.round((redPoss / (redPoss + bluePoss + 0.000001)) * 100);
  590. var bluePossPercent = Math.round((bluePoss / (redPoss + bluePoss + 0.000001)) * 100);
  591. room.sendChat("⛹ Ball possession: Red 🔴 " + boldedNumber(redPossPercent) + "% - " + boldedNumber(bluePossPercent) + "% Blue 🔵" );
  592.  
  593. var timeOnRedHalf = Math.round((timeOnHalves[0] / (timeOnHalves[0] + timeOnHalves[1] + 0.000001)) * 100);
  594. var timeOnBlueHalf = Math.round((timeOnHalves[1] / (timeOnHalves[0] + timeOnHalves[1] + 0.000001)) * 100);
  595. room.sendChat("◧ Game time on halves : 🔴 " + boldedNumber(timeOnRedHalf) + "% - " + boldedNumber(timeOnBlueHalf) + "% 🔵" );
  596. }
  597.  
  598.  
  599.  
  600. /*
  601. For the game
  602. */
  603.  
  604. // Gives the last player who touched the ball, works only if the ball has the same
  605. // size than in classics maps.
  606. var radiusBall = 10;
  607. function getLastTouchTheBall(lastPlayerTouched, time) {
  608. var ballPosition = room.getBallPosition();
  609. var players = room.getPlayerList();
  610. for(var i = 0; i < players.length; i++) {
  611. if(players[i].position != null) {
  612. var distanceToBall = pointDistance(players[i].position, ballPosition);
  613. if(distanceToBall < triggerDistance) {
  614. lastPlayerTouched = players[i];
  615. return lastPlayerTouched;
  616. }
  617. }
  618. }
  619. return lastPlayerTouched;
  620.  
  621. }
  622.  
  623.  
  624.  
  625. // Calculate the distance between 2 points
  626. function pointDistance(p1, p2) {
  627. var d1 = p1.x - p2.x;
  628. var d2 = p1.y - p2.y;
  629. return Math.sqrt(d1 * d1 + d2 * d2);
  630. }
  631.  
  632. function isOvertime(){
  633. scores = room.getScores();
  634. if (scores != null){
  635. if (scores.timeLimit != 0){
  636. if (scores.time > scores.timeLimit){
  637. if (scores.red == 0 && hasFinished == false){
  638. let account = accounts.find(a => a.playerId === gk[0].id);
  639. if (account !== undefined) {
  640. stats[account.username][5] += 1;}else{};
  641. let account1 = accounts.find(a => a.playerId === gk[1].id);
  642. if (account1 !== undefined) {
  643. stats[account1.username][5] += 1;}else{};
  644. hasFinished = true;
  645. }
  646. }
  647. }
  648. }
  649. }
  650. // return: the name of the team who took a goal
  651. var team_name = team => team == 1 ? "🔴 Red" : "🔵 Blue";
  652.  
  653. var team_color = team => team == 1 ? "🔴" : "🔵";
  654.  
  655. // return: whether it's an OG
  656. var isOwnGoal = (team, player) => team != player.team ? " [OG]" : "";
  657.  
  658. // return: a better display of the second when a goal is scored
  659. var floor = s => s < 10 ? "0" + s : s;
  660.  
  661. // return: whether there's an assist
  662. //var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (" + playerList[1].name + ")" : "";
  663.  
  664. playerTouchedTwice = function(playerList){
  665. let account = accounts.find(a => a.playerId === playerList[1].id);
  666. if (playerList[0].team == playerList[1].team && account !== undefined){ return " (" + playerList[1].name + "[" + account.username + "]" + ")"; }
  667. else if (playerList[0].team == playerList[1].team && account == undefined){ return " (" + playerList[1].name + ")"; }
  668. else{ return "";};
  669.  
  670. }
  671.  
  672.  
  673.  
  674. var stats;
  675. if (!(localStorage.getItem("stats"))){
  676. stats = {};
  677. } else {stats = JSON.parse(localStorage.getItem("stats"));}
  678. window.setInterval(saveStatsFun, 300000);
  679. /* window.setInterval(saveStatsFun, 300000); */
  680. var mutedPlayers = []; // Array where will be added muted players
  681. const confirmedPlayers = new Set()
  682. const afkPlayerIDs = new Set()
  683. var init = "init"; // Smth to initialize smth
  684. init.id = 0; // Faster than getting host's id with the method
  685. init.name = "init";
  686. var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
  687. var whoTouchedLast; // var representing the last player who touched the ball
  688. var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
  689. var gk = [init, init];
  690. var goalScored = false;
  691. let accounts = [];
  692.  
  693. accounts.push({username: "Waffle",password: "waf234"});
  694. accounts.push({username: "Ronaldeano",password: "ronhasfatcock0521"});
  695. accounts.push({username: "King Natex",password: "kngnatex"});
  696. accounts.push({username: "Wino",password: "slowball21"});
  697. accounts.push({username: "Mercurial",password: "sk30"});
  698. accounts.push({username: "Klister",password: "bigcock10"});
  699. accounts.push({username: "Sergi Roberto",password: "Veserto"});
  700. accounts.push({username: "Gluee",password: "87"});
  701. accounts.push({username: "earth",password: "txtesla"});
  702. accounts.push({username: "Mecha112",password: "bt46"});
  703. accounts.push({username: "champagnepapi",password: "bbg1903"});
  704. accounts.push({username: "Faraone",password: "culpables"});
  705. accounts.push({username: "Time Lord",password: "1988"});
  706. accounts.push({username: "Nou",password: "nouisthebest1010"});
  707. accounts.push({username: "WAZZA",password: "WAZZA10"});
  708. accounts.push({username: "Gelson Martins",password: "gudelj86"});
  709. accounts.push({username: "ChiCharito",password: "lozano22"});
  710. accounts.push({username: "Xavi",password: "skeetandyeet"});
  711. accounts.push({username: "Kaz",password: "hundred1"});
  712. accounts.push({username: "magor",password: "thalassa"});
  713. accounts.push({username: "Nogo",password: "iamJamaican"});
  714. accounts.push({username: "VR6",password: "nosevr6"});
  715. accounts.push({username: "Mariano Diaz",password: "rumania1"});
  716. accounts.push({username: "Bump",password: "bump3616"});
  717. accounts.push({username: "Rorschach",password: "slowbrained"});
  718. accounts.push({username: "darko",password: "dorko"});
  719. accounts.push({username: "ᴱᴰᴮᴱᴿᴳ",password: "sChatzschneidE83r"});
  720. accounts.push({username: "mané",password: "bk11"});
  721. accounts.push({username: "Nigel Farage",password: "88888"});
  722. accounts.push({username: "Ben Simmons",password: "animefan"});
  723. accounts.push({username: "27",password: "twentyseven"});
  724. accounts.push({username: "best",password: "2340"});
  725. accounts.push({username: "BetoForPresident2020",password: "ebk1996"});
  726. accounts.push({username: "ant",password: "stickarena123"});
  727. accounts.push({username: "chad",password: "puss"});
  728. accounts.push({username: "brad",password: "cockinass"});
  729. accounts.push({username: "Calument",password: "MU2004"});
  730. accounts.push({username: "henry burris",password: "wombat"});
  731. accounts.push({username: "geoff",password: "mama"});
  732. accounts.push({username: "West",password: "7656"});
  733. accounts.push({username: "prestige",password: "nopreference"});
  734. accounts.push({username: "burr",password: "b0rr"});
  735. accounts.push({username: "Lukas",password: "hyperbiird"});
  736. accounts.push({username: "S.Ramos",password: "SergioR4RMadrid"});
  737. accounts.push({username: "⊕šαmα",password: "135246sa"});
  738. accounts.push({username: "Hɨddэn Gэm",password: "1996"});
  739. accounts.push({username: "feneria",password: "biko"});
  740. accounts.push({username: "Bigfatsnoozy",password: "opensesame"});
  741. accounts.push({username: "Luciano",password: "xqef7"});
  742. accounts.push({username: "Kevinm31",password: "osu"});
  743. accounts.push({username: "Lindros",password: "kaleshake"});
  744. accounts.push({username: "Compass",password: "gaygayass123"});
  745. accounts.push({username: "Derrick Rose",password: "reize27"});
  746. accounts.push({username: "Ant",password: "ownit41"});
  747. accounts.push({username: "Panda",password: "1227rg"});
  748. accounts.push({username: "Starcrushed",password: "cocochanel"});
  749. accounts.push({username: "guid",password: "cock"});
  750. accounts.push({username: "dzeko",password: "BOsna123"});
  751. accounts.push({username: "pixel",password: "niggerssmellbad"});
  752. accounts.push({username: "knowledge",password: "purplevase"});
  753. accounts.push({username: "House of Balloons",password: "pirlo5"});
  754. accounts.push({username: "Messi Da Best",password: "FCB2013"});
  755. accounts.push({username: "Matt",password: "Brian61202"});
  756. accounts.push({username: "kpa",password: "geoff"});
  757.  
  758. var commands = {
  759. // Command that doesnt need to know players attributes.
  760. "!help": helpFun,
  761. "!gkhelp": gkHelpFun,
  762. "!adminhelp": adminHelpFun,
  763. "!rankhelp": rankHelpFun,
  764. "!ranking": ranking,
  765. "!poss": teamPossFun,
  766. "!elohelp": eloHelpFun,
  767. "!eloranking": eloranking,
  768. "!reset824": resetStatsAdminFun,
  769.  
  770. // Command that need to know who is the player.
  771. "!gk": gkFun,
  772. "!despacito105": adminFun,
  773.  
  774. // Command that need to know if a player is admin.
  775. "!swap": swapFun,
  776. "!rr": resetFun,
  777. "!clearbans": clearbansFun,
  778. "!close876": closeFun,
  779. "!save876": saveStatsFun,
  780.  
  781. // Command that need to know what's the message.
  782. "!stats": statsFun,
  783. "!addaccount824": addaccountFun,
  784. "!bb" : leaveFun,
  785. "!leave" : leaveFun,
  786. "!quit" : leaveFun,
  787. "!confirm" : confirmFun,
  788. "!confirmed_players" : confirmedPlayersFun,
  789. "!afk" : afkFun,
  790. "!afks" : afksFun,
  791. "!kickafks" : kickafksFun,
  792. "!resign" : resignFun,
  793. "!chatasbot" : chatasbotFun,
  794. "!mute" : pushMuteFun,
  795. "!8ball" : eightballFun,
  796. "!downloadstats" : backupServerData,
  797. "!unmute": unmuteFun,
  798. "!set_password876": setpasswordFun,
  799. "!clear_password876": clearpasswordFun,
  800. /* "!pm": pmFun,
  801. */ "!back876": backaccountFun
  802. }
  803.  
  804. initPlayerStats(room.getPlayerList()[0]) // lazy lol, i'll fix it later
  805. initPlayerStats(init);
  806.  
  807.  
  808.  
  809.  
  810.  
  811. room.onGameStart = function(player) {
  812. lineCrossedPlayers = [{name: "temp", times: 0}];
  813. lastScores = room.getScores().red + room.getScores().blue;
  814. timeOutside = 0;
  815. isTimeAddedShown = false;
  816. lineBallPosition = 0;
  817. [redTeam,blueTeam] = whichTeam();
  818. ballCarrying = initBallCarrying(redTeam, blueTeam);
  819. timeOnHalves = [0,0];
  820. }
  821.  
  822.  
  823. room.onPlayerTeamChange = function(player){
  824. if (room.getScores() != null){
  825. if (1 <= player.team <= 2) ballCarrying.set(player.name, [0, player.team]);
  826. }
  827. if (player.team !== 0 && afkPlayerIDs.has(player.id))
  828. {room.setPlayerTeam(player.id, 0)
  829. room.sendChat("💎 " + player.name + " is AFK!")}
  830. if (player.id <= 0){
  831. room.setPlayerTeam(player.id, 0)}
  832. }
  833.  
  834.  
  835.  
  836. room.onPlayerChat = function(player, message) {
  837. if (mutedPlayers.includes(player.name)) return false;
  838. let spacePos = message.search(" ");
  839. let command = message.substr(0, spacePos !== -1 ? spacePos : message.length);
  840. if (commands.hasOwnProperty(command) == true) return commands[command](player, message);
  841. if (message.indexOf("!") == 0) return false;
  842. }
  843.  
  844. room.onPlayerBallKick = function(player) {
  845. whoTouchedLast = player;
  846. var ballPosition = room.getBallPosition();
  847. if(player.name!=lastPlayerTouched)
  848. {
  849. if(lastTeamTouched==player.team)
  850. {
  851. assistingTouch = lastPlayerTouched;
  852. }else assistingTouch = "";
  853. }
  854. previousPlayerTouched = lastPlayerTouched;
  855. lastPlayerTouched = player.name;
  856. lastTeamTouched = player.team;
  857. if(isBallOutsideStadium)
  858. {
  859. getPlayersNotWithinLine();
  860. }
  861. if(isBallOutsideStadium && ballPosition.y<0)
  862. {
  863. isBallKickedOutside = true;
  864. }else if(isBallOutsideStadium && ballPosition.y>0)
  865. {
  866. isBallKickedOutside = true;
  867. }else isBallKickedOutside = false;
  868. }
  869. function isBallGoingUp() {
  870. previousBallPosForGoingUp = currentBallPosForGoingUp;
  871. currentBallPosForGoingUp = room.getBallPosition().y;
  872. if (previousBallPosForGoingUp - currentBallPosForGoingUp > 0.01) {
  873. isBallUp = 2;
  874. } else if (previousBallPosForGoingUp - currentBallPosForGoingUp < -0.01) {
  875.  
  876. isBallUp = 1;
  877. } else {
  878. isBallUp = 0;
  879. }
  880. }
  881. function addedTime()
  882. {
  883. var ballPosition = room.getBallPosition();
  884. if(isOutsideStadium(ballPosition))
  885. {
  886. timeOutside++;
  887. return true;
  888. }
  889. }
  890.  
  891. function checkEnd() {
  892. var scores = room.getScores();
  893. if (scores.time > 590 && !isTimeAddedShown) {
  894. var actualTimeAdded = Math.round((timeOutside-(100*60))/120);
  895. if(actualTimeAdded<60&&actualTimeAdded>-1)
  896. {
  897. room.sendChat("ADDED TIME: + " + actualTimeAdded + " SECONDS");
  898. }else if(actualTimeAdded<0)
  899. {
  900. room.sendChat("NO ADDED TIME. (+0)");
  901. }else
  902. {
  903. room.sendChat("ADDED TIME: + 1 MINUTE");
  904. }
  905. isTimeAddedShown = true;
  906. }
  907. }
  908. var tickCount = 0;
  909. var kickOff = false;
  910. var hasFinished = false;
  911. room.onGameTick = function() {
  912.  
  913. if (kickOff == false) { // simplest comparison to not charge usulessly the tick thing
  914. if (room.getScores().time != 0){
  915. kickOff = true;
  916. gk = isGk();
  917. let account = accounts.find(a => a.playerId === gk[0].id);
  918. let account1 = accounts.find(a => a.playerId === gk[1].id);
  919. if (account == undefined && account1 == undefined) {room.sendChat("Red GK: " + gk[0].name + ", Blue GK: " + gk[1].name)}
  920. else if (account !== undefined && account1 == undefined) {room.sendChat("Red GK: " + gk[0].name + "[" + account.username + "]" + ", Blue GK: " + gk[1].name)}
  921. else if (account == undefined && account1 !== undefined) {room.sendChat("Red GK: " + gk[0].name + ", Blue GK: " + gk[1].name + "[" + account1.username + "]")}
  922. else{room.sendChat("Red GK: " + gk[0].name + "[" + account.username + "]" + ", Blue GK: " + gk[1].name + "[" + account1.username + "]")};
  923. }
  924. }
  925. if (goalScored == false){
  926. whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
  927. }
  928. if (whoTouchedLast != undefined) {
  929.  
  930. if (ballCarrying.get(whoTouchedLast.name)) {
  931. ballCarrying.get(whoTouchedLast.name)[0] += 1/60;
  932. }
  933.  
  934. if ( whoTouchedLast.id != whoTouchedBall[0].id){
  935. whoTouchedBall[1] = whoTouchedBall[0];
  936. whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
  937. }
  938. }
  939. updateTimeOnHalves();
  940.  
  941.  
  942. isThrowInCorrect();
  943. getLastTouchTheBalltwo();
  944. checkBallPosition();
  945. isBackRequired();
  946. hasBallLeftTheLine();
  947. addedTime();
  948. checkEnd();
  949. tickCount++;
  950.  
  951.  
  952.  
  953. }
  954.  
  955. updateTimeOnHalves = function(){
  956. if(room.getBallPosition().x < 0){
  957. timeOnHalves[0] += 1/60;
  958. }else if(room.getBallPosition().x > 0){
  959. timeOnHalves[1] += 1/60;
  960. }
  961. }
  962.  
  963.  
  964. room.onTeamGoal = function(team){ // Write on chat who scored and when.
  965. goalScored = true;
  966. var time = room.getScores().time;
  967. var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
  968. time = m + ":" + floor(s); // MM:SS format
  969. var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
  970. var assist = "";
  971. if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
  972.  
  973. let account = accounts.find(a => a.playerId === whoTouchedBall[0].id);
  974. if (account !== undefined) {
  975.  
  976. room.sendChat("⚽ GOAL scored by " + whoTouchedBall[0].name + "[" + account.username + "]" +
  977. assist + ownGoal + " at [" +
  978. time + "] for team " + team_name(team));
  979. room.sendChat("Match Score now: " + team_color(1) + " " +
  980. boldedNumber(room.getScores().red) + " - " + boldedNumber(room.getScores().blue) + " " + team_color(2));
  981.  
  982.  
  983. if (ownGoal != "") {
  984. stats[account.username][4] += 1;
  985. } else {
  986. stats[account.username][0] += 1;
  987. }
  988. }
  989. else {
  990. room.sendChat("⚽ GOAL scored by " + whoTouchedBall[0].name +
  991. assist + ownGoal + " at [" +
  992. time + "] for team " + team_name(team));
  993. room.sendChat("Match Score now: " + team_color(1) + " " +
  994. boldedNumber(room.getScores().red) + " - " + boldedNumber(room.getScores().blue) + " " + team_color(2));
  995.  
  996. }
  997. let account1 = accounts.find(a => a.playerId === whoTouchedBall[1].id);
  998. if (account1 !== undefined) {
  999. if (whoTouchedBall[1] != init && assist != "") stats[account1.username][1] += 1;
  1000. }
  1001. else{
  1002. if (whoTouchedBall[1] != init && assist != "");
  1003. }
  1004.  
  1005.  
  1006. if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
  1007. scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
  1008. whoTouchedBall = [init, init];
  1009. whoTouchedLast = undefined;
  1010. saveStatsFun();
  1011. }
  1012.  
  1013. room.onPositionsReset = function(){
  1014. goalScored = false;
  1015. }
  1016.  
  1017.  
  1018. room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
  1019. let account = accounts.find(a => a.playerId === gk[0].id);
  1020. if (account !== undefined && scores.blue == 0 && gk[0].position != null && hasFinished == false)
  1021. {stats[account.username][5] += 1;}else {};
  1022. let account1 = accounts.find(a => a.playerId === gk[1].id);
  1023. if (account1 !== undefined && scores.red == 0 && gk[1].position != null && hasFinished == false)
  1024. {stats[account1.username][5] += 1;}else {};
  1025.  
  1026. if (scores.red > scores.blue) {
  1027. eloDelta = updateElo(redTeam, blueTeam, 1, 0);
  1028. updateWinLoseStats(redTeam, blueTeam);
  1029. updateWinLoseStreakStats(redTeam, blueTeam);
  1030. }
  1031. else{
  1032. eloDelta = updateElo(redTeam, blueTeam, 0, 1);
  1033. updateWinLoseStats(blueTeam, redTeam);
  1034. updateWinLoseStreakStats(blueTeam, redTeam);
  1035. }
  1036. room.sendChat("Scored goals ⚽:")
  1037. for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
  1038. room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
  1039. }
  1040. room.sendChat("The game cost " + Math.abs(eloDelta) + " points. [ELO Points UPDATED only on 4vs4!]")
  1041. teamPossFun();
  1042. room.stopGame();
  1043. players = room.getPlayerList();
  1044. for (var i = 0; i < players.length; i++) {
  1045. room.setPlayerTeam(players[i].id, 0);
  1046. }
  1047. saveStatsFun();
  1048. }
  1049.  
  1050. room.onGameStop = function(){
  1051. scorers = undefined;
  1052. whoTouchedBall = [init, init];
  1053. whoTouchedLast = undefined;
  1054. gk = [init, init];
  1055. kickOff = false;
  1056. hasFinished = false;
  1057. }
  1058.  
  1059. function getNewRating(myRating, opponentRating, myGameResult) {
  1060. return myRating + getRatingDelta(myRating, opponentRating, myGameResult);
  1061. }
  1062.  
  1063. var _savestatsInterval = 1000 * 10800;
  1064. SaveStats = setInterval(function() {saveStatsFun();},_savestatsInterval);
  1065.  
  1066.  
  1067.  
  1068. function download(data, filename, type) {
  1069. var file = new Blob([data], {type: type});
  1070. var a = document.createElement("a"),
  1071. url = URL.createObjectURL(file);
  1072. a.href = url;
  1073. a.download = filename;
  1074. document.body.appendChild(a);
  1075. a.click();
  1076. setTimeout(function() {
  1077. document.body.removeChild(a);
  1078. window.URL.revokeObjectURL(url);
  1079. }, 0);
  1080. }
  1081.  
  1082. function backupServerData() {
  1083. let jsonData = JSON.stringify(stats);
  1084. download(jsonData, "server_stats.txt", "text/plain");
  1085. return false;
  1086. }
  1087. var _downloadstatsInterval = 1000 * 10800;
  1088. DownladStats = setInterval(function() {backupServerData();},_downloadstatsInterval);
  1089.  
  1090. room.onPlayerJoin = function(player) {
  1091. clonekick(player);
  1092. playerName = player.name.replace(/ /g,"_");
  1093. room.sendChat("💬 Hi @" + playerName + " !" )
  1094. room.sendChat("@" + playerName + " Write !help, !adminhelp, !rankhelp for commands." )
  1095. room.sendChat("@" + playerName + " --> Confirm now to get your stats saved.[!confirm password]" )
  1096. var players = room.getPlayerList();
  1097. var adminNumber = 0;
  1098. for (var i = 0; i < players.length; i++) {
  1099. if (players[i].admin) {
  1100. adminNumber++;
  1101. }
  1102. }
  1103. if (adminNumber < 2) {
  1104. room.setPlayerAdmin(players[1].id, true);
  1105. }
  1106. }
  1107. room.onPlayerLeave = function(player) {
  1108. var players = room.getPlayerList();
  1109. var adminNumber = 0;
  1110. for (var i = 0; i < players.length; i++) {
  1111. if (players[i].admin) {
  1112. adminNumber++;
  1113. }
  1114. }
  1115. if (adminNumber < 2) {
  1116. room.setPlayerAdmin(players[1].id, true);
  1117. }
  1118. }
  1119.  
  1120. function isOutsideStadium(ballPosition) {
  1121. return ballPosition.x > stadiumWidth || ballPosition.x < -stadiumWidth || ballPosition.y > stadiumHeight || ballPosition.y < -stadiumHeight;
  1122. }
  1123.  
  1124. var isBallOutsideStadium = false;
  1125.  
  1126. function checkBallPosition() {
  1127. var ballPosition = room.getBallPosition();
  1128. if(isOutsideStadium(ballPosition)) {
  1129. if(!isBallOutsideStadium) {
  1130. isBallOutsideStadium = true;
  1131. exitingPos = ballPosition.x;
  1132. var totalScores = room.getScores().red + room.getScores().blue;
  1133. if(lastScores != totalScores) {
  1134. lastScores = totalScores;
  1135. return false;
  1136. }
  1137. if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.RED || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.BLUE) {
  1138. lastCall = "GK";
  1139. room.sendChat("GK");
  1140. }
  1141. else if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.BLUE || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.RED) {
  1142. room.sendChat("CK");
  1143. lastCall = "CK";
  1144. }
  1145. else {
  1146. isBallKickedOutside = false;
  1147. room.sendChat(lastTeamTouched == Team.RED ? "B" : "R");
  1148. lastCall = lastTeamTouched == Team.RED ? "2" : "1";
  1149. }
  1150.  
  1151. }
  1152. }
  1153. else {
  1154. isBallOutsideStadium = false;
  1155. backMSG = true;
  1156.  
  1157. }
  1158. return true;
  1159. }
  1160.  
  1161. function getLastTouchTheBalltwo() {
  1162. var ballPosition = room.getBallPosition();
  1163. var players = room.getPlayerList();
  1164. for(var i = 0; i < players.length; i++) {
  1165. if(players[i].position != null) {
  1166. var distanceToBall = pointDistance(players[i].position, ballPosition);
  1167. if(distanceToBall < triggerDistance) {
  1168. if(lastPlayerTouched!=players[i].name)
  1169. {
  1170. if(lastTeamTouched==players[i].team)
  1171. {
  1172. assistingTouch = lastPlayerTouched;
  1173. }else assistingTouch = "";
  1174. }
  1175. lastTeamTouched = players[i].team;
  1176. previousPlayerTouched == lastPlayerTouched;
  1177. lastPlayerTouched = players[i].name;
  1178. }
  1179. }
  1180. }
  1181. return lastPlayerTouched;
  1182. }
  1183.  
  1184. /*
  1185. function filter(message)
  1186. {
  1187. message = message.toLowerCase();
  1188. message = message.replace(/\s/g, '');
  1189. message = message.replace(/\./g,' ')
  1190. if(message.includes("pizd") || message.includes("pedal") || message.includes("retard") || message.includes("debil") || message.includes("idiot") || message.includes("kurw") || message.includes("pierd") || message.includes("jeb") || message.includes("fuck") || message.includes("szmat") || message.includes("bitch") || message.includes("suck") || message.includes("dick") || message.includes("sikerim") || message.includes("orospu") || message.includes("çocuğu") || message.includes("scheiße") || message.includes("dich") || message.includes("fick") || message.includes("hure") || message.includes("ass") || message.includes("whore") || message.includes("shit") || message.includes("gown") || message.includes("huj") || message.includes("dziwk") ||message.includes("kutas"))
  1191. {
  1192. return true;
  1193. }else return false;
  1194. }
  1195. room.onPlayerChat = function(player, message) {
  1196. if(filter(message))
  1197. {
  1198. return false;
  1199. }
  1200. }
  1201. */
  1202.  
  1203. function pointDistance(p1, p2) {
  1204. var d1 = p1.x - p2.x;
  1205. var d2 = p1.y - p2.y;
  1206. return Math.sqrt(d1 * d1 + d2 * d2);
  1207. }
  1208. var playersNotInLine = new Array;
  1209. function getPlayersNotWithinLine() {
  1210. console.log("test");
  1211. playersNotInLine = new Array;
  1212. var players = room.getPlayerList();
  1213. for (var i = 0; i < players.length; i++) {
  1214. if (players[i].position != null) {
  1215. if (players[i].team != lastTeamTouched && players[i].team != lastCall && lastCall != "CK" && lastCall != "GK") {
  1216. if ((players[i].position.y > greenLine || players[i].position.y < -greenLine) && pointDistance(room.getBallPosition(), players[i].position) < 500) {
  1217. playersNotInLine.push(players[i].name);
  1218. }
  1219. }
  1220.  
  1221. }
  1222. }
  1223. }
  1224. function checkPlayersLine() {
  1225.  
  1226. console.log("2");
  1227. for(var i = 0; i < playersNotInLine.length; i++)
  1228. {
  1229. var found = false;
  1230. for (var j = 0; j < lineCrossedPlayers.length; j++) {
  1231. if (lineCrossedPlayers[j].name == playersNotInLine[i]) {
  1232. lineCrossedPlayers[j].times = lineCrossedPlayers[j].times + 1;
  1233. room.sendChat("LINE - " + lineCrossedPlayers[j].name + " {" + lineCrossedPlayers[j].times + "}");
  1234. found = true;
  1235. }
  1236.  
  1237. }
  1238. if (!found) {
  1239. lineCrossedPlayers.push({
  1240. name: playersNotInLine[i],
  1241. times: 1,
  1242. punished: false
  1243. });
  1244. room.sendChat("LINE - " + playersNotInLine[i] + " {1}");
  1245. }
  1246. }
  1247.  
  1248. }
  1249. var trigger = false;
  1250. var wrongThrowPosition = false;
  1251. function isBackRequired()
  1252. {
  1253. var ballPosition = room.getBallPosition();
  1254. if(!isBallKickedOutside)
  1255. {
  1256. if(lastCall=="1")
  1257. {
  1258. if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  1259. {
  1260. backMSG = false;
  1261. room.sendChat("BACK");
  1262. trigger = true;
  1263. wrongThrowPosition = true;
  1264. }
  1265. if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  1266. {
  1267. backMSG = false;
  1268. room.sendChat("FURTHER");
  1269. trigger = true;
  1270. wrongThrowPosition = true;
  1271. }
  1272. }
  1273. if(lastCall=="2")
  1274. {
  1275. if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  1276. {
  1277. backMSG = false;
  1278. room.sendChat("FURTHER");
  1279. trigger = true;
  1280. wrongThrowPosition = true;
  1281. }
  1282. if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  1283. {
  1284. backMSG = false;
  1285. room.sendChat("BACK");
  1286. trigger = true;
  1287. wrongThrowPosition = true;
  1288. }
  1289. }
  1290. }
  1291. if(lastCall=="2" && trigger && isOutsideStadium && Math.abs(exitingPos - ballPosition.x)< throwInLeeway-20)
  1292. {
  1293. room.sendChat("OK");
  1294. trigger = false;
  1295. wrongThrowPosition = false;
  1296. backMSG = true;
  1297. }
  1298. if(lastCall=="1" && trigger && isOutsideStadium && Math.abs(exitingPos - ballPosition.x)< throwInLeeway-20)
  1299. {
  1300. room.sendChat("OK");
  1301. trigger = false;
  1302. wrongThrowPosition = false;
  1303. backMSG = true;
  1304. }
  1305.  
  1306.  
  1307.  
  1308. }
  1309. function isThrowInCorrect()
  1310. {
  1311. var ballPosition = room.getBallPosition();
  1312. var boolCrossing = isBallCrossingTheLine();
  1313. var string = lastTeamTouched.toString();
  1314.  
  1315. if(boolCrossing && !isBallKickedOutside && string==lastCall && (lastCall=="1" || lastCall=="2"))
  1316. {
  1317.  
  1318. if(lastCall=="2")
  1319. {
  1320. room.sendChat("RED (BAD THROW-IN)");
  1321. }
  1322. if(lastCall=="1")
  1323. {
  1324. room.sendChat("BLUE (BAD THROW-IN)");
  1325. }
  1326.  
  1327. isBallKickedOutside == false;
  1328. }else if(boolCrossing && string!=lastCall && (lastCall=="1" || lastCall=="2"))
  1329. {
  1330. //room.sendChat("WRONG TEAM");
  1331. wrongThrowPosition = false;
  1332. trigger = false;
  1333. }else if(boolCrossing && wrongThrowPosition&& string==lastCall && (lastCall=="1" || lastCall=="2"))
  1334. {
  1335. room.sendChat("WRONG PLACE");
  1336. wrongThrowPosition = false;
  1337. trigger = false;
  1338. }else if(boolCrossing)
  1339. {
  1340. checkPlayersLine();
  1341. }
  1342.  
  1343. }
  1344. function isBallCrossingTheLine()
  1345. {
  1346. previousBallPos = lineBallPosition;
  1347. lineBallPosition = room.getBallPosition().y;
  1348. crossed = (lineBallPosition<stadiumHeight && previousBallPos>stadiumHeight) || (lineBallPosition>-stadiumHeight && previousBallPos<-stadiumHeight);
  1349. return (lineBallPosition<stadiumHeight && previousBallPos>stadiumHeight) || (lineBallPosition>-stadiumHeight && previousBallPos<-stadiumHeight);
  1350. }
  1351.  
  1352. var previousBallPosForGoingUp;
  1353. var currentBallPosForGoingUp;
  1354.  
  1355. function hasBallLeftTheLine()
  1356. {
  1357. var ballPosition = room.getBallPosition();
  1358. if(ballPosition.y<outLineY && isBallKickedOutside)
  1359. {
  1360. }else if (ballPosition.y>outLineY && isBallKickedOutside && lastPlayerTouched==previousPlayerTouched)
  1361. {
  1362. room.sendChat("BAD THROW-IN");
  1363. }
  1364.  
  1365. }
  1366. room.onStadiumChange = function(newStadiumName, byPlayer) {
  1367. if (newStadiumName != "Real Soccer 1.3D by RawR") {
  1368. room.setCustomStadium(RSHLMap);
  1369. }
  1370. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement