Advertisement
tomasg2000

HOST BOT

Jan 20th, 2020
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.31 KB | None | 0 0
  1. var roomName = "host prueba";
  2. var maxPlayers = 16;
  3. var roomPublic = true;
  4. var playerName = "Arbitro ARSA";
  5.  
  6. /* STADIUM */
  7. //Wartosci dotycza boiska na którym rozgrywany jest mecz - wartosci domyslne 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 = 52;
  34. var long = 21;
  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, geo: {"code": "AR", "lat": -34.6131500, "lon": -58.3772300 }});
  45. room.setScoreLimit(0);
  46. room.setTimeLimit(0);
  47. var RSHLMap = `{
  48.  
  49. "name" : "Real Soccer 1.3D by RawR",
  50.  
  51. "width" : 1300,
  52.  
  53. "height" : 670,
  54.  
  55. "spawnDistance" : 500,
  56.  
  57. "bg" : { "type" : "grass", "width" : 1150, "height" : 600, "kickOffRadius" : 180, "cornerRadius" : 0 },
  58.  
  59. "playerPhysics" : {
  60. "bCoef" : 0.5,
  61. "invMass" : 0.5,
  62. "damping" : 0.96,
  63. "acceleration" : 0.12,
  64. "kickingAcceleration" : 0.07,
  65. "kickingDamping" : 0.96,
  66. "kickStrength" : 5.65
  67.  
  68. },
  69.  
  70. "vertexes" : [
  71. /* 0 */ { "x" : 0, "y" : 700, "trait" : "kickOffBarrier" },
  72. /* 1 */ { "x" : 0, "y" : 180, "trait" : "kickOffBarrier" },
  73. /* 2 */ { "x" : 0, "y" : -180, "trait" : "kickOffBarrier" },
  74. /* 3 */ { "x" : 0, "y" : -700, "trait" : "kickOffBarrier" },
  75.  
  76. /* 4 */ { "x" : 1150, "y" : 255, "trait" : "line" },
  77. /* 5 */ { "x" : 840, "y" : 255, "trait" : "line" },
  78. /* 6 */ { "x" : 1150, "y" : -255, "trait" : "line" },
  79. /* 7 */ { "x" : 840, "y" : -255, "trait" : "line" },
  80. /* 8 */ { "x" : 1150, "y" : 155, "trait" : "line" },
  81. /* 9 */ { "x" : 1030, "y" : 155, "trait" : "line" },
  82. /* 10 */ { "x" : 1150, "y" : -155, "trait" : "line" },
  83. /* 11 */ { "x" : 1030, "y" : -155, "trait" : "line" },
  84. /* 12 */ { "x" : 840, "y" : -135, "trait" : "line", "curve" : -130 },
  85. /* 13 */ { "x" : 840, "y" : 135, "trait" : "line", "curve" : -130 },
  86. /* 14 */ { "x" : -1150, "y" : -255, "trait" : "line", "curve" : -90, "color" : "97AC86" },
  87. /* 15 */ { "x" : -840, "y" : -255, "trait" : "line" },
  88. /* 16 */ { "x" : -1150, "y" : 255, "trait" : "line" },
  89. /* 17 */ { "x" : -840, "y" : 255, "trait" : "line" },
  90. /* 18 */ { "x" : -1150, "y" : -155, "trait" : "line" },
  91. /* 19 */ { "x" : -1030, "y" : -155, "trait" : "line" },
  92. /* 20 */ { "x" : -1150, "y" : 155, "trait" : "line" },
  93. /* 21 */ { "x" : -1030, "y" : 155, "trait" : "line" },
  94. /* 22 */ { "x" : -840, "y" : 135, "trait" : "line", "curve" : -130 },
  95. /* 23 */ { "x" : -840, "y" : -135, "trait" : "line", "curve" : -130 },
  96. /* 24 */ { "x" : 935, "y" : 4, "trait" : "line" },
  97. /* 25 */ { "x" : 935, "y" : -4, "trait" : "line" },
  98. /* 26 */ { "x" : -935, "y" : 4, "trait" : "line" },
  99. /* 27 */ { "x" : -935, "y" : -4, "trait" : "line" },
  100. /* 28 */ { "x" : -1150, "y" : 525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  101. /* 29 */ { "x" : -1075, "y" : 600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line", "_selected" : true },
  102. /* 30 */ { "x" : -1075, "y" : -600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  103. /* 31 */ { "x" : -1150, "y" : -525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  104. /* 32 */ { "x" : 1075, "y" : 600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  105. /* 33 */ { "x" : 1150, "y" : 525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  106. /* 34 */ { "x" : 1150, "y" : -525, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  107. /* 35 */ { "x" : 1075, "y" : -600, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  108. /* 36 */ { "x" : -1150, "y" : 127, "trait" : "line", "color" : "ffffff" },
  109. /* 37 */ { "x" : -1214, "y" : 124, "trait" : "line", "color" : "ffffff", "curve" : 5 },
  110. /* 38 */ { "x" : -1150, "y" : -127, "trait" : "line", "color" : "ffffff" },
  111. /* 39 */ { "x" : -1214, "y" : -124, "trait" : "line", "color" : "ffffff", "curve" : 5 },
  112. /* 40 */ { "x" : 1150, "y" : 127, "trait" : "line", "color" : "ffffff" },
  113. /* 41 */ { "x" : 1214, "y" : 124, "trait" : "line", "color" : "ffffff", "curve" : -5 },
  114. /* 42 */ { "x" : 1150, "y" : -127, "trait" : "line", "color" : "ffffff" },
  115. /* 43 */ { "x" : 1214, "y" : -124, "trait" : "line", "color" : "ffffff", "curve" : -5 },
  116. /* 44 */ { "x" : 0, "y" : -4, "trait" : "line" },
  117. /* 45 */ { "x" : 0, "y" : 4, "trait" : "line" },
  118. /* 46 */ { "x" : 0, "y" : -4, "trait" : "line" },
  119. /* 47 */ { "x" : 0, "y" : 4, "trait" : "line" },
  120. /* 48 */ { "x" : -1214, "y" : 124, "trait" : "line", "color" : "ffffff" },
  121. /* 49 */ { "x" : -1250, "y" : 150, "trait" : "line", "color" : "ffffff", "pos" : [-1250,150 ] },
  122. /* 50 */ { "x" : -1214, "y" : -124, "trait" : "line", "color" : "ffffff" },
  123. /* 51 */ { "x" : -1250, "y" : -150, "trait" : "line", "color" : "ffffff", "pos" : [-1250,-150 ] },
  124. /* 52 */ { "x" : 1214, "y" : 124, "trait" : "line", "color" : "ffffff" },
  125. /* 53 */ { "x" : 1250, "y" : 150, "trait" : "line", "color" : "ffffff" },
  126. /* 54 */ { "x" : 1214, "y" : -124, "trait" : "line", "color" : "ffffff" },
  127. /* 55 */ { "x" : 1250, "y" : -150, "trait" : "line", "color" : "ffffff" },
  128. /* 56 */ { "x" : -1185, "y" : 155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
  129. /* 57 */ { "x" : -1185, "y" : 255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
  130. /* 58 */ { "x" : 1185, "y" : 155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
  131. /* 59 */ { "x" : 1185, "y" : 255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
  132. /* 60 */ { "x" : -1185, "y" : -155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
  133. /* 61 */ { "x" : -1185, "y" : -255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : -40, "color" : "BEB86C" },
  134. /* 62 */ { "x" : 1185, "y" : -155, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
  135. /* 63 */ { "x" : 1185, "y" : -255, "bCoef" : -4.5, "cMask" : ["ball" ], "trait" : "line", "curve" : 40, "color" : "BEB86C" },
  136. /* 64 */ { "x" : 1158, "y" : -607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
  137. /* 65 */ { "x" : 1187, "y" : -578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : -60, "color" : "BEB86C" },
  138. /* 66 */ { "x" : 1158, "y" : 607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
  139. /* 67 */ { "x" : 1187, "y" : 578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 60, "color" : "BEB86C" },
  140. /* 68 */ { "x" : -1158, "y" : 607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
  141. /* 69 */ { "x" : -1187, "y" : 578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : -60, "color" : "BEB86C" },
  142. /* 70 */ { "x" : -1158, "y" : -607, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 0, "color" : "BEB86C" },
  143. /* 71 */ { "x" : -1187, "y" : -578, "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line", "curve" : 60, "color" : "BEB86C" },
  144. /* 72 */ { "x" : -1190, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  145. /* 73 */ { "x" : -1180, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  146. /* 74 */ { "x" : -1190, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  147. /* 75 */ { "x" : -1180, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  148. /* 76 */ { "x" : -1190, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  149. /* 77 */ { "x" : -1180, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  150. /* 78 */ { "x" : -1190, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  151. /* 79 */ { "x" : -1180, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  152. /* 80 */ { "x" : 1190, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  153. /* 81 */ { "x" : 1180, "y" : -255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  154. /* 82 */ { "x" : 1190, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  155. /* 83 */ { "x" : 1180, "y" : -155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  156. /* 84 */ { "x" : 1190, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  157. /* 85 */ { "x" : 1180, "y" : 255, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  158. /* 86 */ { "x" : 1190, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  159. /* 87 */ { "x" : 1180, "y" : 155, "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line", "color" : "000000", "curve" : 0 },
  160. /* 88 */ { "x" : -1148, "y" : -525, "trait" : "line", "curve" : -90, "color" : "5E844D" },
  161. /* 89 */ { "x" : 1148, "y" : -525, "trait" : "line", "color" : "5E844D" },
  162. /* 90 */ { "x" : -1148, "y" : 525, "trait" : "line", "curve" : -90, "color" : "5E844D" },
  163. /* 91 */ { "x" : 1148, "y" : 525, "trait" : "line", "color" : "5E844D" },
  164. /* 92 */ { "x" : -1150, "y" : -260, "trait" : "line", "curve" : -100, "color" : "5E844D" },
  165. /* 93 */ { "x" : -840, "y" : -600, "trait" : "line", "color" : "5E844D", "curve" : -100 },
  166. /* 94 */ { "x" : -1150, "y" : 260, "trait" : "line", "curve" : 100, "color" : "5E844D" },
  167. /* 95 */ { "x" : -840, "y" : 600, "trait" : "line", "color" : "5E844D", "curve" : 100 },
  168. /* 96 */ { "x" : -840, "y" : -1150, "trait" : "line", "color" : "5E844D", "curve" : -100 },
  169. /* 97 */ { "x" : 1150, "y" : -260, "trait" : "line", "curve" : 100, "color" : "5E844D" },
  170. /* 98 */ { "x" : 840, "y" : -600, "trait" : "line", "color" : "5E844D", "curve" : 100 },
  171. /* 99 */ { "x" : 1150, "y" : 260, "trait" : "line", "curve" : -100, "color" : "5E844D" },
  172. /* 100 */ { "x" : 840, "y" : 600, "trait" : "line", "color" : "5E844D", "curve" : -100 }
  173.  
  174. ],
  175.  
  176. "segments" : [
  177. { "v0" : 37, "v1" : 39, "curve" : 5, "color" : "ffffff", "trait" : "reargoalNetleft", "x" : -1210 },
  178.  
  179. { "v0" : 41, "v1" : 43, "curve" : -5, "color" : "ffffff", "trait" : "reargoalNetright" },
  180.  
  181. { "v0" : 4, "v1" : 5, "trait" : "line", "y" : 250 },
  182. { "v0" : 5, "v1" : 7, "trait" : "line", "x" : 840 },
  183. { "v0" : 6, "v1" : 7, "trait" : "line", "y" : -250 },
  184. { "v0" : 8, "v1" : 9, "trait" : "line", "y" : 150 },
  185. { "v0" : 9, "v1" : 11, "trait" : "line", "x" : 1030 },
  186. { "v0" : 10, "v1" : 11, "trait" : "line", "y" : -150 },
  187. { "v0" : 12, "v1" : 13, "curve" : -130, "trait" : "line", "x" : 840 },
  188. { "v0" : 14, "v1" : 15, "trait" : "line", "y" : -250 },
  189. { "v0" : 15, "v1" : 17, "trait" : "line", "x" : -840 },
  190. { "v0" : 16, "v1" : 17, "trait" : "line", "y" : 250 },
  191. { "v0" : 18, "v1" : 19, "trait" : "line", "y" : -150 },
  192. { "v0" : 19, "v1" : 21, "trait" : "line", "x" : -1030 },
  193. { "v0" : 20, "v1" : 21, "trait" : "line", "y" : 150 },
  194. { "v0" : 22, "v1" : 23, "curve" : -130, "trait" : "line", "x" : -840 },
  195. { "v0" : 24, "v1" : 25, "curve" : -180, "trait" : "line", "x" : 935 },
  196. { "v0" : 26, "v1" : 27, "curve" : -180, "trait" : "line", "x" : -935 },
  197. { "v0" : 24, "v1" : 25, "curve" : 180, "trait" : "line", "x" : 935 },
  198. { "v0" : 26, "v1" : 27, "curve" : 180, "trait" : "line", "x" : -935 },
  199. { "v0" : 24, "v1" : 25, "curve" : 90, "trait" : "line", "x" : 935 },
  200. { "v0" : 26, "v1" : 27, "curve" : 90, "trait" : "line", "x" : -935 },
  201. { "v0" : 24, "v1" : 25, "curve" : -90, "trait" : "line", "x" : 935 },
  202. { "v0" : 26, "v1" : 27, "curve" : -90, "trait" : "line", "x" : -935 },
  203. { "v0" : 24, "v1" : 25, "trait" : "line", "x" : 935 },
  204. { "v0" : 26, "v1" : 27, "trait" : "line", "x" : -935 },
  205. { "v0" : 28, "v1" : 29, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  206. { "v0" : 30, "v1" : 31, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  207. { "v0" : 32, "v1" : 33, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  208. { "v0" : 34, "v1" : 35, "curve" : 90, "bCoef" : 0, "cMask" : ["wall" ], "trait" : "line" },
  209.  
  210. { "v0" : 36, "v1" : 37, "curve" : 5, "color" : "ffffff", "trait" : "sidegoalNet" },
  211. { "v0" : 38, "v1" : 39, "curve" : -5, "color" : "ffffff", "trait" : "sidegoalNet" },
  212. { "v0" : 40, "v1" : 41, "curve" : -5, "color" : "ffffff", "trait" : "sidegoalNet" },
  213. { "v0" : 42, "v1" : 43, "curve" : 5, "color" : "ffffff", "trait" : "sidegoalNet" },
  214.  
  215. { "v0" : 44, "v1" : 45, "curve" : -180, "trait" : "line" },
  216. { "v0" : 46, "v1" : 47, "curve" : 180, "trait" : "line" },
  217. { "v0" : 44, "v1" : 45, "curve" : -90, "trait" : "line" },
  218. { "v0" : 46, "v1" : 47, "curve" : 90, "trait" : "line" },
  219. { "v0" : 48, "v1" : 49, "color" : "ffffff", "trait" : "line" },
  220. { "v0" : 50, "v1" : 51, "color" : "ffffff", "trait" : "line" },
  221. { "v0" : 52, "v1" : 53, "color" : "ffffff", "trait" : "line" },
  222. { "v0" : 54, "v1" : 55, "color" : "ffffff", "trait" : "line" },
  223. { "v0" : 56, "v1" : 57, "curve" : 40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : -1220 },
  224. { "v0" : 58, "v1" : 59, "curve" : -40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : 1220 },
  225. { "v0" : 60, "v1" : 61, "curve" : -40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : -1220 },
  226. { "v0" : 62, "v1" : 63, "curve" : 40, "vis" : true, "color" : "BEB86C", "bCoef" : -4.7, "cMask" : ["ball" ], "trait" : "line", "x" : 1220 },
  227. { "v0" : 64, "v1" : 65, "curve" : -60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
  228. { "v0" : 66, "v1" : 67, "curve" : 60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
  229. { "v0" : 68, "v1" : 69, "curve" : -60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
  230. { "v0" : 70, "v1" : 71, "curve" : 60, "vis" : true, "color" : "BEB86C", "bCoef" : -2.45, "cMask" : ["ball" ], "trait" : "line" },
  231.  
  232. { "v0" : 0, "v1" : 1, "trait" : "kickOffBarrier" },
  233. { "v0" : 1, "v1" : 2, "curve" : 180, "cGroup" : ["blueKO" ], "trait" : "kickOffBarrier" },
  234. { "v0" : 1, "v1" : 2, "curve" : -180, "cGroup" : ["redKO" ], "trait" : "kickOffBarrier" },
  235. { "v0" : 2, "v1" : 3, "trait" : "kickOffBarrier" },
  236.  
  237. { "v0" : 72, "v1" : 73, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  238. { "v0" : 74, "v1" : 75, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  239. { "v0" : 76, "v1" : 77, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  240. { "v0" : 78, "v1" : 79, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  241. { "v0" : 80, "v1" : 81, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  242. { "v0" : 82, "v1" : 83, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  243. { "v0" : 84, "v1" : 85, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  244. { "v0" : 86, "v1" : 87, "curve" : 0, "vis" : true, "color" : "000000", "bCoef" : -1, "cMask" : ["ball" ], "trait" : "line" },
  245. { "v0" : 88, "v1" : 89, "color" : "5E844D", "trait" : "line", "y" : -475 },
  246. { "v0" : 90, "v1" : 91, "color" : "5E844D", "trait" : "line", "y" : -475 },
  247. { "v0" : 92, "v1" : 93, "curve" : -100, "color" : "5E844D", "trait" : "line", "y" : -475 },
  248. { "v0" : 94, "v1" : 95, "curve" : 100, "color" : "5E844D", "trait" : "line", "y" : -475 },
  249. { "v0" : 97, "v1" : 98, "curve" : 100, "color" : "5E844D", "trait" : "line", "y" : -475 },
  250. { "v0" : 99, "v1" : 100, "curve" : -100, "color" : "5E844D", "trait" : "line", "y" : -475 }
  251.  
  252. ],
  253.  
  254. "goals" : [
  255. { "p0" : [-1160,-124 ], "p1" : [-1160,124 ], "team" : "red" },
  256. { "p0" : [1160,124 ], "p1" : [1160,-124 ], "team" : "blue" }
  257.  
  258. ],
  259.  
  260. "discs" : [
  261. { "pos" : [-1150,127 ], "color" : "FF0000", "bCoef" : 0.5, "trait" : "goalPost" },
  262. { "pos" : [-1150,-127 ], "color" : "FF0000", "bCoef" : 0.5, "trait" : "goalPost" },
  263. { "pos" : [1150,127 ], "color" : "0000FF", "bCoef" : 0.5, "trait" : "goalPost" },
  264. { "pos" : [1150,-127 ], "color" : "0000FF", "bCoef" : 0.5, "trait" : "goalPost" },
  265.  
  266. { "pos" : [-1250,150 ], "color" : "FF0000", "trait" : "stanchion" },
  267. { "pos" : [-1250,-150 ], "color" : "FF0000", "trait" : "stanchion" },
  268. { "pos" : [1250,150 ], "color" : "0000FF", "trait" : "stanchion", "x" : 1250 },
  269. { "pos" : [1250,-150 ], "color" : "0000FF", "trait" : "stanchion", "x" : 1250 },
  270.  
  271. { "radius" : 2, "invMass" : 0, "pos" : [-1150,-600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" },
  272. { "radius" : 2, "invMass" : 0, "pos" : [-1150,600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" },
  273. { "radius" : 2, "invMass" : 0, "pos" : [1150,-600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" },
  274. { "radius" : 2, "invMass" : 0, "pos" : [1150,600 ], "color" : "FFFFFF", "bCoef" : -0.1, "cMask" : ["ball" ], "trait" : "goalPost" }
  275.  
  276. ],
  277.  
  278. "planes" : [
  279. { "normal" : [0,1 ], "dist" : -635, "bCoef" : 0, "trait" : "ballArea" },
  280. { "normal" : [0,-1 ], "dist" : -635, "bCoef" : 0, "trait" : "ballArea" },
  281.  
  282. { "normal" : [0,1 ], "dist" : -670, "bCoef" : 0 },
  283. { "normal" : [0,-1 ], "dist" : -670, "bCoef" : 0 },
  284. { "normal" : [1,0 ], "dist" : -1300, "bCoef" : 0 },
  285. { "normal" : [-1,0 ], "dist" : -1300, "bCoef" : 0.1 },
  286. { "normal" : [1,0 ], "dist" : -1214, "bCoef" : 0, "cMask" : ["ball" ] },
  287. { "normal" : [-1,0 ], "dist" : -1214, "bCoef" : 0, "cMask" : ["ball" ] }
  288.  
  289. ],
  290.  
  291. "traits" : {
  292. "ballArea" : { "vis" : false, "bCoef" : 0, "cMask" : ["ball" ] },
  293. "goalPost" : { "radius" : 5, "invMass" : 0, "bCoef" : 2 },
  294. "stanchion" : { "radius" : 3, "invMass" : 0, "bCoef" : 3, "cMask" : ["none" ] },
  295. "cornerflag" : { "radius" : 3, "invMass" : 0, "bCoef" : 0.5, "color" : "FFFF00", "cGroup" : [ ] },
  296. "reargoalNetleft" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["ball","red","blue" ], "curve" : 10, "color" : "C7E6BD" },
  297. "reargoalNetright" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["ball","red","blue" ], "curve" : -10, "color" : "C7E6BD" },
  298. "sidegoalNet" : { "vis" : true, "bCoef" : 1, "cMask" : ["ball","red","blue" ], "color" : "C7E6BD" },
  299. "kickOffBarrier" : { "vis" : false, "bCoef" : 0.1, "cGroup" : ["redKO","blueKO" ], "cMask" : ["red","blue" ] },
  300. "line" : { "vis" : true, "cMask" : [ ], "color" : "C7E6BD" },
  301. "tunnel" : { "vis" : true, "cMask" : ["red","blue" ], "color" : "000000" },
  302. "advertising" : { "vis" : true, "cMask" : ["red","blue" ], "color" : "333333" },
  303. "teambench" : { "vis" : true, "cMask" : [ ], "color" : "000000" },
  304. "manager" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "333333" },
  305. "physio" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "666666" },
  306. "redsubs" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "E56E56" },
  307. "bluesubs" : { "radius" : 15, "vis" : true, "cMask" : ["red","blue" ], "invMass" : 0, "color" : "5689E5" }
  308.  
  309. },
  310.  
  311. "ballPhysics" : {
  312. "invMass" : 1.05,
  313. "radius" : 9.8
  314.  
  315. }
  316. }`;
  317. room.setCustomStadium(RSHLMap);
  318. room.onGameStart = function(player) {
  319. lineCrossedPlayers = [{name: "temp", times: 0}];
  320. lastScores = room.getScores().red + room.getScores().blue;
  321. timeOutside = 0;
  322. isTimeAddedShown = false;
  323. lineBallPosition = 0;
  324. }
  325.  
  326. room.onPlayerBallKick = function(player) {
  327. var ballPosition = room.getBallPosition();
  328. if(player.name!=lastPlayerTouched)
  329. {
  330. if(lastTeamTouched==player.team)
  331. {
  332. assistingTouch = lastPlayerTouched;
  333. }else assistingTouch = "";
  334. }
  335. previousPlayerTouched = lastPlayerTouched;
  336. lastPlayerTouched = player.name;
  337. lastTeamTouched = player.team;
  338. if(isBallOutsideStadium)
  339. {
  340. getPlayersNotWithinLine();
  341. }
  342. if(isBallOutsideStadium && ballPosition.y<0)
  343. {
  344. isBallKickedOutside = true;
  345. }else if(isBallOutsideStadium && ballPosition.y>0)
  346. {
  347. isBallKickedOutside = true;
  348. }else isBallKickedOutside = false;
  349. }
  350. function isBallGoingUp() {
  351. previousBallPosForGoingUp = currentBallPosForGoingUp;
  352. currentBallPosForGoingUp = room.getBallPosition().y;
  353. if (previousBallPosForGoingUp - currentBallPosForGoingUp > 0.01) {
  354. isBallUp = 2;
  355. } else if (previousBallPosForGoingUp - currentBallPosForGoingUp < -0.01) {
  356.  
  357. isBallUp = 1;
  358. } else {
  359. isBallUp = 0;
  360. }
  361. }
  362. function addedTime()
  363. {
  364. var ballPosition = room.getBallPosition();
  365. if(isOutsideStadium(ballPosition))
  366. {
  367. timeOutside++;
  368. return true;
  369. }
  370. }
  371.  
  372. function checkEnd() {
  373. var scores = room.getScores();
  374. if (scores.time > 590 && !isTimeAddedShown) {
  375. var actualTimeAdded = Math.round((timeOutside-(100*60))/120);
  376. if(actualTimeAdded<60&&actualTimeAdded>-1)
  377. {
  378. room.sendChat("SE ADICIONA: + " + actualTimeAdded + " SECONDS");
  379. }else if(actualTimeAdded<0)
  380. {
  381. room.sendChat("NO SE ADICIONA. (+0)");
  382. }else
  383. {
  384. room.sendChat("SE ADICIONA: + 1 MINUTE");
  385. }
  386. isTimeAddedShown = true;
  387. }
  388. }
  389. var tickCount = 0;
  390. room.onGameTick = function() {
  391. isThrowInCorrect();
  392. getLastTouchTheBall();
  393. checkBallPosition();
  394. isBackRequired();
  395. hasBallLeftTheLine();
  396. addedTime();
  397. checkEnd();
  398. tickCount++;
  399. }
  400.  
  401. room.onPlayerJoin = function(player) {
  402. var players = room.getPlayerList();
  403. var adminNumber = 0;
  404. for (var i = 0; i < players.length; i++) {
  405. if (players[i].admin) {
  406. adminNumber++;
  407. }
  408. }
  409. if (adminNumber < 2) {
  410. room.setPlayerAdmin(players[1].id, true);
  411. }
  412. }
  413.  
  414. function isOutsideStadium(ballPosition) {
  415. return ballPosition.x > stadiumWidth || ballPosition.x < -stadiumWidth || ballPosition.y > stadiumHeight || ballPosition.y < -stadiumHeight;
  416. }
  417.  
  418. var isBallOutsideStadium = false;
  419.  
  420. function checkBallPosition() {
  421. var ballPosition = room.getBallPosition();
  422. if(isOutsideStadium(ballPosition)) {
  423. if(!isBallOutsideStadium) {
  424. isBallOutsideStadium = true;
  425. exitingPos = ballPosition.x;
  426. var totalScores = room.getScores().red + room.getScores().blue;
  427. if(lastScores != totalScores) {
  428. lastScores = totalScores;
  429. return false;
  430. }
  431. if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.RED || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.BLUE) {
  432. lastCall = "ARCO";
  433. room.sendChat("ARCO");
  434. }
  435. else if(ballPosition.x > stadiumWidth && lastTeamTouched == Team.BLUE || ballPosition.x < -stadiumWidth && lastTeamTouched == Team.RED) {
  436. room.sendChat("CORNER");
  437. lastCall = "CORNER";
  438. }
  439. else {
  440. isBallKickedOutside = false;
  441. room.sendChat(lastTeamTouched == Team.RED ? "B" : "R");
  442. lastCall = lastTeamTouched == Team.RED ? "2" : "1";
  443. }
  444.  
  445. }
  446. }
  447. else {
  448. isBallOutsideStadium = false;
  449. backMSG = true;
  450.  
  451. }
  452. return true;
  453. }
  454.  
  455. function getLastTouchTheBall() {
  456. var ballPosition = room.getBallPosition();
  457. var players = room.getPlayerList();
  458. for(var i = 0; i < players.length; i++) {
  459. if(players[i].position != null) {
  460. var distanceToBall = pointDistance(players[i].position, ballPosition);
  461. if(distanceToBall < triggerDistance) {
  462. if(lastPlayerTouched!=players[i].name)
  463. {
  464. if(lastTeamTouched==players[i].team)
  465. {
  466. assistingTouch = lastPlayerTouched;
  467. }else assistingTouch = "";
  468. }
  469. lastTeamTouched = players[i].team;
  470. previousPlayerTouched == lastPlayerTouched;
  471. lastPlayerTouched = players[i].name;
  472. }
  473. }
  474. }
  475. return lastPlayerTouched;
  476. }
  477.  
  478. function filter(message)
  479. {
  480. message = message.toLowerCase();
  481. message = message.replace(/\s/g, '');
  482. message = message.replace(/\./g,' ')
  483. if(message.includes("????????????h????????????????C?????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????‚?¹ ??????????????? ????? ???????????????????? ???????????????????h????????????????C?????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????‚?¹ ??????????????? ????? ???????????????????? ???????") )
  484. {
  485. return true;
  486. }else return false;
  487. }
  488. room.onPlayerChat = function(player, message) {
  489. if(filter(message))
  490. {
  491. return false;
  492. }
  493. }
  494.  
  495. function pointDistance(p1, p2) {
  496. var d1 = p1.x - p2.x;
  497. var d2 = p1.y - p2.y;
  498. return Math.sqrt(d1 * d1 + d2 * d2);
  499. }
  500. var playersNotInLine = new Array;
  501. function getPlayersNotWithinLine() {
  502. console.log("test");
  503. playersNotInLine = new Array;
  504. var players = room.getPlayerList();
  505. for (var i = 0; i < players.length; i++) {
  506. if (players[i].position != null) {
  507. if (players[i].team != lastTeamTouched && players[i].team != lastCall && lastCall != "CK" && lastCall != "GK") {
  508. if ((players[i].position.y > greenLine || players[i].position.y < -greenLine) && pointDistance(room.getBallPosition(), players[i].position) < 500) {
  509. playersNotInLine.push(players[i].name);
  510. }
  511. }
  512.  
  513. }
  514. }
  515. }
  516. function checkPlayersLine() {
  517.  
  518. console.log("2");
  519. for(var i = 0; i < playersNotInLine.length; i++)
  520. {
  521. var found = false;
  522. for (var j = 0; j < lineCrossedPlayers.length; j++) {
  523. if (lineCrossedPlayers[j].name == playersNotInLine[i]) {
  524. lineCrossedPlayers[j].times = lineCrossedPlayers[j].times + 1;
  525. room.sendChat("FALTA - " + lineCrossedPlayers[j].name + " {" + lineCrossedPlayers[j].times + "}");
  526. found = true;
  527. }
  528.  
  529. }
  530. if (!found) {
  531. lineCrossedPlayers.push({
  532. name: playersNotInLine[i],
  533. times: 1,
  534. punished: false
  535. });
  536. room.sendChat("FALTA - " + playersNotInLine[i] + " {1}");
  537. }
  538. }
  539.  
  540. }
  541. var trigger = false;
  542. var wrongThrowPosition = false;
  543. function isBackRequired()
  544. {
  545. var ballPosition = room.getBallPosition();
  546. if(!isBallKickedOutside)
  547. {
  548. if(lastCall=="1")
  549. {
  550. if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  551. {
  552. backMSG = false;
  553. room.sendChat("ATRAS");
  554. trigger = true;
  555. wrongThrowPosition = true;
  556. }
  557. if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  558. {
  559. backMSG = false;
  560. room.sendChat("ADELANTE");
  561. trigger = true;
  562. wrongThrowPosition = true;
  563. }
  564. }
  565. if(lastCall=="2")
  566. {
  567. if((ballPosition.x - exitingPos > throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  568. {
  569. backMSG = false;
  570. room.sendChat("ADELANTE");
  571. trigger = true;
  572. wrongThrowPosition = true;
  573. }
  574. if((ballPosition.x - exitingPos < -throwInLeeway) && backMSG==true && isOutsideStadium(ballPosition) && ((ballPosition.y - outLineY > 20) || (ballPosition.y - outLineY < -20)))
  575. {
  576. backMSG = false;
  577. room.sendChat("ATRAS");
  578. trigger = true;
  579. wrongThrowPosition = true;
  580. }
  581. }
  582. }
  583. if(lastCall=="2" && trigger && isOutsideStadium && Math.abs(exitingPos - ballPosition.x)< throwInLeeway-20)
  584. {
  585. room.sendChat("OK");
  586. trigger = false;
  587. wrongThrowPosition = false;
  588. backMSG = true;
  589. }
  590. if(lastCall=="1" && trigger && isOutsideStadium && Math.abs(exitingPos - ballPosition.x)< throwInLeeway-20)
  591. {
  592. room.sendChat("OK");
  593. trigger = false;
  594. wrongThrowPosition = false;
  595. backMSG = true;
  596. }
  597.  
  598.  
  599.  
  600. }
  601. function isThrowInCorrect()
  602. {
  603. var ballPosition = room.getBallPosition();
  604. var boolCrossing = isBallCrossingTheLine();
  605. var string = lastTeamTouched.toString();
  606.  
  607. if(boolCrossing && !isBallKickedOutside && string==lastCall && (lastCall=="1" || lastCall=="2"))
  608. {
  609.  
  610. if(lastCall=="2")
  611. {
  612. room.sendChat("RED (MAL SACADO)");
  613. }
  614. if(lastCall=="1")
  615. {
  616. room.sendChat("BLUE (MAL SACADO)");
  617. }
  618.  
  619. isBallKickedOutside == false;
  620. }else if(boolCrossing && string!=lastCall && (lastCall=="1" || lastCall=="2"))
  621. {
  622. //room.sendChat("WRONG TEAM");
  623. wrongThrowPosition = false;
  624. trigger = false;
  625. }else if(boolCrossing && wrongThrowPosition&& string==lastCall && (lastCall=="1" || lastCall=="2"))
  626. {
  627. room.sendChat("LUGAR EQUIVOCADO");
  628. wrongThrowPosition = false;
  629. trigger = false;
  630. }else if(boolCrossing)
  631. {
  632. checkPlayersLine();
  633. }
  634.  
  635. }
  636. function isBallCrossingTheLine()
  637. {
  638. previousBallPos = lineBallPosition;
  639. lineBallPosition = room.getBallPosition().y;
  640. crossed = (lineBallPosition<stadiumHeight && previousBallPos>stadiumHeight) || (lineBallPosition>-stadiumHeight && previousBallPos<-stadiumHeight);
  641. return (lineBallPosition<stadiumHeight && previousBallPos>stadiumHeight) || (lineBallPosition>-stadiumHeight && previousBallPos<-stadiumHeight);
  642. }
  643.  
  644. var previousBallPosForGoingUp;
  645. var currentBallPosForGoingUp;
  646.  
  647. function hasBallLeftTheLine()
  648. {
  649. var ballPosition = room.getBallPosition();
  650. if(ballPosition.y<outLineY && isBallKickedOutside)
  651. {
  652. }else if (ballPosition.y>outLineY && isBallKickedOutside && lastPlayerTouched==previousPlayerTouched)
  653. {
  654. room.sendChat("MAL SACADO");
  655. }
  656.  
  657. }
  658.  
  659. /*
  660. Functions
  661. */
  662. // If there are no admins left in the room give admin to one of the remaining players.
  663. function updateAdmins() {
  664. // Get all players except the host (id = 0 is always the host)
  665. var players = room.getPlayerList().filter((player) => player.id != 0 );
  666. if ( players.length == 0 ) return; // No players left, do nothing.
  667. if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  668. room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  669. }
  670.  
  671. function initPlayerStats(player){
  672. if (stats.get(player.name)) return;
  673. stats.set(player.name, [0, 0, 0, 0, 0, 0]) // goals, assists, wins, loses, og, cs
  674. }
  675.  
  676.  
  677.  
  678. /*
  679. for commands
  680. */
  681.  
  682. function swapFun(player){
  683. if (player.admin == true){
  684. if (room.getScores() == null) {
  685. players = room.getPlayerList();
  686. for (i = 0; i < players.length; i++){
  687. if (players[i].team == 1){
  688. room.setPlayerTeam(players[i].id, 2);
  689. }
  690. else if (players[i].team == 2){
  691. room.setPlayerTeam(players[i].id, 1);
  692. }
  693. }
  694. }
  695. }
  696. }
  697.  
  698.  
  699. function pushMuteFun(player, message){ // !mute Anddy
  700. // Prevent somebody to talk in the room (uses the nickname, not the id)
  701. // need to be admin
  702. if (player.admin == true){
  703. if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
  704. }
  705. }
  706.  
  707.  
  708. function gotMutedFun(player){
  709. if (mutedPlayers.includes(player.name)){
  710. return true;
  711. }
  712. }
  713.  
  714. function unmuteFun(player, message){ // !unmute Anddy
  715. // Allow somebody to talk if he has been muted
  716. // need to be admin
  717. if (player.admin == true){
  718. pos = mutedPlayers.indexOf(message.substr(9));
  719. mutedPlayers.splice(pos, 1);
  720. }
  721. }
  722.  
  723. function adminFun(player, message){ // !admin Anddyisthebest
  724. // Gives admin to the person who type this password
  725.  
  726. room.setPlayerAdmin(player.id, true);
  727. return false; // The message won't be displayed
  728. }
  729.  
  730. function putPauseFun() { // p
  731. room.pauseGame(true);
  732. }
  733.  
  734. function unPauseFun() { // !p
  735. room.pauseGame(false);
  736. }
  737.  
  738. function helpFun() { // !help
  739. room.sendChat('Available commands: "p", "!p" , "!stats Nickname", "!ranking", "!poss", "!resetstats", "!adminhelp", "!gkhelp", "!rankhelp"');
  740. }
  741.  
  742. function adminHelpFun() {
  743. room.sendChat('Available commands: "!mute Player", "!unmute Player", ' +
  744. '"!clearbans", "!rr", "!swap" (to switch reds and blues). You need to be admin.')
  745. }
  746.  
  747.  
  748. function gkHelpFun() { // !gkhelp
  749. room.sendChat('The most backward player at the kick off will be set as gk ! (write "!gk" if the bot was wrong).')
  750. }
  751. function rankHelpFun() { // !gkhelp
  752. room.sendChat("Get points by doing good things in this room ! Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts.")
  753. }
  754.  
  755.  
  756. function statsFun(player, message){ // !stats Anddy
  757. if (stats.get(message.substr(7))){
  758. sendStats(message.substr(7));
  759. } else{ return false;}
  760. }
  761.  
  762. function rankFun() { // !ranking
  763. string = ranking();
  764. room.sendChat("Ranking: " + string);
  765. }
  766.  
  767. function resetStatsFun (player){ // !resetstats
  768. if (rankingCalc(player.name) > 0){
  769. stats.set(player.name, [0,0,0,0,0,0]);
  770. room.sendChat("Your stats have been reseted ! ")
  771. }
  772. else (room.sendChat("You must have positive points to be able to reset it, sorry."))
  773. }
  774.  
  775. function clearFun(player){ // !clear
  776. if (player.admin == true) room.clearBans();
  777. }
  778.  
  779. function resetFun(player){
  780. if (player.admin == true){
  781. room.stopGame();
  782. room.startGame();
  783. }
  784. }
  785.  
  786. function gkFun(player){ // !gk
  787.  
  788. if (room.getScores() != null && room.getScores().time < 60){
  789. if (player.team == 1) {
  790. gk[0] = player;
  791. }
  792. else if (player.team == 2){
  793. gk[1] = player;
  794. }
  795. }
  796. return;
  797. }
  798.  
  799.  
  800. function closeFun(player){
  801. if (player.name == "js2ps"){ // artificially generate an error in order to close the room
  802. stats.crash();
  803. }
  804. }
  805.  
  806.  
  807.  
  808. /*
  809. For ranking
  810. */
  811.  
  812. function rankingCalc(player){
  813. return stats.get(player)[0] * 5 + stats.get(player)[1] * 3 +
  814. stats.get(player)[2] * 3 + stats.get(player)[5] * 6 -
  815. stats.get(player)[3] * 7 - stats.get(player)[4] * 4;
  816. }
  817.  
  818. function ranking(){
  819.  
  820. var overall = [];
  821. players = Array.from(stats.keys());
  822. for (var i = 2; i < players.length; i++) {
  823. score = rankingCalc(players[i])
  824. // Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts
  825. overall.push({name: players[i], value: score});
  826. }
  827. overall.sort(function(a,b){
  828. return b.value - a.value;
  829. })
  830. string = "";
  831.  
  832. for (var i = 0; i < overall.length; i++) {
  833. if (overall[i].value != 0){
  834. string += i+1 + ") " + overall[i].name + ": " + overall[i].value + " pts, ";
  835. }
  836. }
  837. return string;
  838. }
  839.  
  840. function sendStats(name){
  841. ps = stats.get(name); // stands for playerstats
  842. room.sendChat(name + ": goals: " + ps[0] + ", assists: " + ps[1]
  843. + ", og: " + ps[4] + ", cs: " + ps[5] + ", wins: " + ps[2] + ", loses: " + ps[3] +
  844. " points: " + rankingCalc(name));
  845. }
  846.  
  847.  
  848. function whichTeam(){ // gives the players in the red or blue team
  849. var players = room.getPlayerList();
  850. var redTeam = players.filter(player => player.team == 1);
  851. var blueTeam = players.filter(player => player.team == 2);
  852. return [redTeam, blueTeam]
  853. }
  854.  
  855.  
  856.  
  857. function isGk(){ // gives the mosts backward players before the first kickOff
  858. var players = room.getPlayerList();
  859. var min = players[0];
  860. min.position = {x: room.getBallPosition().x + 60}
  861. var max = min;
  862.  
  863. for (var i = 0; i < players.length; i++) {
  864. if (players[i].position != null){
  865. if (min.position.x > players[i].position.x) min = players[i];
  866. if (max.position.x < players[i].position.x) max = players[i];
  867. }
  868. }
  869. return [min, max]
  870. }
  871.  
  872.  
  873.  
  874.  
  875.  
  876. function updateWinLoseStats(winners, losers){
  877. for (var i = 0; i < winners.length; i++) {
  878. stats.get(winners[i].name)[2] += 1;
  879. }
  880. for (var i = 0; i < losers.length; i++) {
  881. stats.get(losers[i].name)[3] += 1;
  882. }
  883. }
  884.  
  885. function initBallCarrying(redTeam, blueTeam){
  886. var ballCarrying = new Map();
  887. var playing = redTeam.concat(blueTeam);
  888. for (var i = 0; i < playing.length; i++) {
  889. ballCarrying.set(playing[i].name, [0, playing[i].team]); // secs, team, %
  890. }
  891. return ballCarrying;
  892. }
  893.  
  894.  
  895.  
  896. function updateTeamPoss(value){
  897. if (value[1] == 1) redPoss += value[0];
  898. if (value[1] == 2) bluePoss += value[0];
  899. }
  900.  
  901. var bluePoss;
  902. var redPoss;
  903. function teamPossFun(){
  904. if (room.getScores() == null) return false;
  905. bluePoss = 0;
  906. redPoss = 0
  907. ballCarrying.forEach(updateTeamPoss);
  908. redPoss = Math.round((redPoss / room.getScores().time) * 100);
  909. bluePoss = Math.round((bluePoss / room.getScores().time) * 100);
  910. room.sendChat("Ball possession: red " + redPoss + " - " + bluePoss + " blue." );
  911.  
  912. }
  913.  
  914.  
  915.  
  916. /*
  917. For the game
  918. */
  919.  
  920. // Gives the last player who touched the ball, works only if the ball has the same
  921. // size than in classics maps.
  922. var radiusBall = 10;
  923. var triggerDistance = radiusBall + 15 + 0.1;
  924. function getLastTouchTheBall(lastPlayerTouched, time) {
  925. var ballPosition = room.getBallPosition();
  926. var players = room.getPlayerList();
  927. for(var i = 0; i < players.length; i++) {
  928. if(players[i].position != null) {
  929. var distanceToBall = pointDistance(players[i].position, ballPosition);
  930. if(distanceToBall < triggerDistance) {
  931. lastPlayerTouched = players[i];
  932. return lastPlayerTouched;
  933. }
  934. }
  935. }
  936. return lastPlayerTouched;
  937.  
  938. }
  939.  
  940.  
  941.  
  942. // Calculate the distance between 2 points
  943. function pointDistance(p1, p2) {
  944. var d1 = p1.x - p2.x;
  945. var d2 = p1.y - p2.y;
  946. return Math.sqrt(d1 * d1 + d2 * d2);
  947. }
  948.  
  949. function isOvertime(){
  950. scores = room.getScores();
  951. if (scores != null){
  952. if (scores.timeLimit != 0){
  953. if (scores.time > scores.timeLimit){
  954. if (scores.red == 0 && hasFinished == false){
  955. stats.get(gk[0].name)[5] += 1;
  956. stats.get(gk[1].name)[5] += 1;
  957. hasFinished = true;
  958. }
  959. }
  960. }
  961. }
  962. }
  963. // return: the name of the team who took a goal
  964. var team_name = team => team == 1 ? "blue" : "red";
  965.  
  966. // return: whether it's an OG
  967. var isOwnGoal = (team, player) => team != player.team ? " (og)" : "";
  968.  
  969. // return: a better display of the second when a goal is scored
  970. var floor = s => s < 10 ? "0" + s : s;
  971.  
  972. // return: whether there's an assist
  973. var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (" + playerList[1].name + ")" : "";
  974.  
  975.  
  976.  
  977. /*
  978. Events
  979. */
  980. var stats = new Map(); // map where will be set all player stats
  981. var mutedPlayers = []; // Array where will be added muted players
  982. var init = "init"; // Smth to initialize smth
  983. init.id = 0; // Faster than getting host's id with the method
  984. init.name = "init";
  985. var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
  986. var whoTouchedLast; // var representing the last player who touched the ball
  987. var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
  988. var gk = [init, init];
  989. var goalScored = false;
  990.  
  991. var commands = {
  992. // Command that doesnt need to know players attributes.
  993. "!help": helpFun,
  994. "!gkhelp": gkHelpFun,
  995. "!adminhelp": adminHelpFun,
  996. "!rankhelp": rankHelpFun,
  997. "!ranking": rankFun,
  998. "p": putPauseFun,
  999. "!p": unPauseFun,
  1000. "!poss": teamPossFun,
  1001.  
  1002. // Command that need to know who is the player.
  1003. "!resetstats": resetStatsFun,
  1004. "!gk": gkFun,
  1005. "!uzvara": adminFun,
  1006.  
  1007. // Command that need to know if a player is admin.
  1008. "!swap": swapFun,
  1009. "!rr": resetFun,
  1010. "!clear": clearFun,
  1011. "!close": closeFun,
  1012.  
  1013. // Command that need to know what's the message.
  1014. "!stats": statsFun,
  1015.  
  1016. // Command that need to know who is the player and what's the message.
  1017. "!mute" : pushMuteFun,
  1018. "!unmute": unmuteFun
  1019.  
  1020. }
  1021.  
  1022. initPlayerStats(room.getPlayerList()[0]) // lazy lol, i'll fix it later
  1023. initPlayerStats(init);
  1024.  
  1025. room.onPlayerLeave = function(player) {
  1026. updateAdmins();
  1027. }
  1028.  
  1029.  
  1030.  
  1031. room.onPlayerJoin = function(player) {
  1032. updateAdmins(); // Gives admin to the first player who join the room if there's no one
  1033. initPlayerStats(player); // Set new player's stat
  1034. room.sendChat("Hi " + player.name + " ! Write !help, !adminhelp, !rankhelp or !gkhelp if needed." )
  1035. }
  1036.  
  1037. var redTeam;
  1038. var blueTeam;
  1039. room.onGameStart = function() {
  1040. [redTeam,blueTeam] = whichTeam();
  1041. ballCarrying = initBallCarrying(redTeam, blueTeam);
  1042. }
  1043.  
  1044. room.onPlayerTeamChange = function(player){
  1045. if (room.getScores() != null){
  1046. if (1 <= player.team <= 2) ballCarrying.set(player.name, [0, player.team]);
  1047. }
  1048. }
  1049.  
  1050.  
  1051.  
  1052. room.onPlayerChat = function(player, message) {
  1053. if (mutedPlayers.includes(player.name)) return false;
  1054. let spacePos = message.search(" ");
  1055. let command = message.substr(0, spacePos !== -1 ? spacePos : message.length);
  1056. if (commands.hasOwnProperty(command) == true) return commands[command](player, message);
  1057.  
  1058. }
  1059.  
  1060.  
  1061.  
  1062.  
  1063. room.onPlayerBallKick = function (player){
  1064. whoTouchedLast = player;
  1065. }
  1066.  
  1067. var kickOff = false;
  1068. var hasFinished = false;
  1069.  
  1070. room.onGameTick = function() {
  1071.  
  1072. setInterval(isOvertime, 5000, hasFinished);
  1073.  
  1074. if (kickOff == false) { // simplest comparison to not charge usulessly the tick thing
  1075. if (room.getScores().time != 0){
  1076. kickOff = true;
  1077. gk = isGk();
  1078. room.sendChat("Red GK: " + gk[0].name + ", Blue GK: " + gk[1].name)
  1079. }
  1080. }
  1081. if (goalScored == false){
  1082. whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
  1083. }
  1084. if (whoTouchedLast != undefined) {
  1085.  
  1086. if (ballCarrying.get(whoTouchedLast.name)) {
  1087. ballCarrying.get(whoTouchedLast.name)[0] += 1/60;
  1088. }
  1089.  
  1090. if ( whoTouchedLast.id != whoTouchedBall[0].id){
  1091. whoTouchedBall[1] = whoTouchedBall[0];
  1092. whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
  1093. }
  1094. }
  1095. }
  1096.  
  1097. room.onTeamGoal = function(team){ // Write on chat who scored and when.
  1098.  
  1099. goalScored = true;
  1100. var time = room.getScores().time;
  1101. var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
  1102. time = m + ":" + floor(s); // MM:SS format
  1103. var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
  1104. var assist = "";
  1105. if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
  1106.  
  1107.  
  1108. room.sendChat("A goal has been scored by " + whoTouchedBall[0].name +
  1109. assist + ownGoal + " at " +
  1110. time + " against team " + team_name(team));
  1111.  
  1112. if (ownGoal != "") {
  1113. stats.get(whoTouchedBall[0].name)[4] += 1;
  1114. } else {
  1115. stats.get(whoTouchedBall[0].name)[0] += 1;
  1116. }
  1117.  
  1118. if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].name)[1] += 1;
  1119.  
  1120.  
  1121. if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
  1122. scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
  1123. whoTouchedBall = [init, init];
  1124. whoTouchedLast = undefined;
  1125. }
  1126.  
  1127. room.onPositionsReset = function(){
  1128. goalScored = false;
  1129. }
  1130.  
  1131. room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
  1132. if (scores.blue == 0 && gk[0].position != null && hasFinished == false) stats.get(gk[0].name)[5] += 1;
  1133. if (scores.red == 0 && gk[1].position != null && hasFinished == false) stats.get(gk[1].name)[5] += 1;
  1134. if (scores.red > scores.blue) {
  1135. updateWinLoseStats(redTeam, blueTeam);
  1136. }
  1137. else{ updateWinLoseStats(blueTeam, redTeam); }
  1138.  
  1139. room.sendChat("Scored goals:")
  1140. for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
  1141. room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
  1142. }
  1143. teamPossFun();
  1144. }
  1145.  
  1146. room.onGameStop = function(){
  1147. scorers = undefined;
  1148. whoTouchedBall = [init, init];
  1149. whoTouchedLast = undefined;
  1150. gk = [init, init];
  1151. kickOff = false;
  1152. hasFinished = false;
  1153. }
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161. // Made by Anddy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement