Advertisement
Guest User

ses

a guest
May 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.11 KB | None | 0 0
  1. /*
  2. This script is usable in https://www.haxball.com/headless
  3. Steps:
  4. 1) Copy this script
  5. 2) Go to the link, then press F12
  6. 3) Go to console if it's not already set, then paste
  7. 4) Enter
  8. 5) IF THIS TAB IS CLOSED THE ROOM WILL BE CLOSED TOO
  9. */
  10.  
  11. var room = HBInit({ roomName: "FUTSAL 4V4", maxPlayers: 14, playerName : "BANDZIOREK", public : true});
  12. var futsal = `{
  13.  
  14. "name" : "Futsal ChujowyRanking 4v4",
  15.  
  16. "width" : 1006,
  17.  
  18. "height" : 452,
  19.  
  20. "spawnDistance" : 310,
  21.  
  22. "bg" : { "type" : "hockey", "width" : 786, "height" : 386, "kickOffRadius" : 106, "cornerRadius" : 0 },
  23.  
  24. "vertexes" : [
  25. /* 0 */ { "x" : -787, "y" : 386, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  26. /* 1 */ { "x" : -787, "y" : 107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  27. /* 2 */ { "x" : -787, "y" : -107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  28. /* 3 */ { "x" : -787, "y" : -385, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  29. /* 4 */ { "x" : 787, "y" : 386, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  30. /* 5 */ { "x" : 787, "y" : 107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  31. /* 6 */ { "x" : 787, "y" : -107, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  32. /* 7 */ { "x" : 787, "y" : -385, "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea" },
  33.  
  34. /* 8 */ { "x" : 0, "y" : 106, "trait" : "kickOffBarrier", "curve" : -180 },
  35.  
  36. /* 9 */ { "x" : 0, "y" : -106, "trait" : "line", "curve" : -180 },
  37.  
  38. /* 10 */ { "x" : -874, "y" : -108, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  39. /* 11 */ { "x" : 856, "y" : -108, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  40. /* 12 */ { "x" : -874, "y" : 107, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  41. /* 13 */ { "x" : 856, "y" : 105, "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  42.  
  43. /* 14 */ { "x" : -787, "y" : -286, "trait" : "line" },
  44. /* 15 */ { "x" : -567, "y" : -50, "trait" : "line" },
  45. /* 16 */ { "x" : 787, "y" : -286, "trait" : "line" },
  46. /* 17 */ { "x" : 567, "y" : -50, "trait" : "line" },
  47. /* 18 */ { "x" : -787, "y" : 286, "trait" : "line" },
  48. /* 19 */ { "x" : -567, "y" : 50, "trait" : "line" },
  49. /* 20 */ { "x" : 787, "y" : 286, "trait" : "line" },
  50. /* 21 */ { "x" : 567, "y" : 50, "trait" : "line" },
  51.  
  52. /* 22 */ { "x" : 787, "y" : 386, "bCoef" : 1, "trait" : "ballArea" },
  53. /* 23 */ { "x" : 787, "y" : -385, "bCoef" : 1, "trait" : "ballArea" },
  54.  
  55. /* 24 */ { "x" : 0, "y" : 386, "bCoef" : 0, "trait" : "line" },
  56. /* 25 */ { "x" : 0, "y" : -385, "bCoef" : 0, "trait" : "line" },
  57.  
  58. /* 26 */ { "x" : 0, "y" : 106, "trait" : "kickOffBarrier" },
  59. /* 27 */ { "x" : 0, "y" : -106, "trait" : "kickOffBarrier" },
  60.  
  61. /* 28 */ { "x" : 896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  62. /* 29 */ { "x" : 896, "y" : 110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  63. /* 30 */ { "x" : 896, "y" : -394, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  64. /* 31 */ { "x" : 896, "y" : -110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  65. /* 32 */ { "x" : -896, "y" : 110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  66. /* 33 */ { "x" : -896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  67. /* 34 */ { "x" : -896, "y" : -395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  68. /* 35 */ { "x" : -896, "y" : -110, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  69.  
  70. /* 36 */ { "x" : 0, "y" : 401, "bCoef" : 0.1, "cMask" : ["red","blue" ], "trait" : "kickOffBarrier" },
  71. /* 37 */ { "x" : 0, "y" : 106, "bCoef" : 0.1, "cMask" : ["red","blue" ], "trait" : "kickOffBarrier" },
  72. /* 38 */ { "x" : 0, "y" : -401, "bCoef" : 0.1, "cMask" : ["red","blue" ], "cGroup" : ["redKO","blueKO" ], "trait" : "kickOffBarrier" },
  73. /* 39 */ { "x" : 0, "y" : -106, "bCoef" : 0.1, "cMask" : ["red","blue" ], "cGroup" : ["redKO","blueKO" ], "trait" : "kickOffBarrier" },
  74.  
  75. /* 40 */ { "x" : -896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  76. /* 41 */ { "x" : 896, "y" : 395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  77. /* 42 */ { "x" : -896, "y" : -395, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" },
  78. /* 43 */ { "x" : 896, "y" : -394, "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "color" : "000000" }
  79.  
  80. ],
  81.  
  82. "segments" : [
  83. { "v0" : 0, "v1" : 1, "trait" : "ballArea" },
  84. { "v0" : 2, "v1" : 3, "trait" : "ballArea" },
  85. { "v0" : 4, "v1" : 5, "trait" : "ballArea" },
  86. { "v0" : 6, "v1" : 7, "trait" : "ballArea" },
  87.  
  88. { "v0" : 8, "v1" : 9, "curve" : 180, "cGroup" : ["blueKO" ], "trait" : "kickOffBarrier" },
  89. { "v0" : 8, "v1" : 9, "curve" : -180, "cGroup" : ["redKO" ], "trait" : "kickOffBarrier" },
  90.  
  91. { "v0" : 2, "v1" : 10, "curve" : -3.819298738904888, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  92. { "v0" : 6, "v1" : 11, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  93. { "v0" : 1, "v1" : 12, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  94. { "v0" : 5, "v1" : 13, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet" },
  95. { "v0" : 10, "v1" : 12, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet", "x" : -915 },
  96. { "v0" : 11, "v1" : 13, "curve" : 1.0512692129152263, "vis" : true, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["ball" ], "trait" : "goalNet", "x" : 585 },
  97.  
  98. { "v0" : 14, "v1" : 15, "curve" : 90, "color" : "FFFFFF", "trait" : "line" },
  99. { "v0" : 16, "v1" : 17, "curve" : -90, "color" : "FFFFFF", "trait" : "line" },
  100. { "v0" : 18, "v1" : 19, "curve" : -90, "color" : "FFFFFF", "trait" : "line" },
  101. { "v0" : 20, "v1" : 21, "curve" : 90, "color" : "FFFFFF", "trait" : "line" },
  102. { "v0" : 15, "v1" : 19, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
  103. { "v0" : 17, "v1" : 21, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line", "x" : 667 },
  104.  
  105. { "v0" : 1, "v1" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : -665 },
  106. { "v0" : 5, "v1" : 4, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : 665 },
  107. { "v0" : 2, "v1" : 3, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : -665 },
  108. { "v0" : 6, "v1" : 7, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "cMask" : ["ball" ], "trait" : "ballArea", "x" : 665 },
  109. { "v0" : 0, "v1" : 22, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "trait" : "ballArea", "y" : 290 },
  110. { "v0" : 3, "v1" : 23, "vis" : true, "color" : "FFFFFF", "bCoef" : 1, "trait" : "ballArea", "y" : -290 },
  111.  
  112. { "v0" : 24, "v1" : 25, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
  113. { "v0" : 9, "v1" : 8, "curve" : -180, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
  114. { "v0" : 27, "v1" : 26, "curve" : 180, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
  115. { "v0" : 2, "v1" : 1, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line", "x" : -887 },
  116. { "v0" : 6, "v1" : 5, "curve" : 0, "vis" : true, "color" : "FFFFFF", "bCoef" : 0, "trait" : "line" },
  117.  
  118. { "v0" : 28, "v1" : 29, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" },
  119. { "v0" : 30, "v1" : 31, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" },
  120. { "v0" : 32, "v1" : 33, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "x" : -896 },
  121. { "v0" : 34, "v1" : 35, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea", "x" : -896 },
  122.  
  123. { "v0" : 36, "v1" : 37, "vis" : false, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["red","blue" ], "trait" : "kickOffBarrier", "x" : 0 },
  124. { "v0" : 38, "v1" : 39, "vis" : false, "color" : "FFFFFF", "bCoef" : 0.1, "cMask" : ["red","blue" ], "cGroup" : ["redKO","blueKO" ], "trait" : "kickOffBarrier" },
  125.  
  126. { "v0" : 40, "v1" : 41, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" },
  127. { "v0" : 42, "v1" : 43, "vis" : false, "color" : "000000", "bCoef" : 1, "cMask" : ["ball" ], "cGroup" : ["all" ], "trait" : "ballArea" }
  128.  
  129. ],
  130.  
  131. "goals" : [
  132. { "p0" : [-788,-104 ], "p1" : [-786,102 ], "team" : "red" },
  133. { "p0" : [787,-100 ], "p1" : [787,101 ], "team" : "blue" }
  134.  
  135. ],
  136.  
  137. "discs" : [
  138. { "radius" : 6, "pos" : [-786,108 ], "color" : "FFFFFF", "trait" : "goalPost" },
  139. { "radius" : 6, "pos" : [-787,-107 ], "color" : "FFFFFF", "trait" : "goalPost" },
  140. { "radius" : 6, "pos" : [787.00002288818,108 ], "color" : "FFFFFF", "trait" : "goalPost" },
  141. { "radius" : 6, "pos" : [786.00002288818,-107 ], "color" : "FFFFFF", "trait" : "goalPost" }
  142.  
  143. ],
  144.  
  145. "planes" : [
  146. { "normal" : [1,0 ], "dist" : -1001, "bCoef" : 1 },
  147. { "normal" : [-0.99998232014678,-0.0059463765320919 ], "dist" : -1009.0178392873, "bCoef" : 1 },
  148. { "normal" : [0,1 ], "dist" : -449, "bCoef" : 1 },
  149. { "normal" : [0,-1 ], "dist" : -455, "bCoef" : 1 }
  150.  
  151. ],
  152.  
  153. "traits" : {
  154. "ballArea" : { "vis" : false, "bCoef" : 1, "cMask" : ["ball" ] },
  155. "goalPost" : { "radius" : 8, "invMass" : 0, "bCoef" : 1 },
  156. "goalNet" : { "vis" : true, "bCoef" : 0.1, "cMask" : ["all" ] },
  157. "kickOffBarrier" : { "vis" : false, "bCoef" : 0.1, "cGroup" : ["redKO","blueKO" ], "cMask" : ["red","blue" ] },
  158. "line" : { "vis" : true, "bCoef" : 0, "cMask" : ["" ] },
  159. "arco" : { "radius" : 2, "cMask" : ["n/d" ], "color" : "cccccc" }
  160.  
  161. },
  162.  
  163. "playerPhysics" : {
  164. "acceleration" : 0.11,
  165. "kickingAcceleration" : 0.1,
  166. "kickStrength" : 6.5
  167.  
  168. },
  169.  
  170. "ballPhysics" : {
  171. "radius" : 6.4,
  172. "color" : "EAFF00"
  173.  
  174. }
  175. }`;
  176. room.setCustomStadium(futsal);
  177. room.setScoreLimit(3);
  178. room.setTimeLimit(5);
  179.  
  180.  
  181. /*
  182. Functions
  183. */
  184. // If there are no admins left in the room give admin to one of the remaining players.
  185. function updateAdmins() {
  186. // Get all players except the host (id = 0 is always the host)
  187. var players = room.getPlayerList().filter((player) => player.id != 0 );
  188. if ( players.length == 0 ) return; // No players left, do nothing.
  189. if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  190. room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  191. }
  192.  
  193. function initPlayerStats(player){
  194. if (stats.get(player.name)) return;
  195. stats.set(player.name, [0, 0, 0, 0, 0, 0]) // goals, assists, wins, loses, og, cs
  196. }
  197.  
  198.  
  199.  
  200. /*
  201. for commands
  202. */
  203.  
  204. function swapFun(player){
  205. if (player.admin == true){
  206. if (room.getScores() == null) {
  207. players = room.getPlayerList();
  208. for (i = 0; i < players.length; i++){
  209. if (players[i].team == 1){
  210. room.setPlayerTeam(players[i].id, 2);
  211. }
  212. else if (players[i].team == 2){
  213. room.setPlayerTeam(players[i].id, 1);
  214. }
  215. }
  216. }
  217. }
  218. }
  219.  
  220.  
  221. function pushMuteFun(player, message){ // !mute Anddy
  222. // Prevent somebody to talk in the room (uses the nickname, not the id)
  223. // need to be admin
  224. if (player.admin == true){
  225. if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
  226. }
  227. }
  228.  
  229.  
  230. function gotMutedFun(player){
  231. if (mutedPlayers.includes(player.name)){
  232. return true;
  233. }
  234. }
  235.  
  236. function unmuteFun(player, message){ // !unmute Anddy
  237. // Allow somebody to talk if he has been muted
  238. // need to be admin
  239. if (player.admin == true){
  240. pos = mutedPlayers.indexOf(message.substr(9));
  241. mutedPlayers.splice(pos, 1);
  242. }
  243. }
  244.  
  245. function adminFun(player, message){ // !admin Anddyisthebest
  246. // Gives admin to the person who type this password
  247.  
  248. room.setPlayerAdmin(player.id, true);
  249. return false; // The message won't be displayed
  250. }
  251.  
  252. function putPauseFun() { // p
  253. room.pauseGame(true);
  254. }
  255.  
  256. function unPauseFun() { // !p
  257. room.pauseGame(false);
  258. }
  259.  
  260. function helpFun() { // !help
  261. room.sendChat('Komendy: "p", "!p" , "!stats Nickname", "!ranking", "!poss", "!resetstats", "!adminhelp", "!gkhelp", "!rankhelp"');
  262. }
  263.  
  264. function adminHelpFun() {
  265. room.sendChat('Komendy: "!mute Player", "!unmute Player", ' +
  266. '"!clearbans", "!rr", "!swap" ')
  267. }
  268.  
  269.  
  270. function gkHelpFun() { // !gkhelp
  271. room.sendChat('Gracz najbliższy własnej bramki zostaje uznany bramkarzem).')
  272. }
  273. function rankHelpFun() { // !gkhelp
  274. room.sendChat("Zdobądź punkty! Gol: 1 pkt, Asysta: 1 pkt, Win: 1 pkt, cs: 1 pkt, Lose: -1 pkt, Og: -1 pkt.")
  275. }
  276.  
  277.  
  278. function statsFun(player, message){ // !stats Anddy
  279. if (stats.get(message.substr(7))){
  280. sendStats(message.substr(7));
  281. } else{ return false;}
  282. }
  283.  
  284. function rankFun() { // !ranking
  285. string = ranking();
  286. room.sendChat("Ranking: " + string);
  287. }
  288.  
  289. function resetStatsFun (player){ // !resetstats
  290. if (rankingCalc(player.name) > 0){
  291. stats.set(player.name, [0,0,0,0,0,0]);
  292. room.sendChat("Twoje statystyki zostały zresetowane! ")
  293. }
  294. else (room.sendChat("Musisz mieć pozytywny bilans."))
  295. }
  296.  
  297. function clearFun(player){ // !clear
  298. if (player.admin == true) room.clearBans();
  299. }
  300.  
  301. function resetFun(player){
  302. if (player.admin == true){
  303. room.stopGame();
  304. room.startGame();
  305. }
  306. }
  307.  
  308. function gkFun(player){ // !gk
  309.  
  310. if (room.getScores() != null && room.getScores().time < 60){
  311. if (player.team == 1) {
  312. gk[0] = player;
  313. }
  314. else if (player.team == 2){
  315. gk[1] = player;
  316. }
  317. }
  318. return;
  319. }
  320.  
  321.  
  322. function closeFun(player){
  323. if (player.name == "ADMIN CHUJ"){ // artificially generate an error in order to close the room
  324. stats.crash();
  325. }
  326. }
  327.  
  328.  
  329.  
  330. /*
  331. For ranking
  332. */
  333.  
  334. function rankingCalc(player){
  335. return stats.get(player)[0] * 1 + stats.get(player)[1] * 1 +
  336. stats.get(player)[2] * 1 + stats.get(player)[5] * 1 -
  337. stats.get(player)[3] * 1 - stats.get(player)[4] * 1;
  338. }
  339.  
  340. function ranking(){
  341.  
  342. var overall = [];
  343. players = Array.from(stats.keys());
  344. for (var i = 2; i < players.length; i++) {
  345. score = rankingCalc(players[i])
  346. // Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts
  347. overall.push({name: players[i], value: score});
  348. }
  349. overall.sort(function(a,b){
  350. return b.value - a.value;
  351. })
  352. string = "";
  353.  
  354. for (var i = 0; i < overall.length; i++) {
  355. if (overall[i].value != 0){
  356. string += i+1 + ") " + overall[i].name + ": " + overall[i].value + " pts, ";
  357. }
  358. }
  359. return string;
  360. }
  361.  
  362. function sendStats(name){
  363. ps = stats.get(name); // stands for playerstats
  364. room.sendChat(name + ": Gole: " + ps[0] + ", Asysty: " + ps[1]
  365. + ", Samobóje: " + ps[4] + ", Czyste konta: " + ps[5] + ", Wygrane: " + ps[2] + ", Przegrane: " + ps[3] +
  366. " Punkty: " + rankingCalc(name));
  367. }
  368.  
  369.  
  370. function whichTeam(){ // gives the players in the red or blue team
  371. var players = room.getPlayerList();
  372. var redTeam = players.filter(player => player.team == 1);
  373. var blueTeam = players.filter(player => player.team == 2);
  374. return [redTeam, blueTeam]
  375. }
  376.  
  377.  
  378.  
  379. function isGk(){ // gives the mosts backward players before the first kickOff
  380. var players = room.getPlayerList();
  381. var min = players[0];
  382. min.position = {x: room.getBallPosition().x + 60}
  383. var max = min;
  384.  
  385. for (var i = 0; i < players.length; i++) {
  386. if (players[i].position != null){
  387. if (min.position.x > players[i].position.x) min = players[i];
  388. if (max.position.x < players[i].position.x) max = players[i];
  389. }
  390. }
  391. return [min, max]
  392. }
  393.  
  394.  
  395.  
  396.  
  397.  
  398. function updateWinLoseStats(winners, losers){
  399. for (var i = 0; i < winners.length; i++) {
  400. stats.get(winners[i].name)[2] += 1;
  401. }
  402. for (var i = 0; i < losers.length; i++) {
  403. stats.get(losers[i].name)[3] += 1;
  404. }
  405. }
  406.  
  407. function initBallCarrying(redTeam, blueTeam){
  408. var ballCarrying = new Map();
  409. var playing = redTeam.concat(blueTeam);
  410. for (var i = 0; i < playing.length; i++) {
  411. ballCarrying.set(playing[i].name, [0, playing[i].team]); // secs, team, %
  412. }
  413. return ballCarrying;
  414. }
  415.  
  416.  
  417.  
  418. function updateTeamPoss(value){
  419. if (value[1] == 1) redPoss += value[0];
  420. if (value[1] == 2) bluePoss += value[0];
  421. }
  422.  
  423. var bluePoss;
  424. var redPoss;
  425. function teamPossFun(){
  426. if (room.getScores() == null) return false;
  427. bluePoss = 0;
  428. redPoss = 0
  429. ballCarrying.forEach(updateTeamPoss);
  430. redPoss = Math.round((redPoss / room.getScores().time) * 100);
  431. bluePoss = Math.round((bluePoss / room.getScores().time) * 100);
  432. room.sendChat("Posiadanie piłki: RED " + redPoss + "% - BLUE " + bluePoss + "% " );
  433.  
  434. }
  435.  
  436.  
  437.  
  438. /*
  439. For the game
  440. */
  441.  
  442. // Gives the last player who touched the ball, works only if the ball has the same
  443. // size than in classics maps.
  444. var radiusBall = 10;
  445. var triggerDistance = radiusBall + 15 + 0.1;
  446. function getLastTouchTheBall(lastPlayerTouched, time) {
  447. var ballPosition = room.getBallPosition();
  448. var players = room.getPlayerList();
  449. for(var i = 0; i < players.length; i++) {
  450. if(players[i].position != null) {
  451. var distanceToBall = pointDistance(players[i].position, ballPosition);
  452. if(distanceToBall < triggerDistance) {
  453. lastPlayerTouched = players[i];
  454. return lastPlayerTouched;
  455. }
  456. }
  457. }
  458. return lastPlayerTouched;
  459.  
  460. }
  461.  
  462.  
  463.  
  464. // Calculate the distance between 2 points
  465. function pointDistance(p1, p2) {
  466. var d1 = p1.x - p2.x;
  467. var d2 = p1.y - p2.y;
  468. return Math.sqrt(d1 * d1 + d2 * d2);
  469. }
  470.  
  471. function isOvertime(){
  472. scores = room.getScores();
  473. if (scores != null){
  474. if (scores.timeLimit != 0){
  475. if (scores.time > scores.timeLimit){
  476. if (scores.red == 0 && hasFinished == false){
  477. stats.get(gk[0].name)[5] += 1;
  478. stats.get(gk[1].name)[5] += 1;
  479. hasFinished = true;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. // return: the name of the team who took a goal
  486. var team_name = team => team == 1 ? "Blue" : "Red";
  487.  
  488. // return: whether it's an OG
  489. var isOwnGoal = (team, player) => team != player.team ? " (samobój)" : "";
  490.  
  491. // return: a better display of the second when a goal is scored
  492. var floor = s => s < 10 ? "0" + s : s;
  493.  
  494. // return: whether there's an assist
  495. var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (Asysta: " + playerList[1].name + ")" : "";
  496.  
  497.  
  498.  
  499. /*
  500. Events
  501. */
  502. var stats = new Map(); // map where will be set all player stats
  503. var mutedPlayers = []; // Array where will be added muted players
  504. var init = "init"; // Smth to initialize smth
  505. init.id = 0; // Faster than getting host's id with the method
  506. init.name = "init";
  507. var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
  508. var whoTouchedLast; // var representing the last player who touched the ball
  509. var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
  510. var gk = [init, init];
  511. var goalScored = false;
  512.  
  513. var commands = {
  514. // Command that doesnt need to know players attributes.
  515. "!help": helpFun,
  516. "!gkhelp": gkHelpFun,
  517. "!adminhelp": adminHelpFun,
  518. "!rankhelp": rankHelpFun,
  519. "!ranking": rankFun,
  520. "p": putPauseFun,
  521. "!p": unPauseFun,
  522. "!poss": teamPossFun,
  523.  
  524. // Command that need to know who is the player.
  525. "!resetstats": resetStatsFun,
  526. "!gk": gkFun,
  527. "!bettingexpert": adminFun,
  528.  
  529. // Command that need to know if a player is admin.
  530. "!swap": swapFun,
  531. "!rr": resetFun,
  532. "!clear": clearFun,
  533. "!close": closeFun,
  534.  
  535. // Command that need to know what's the message.
  536. "!stats": statsFun,
  537.  
  538. // Command that need to know who is the player and what's the message.
  539. "!mute" : pushMuteFun,
  540. "!unmute": unmuteFun
  541.  
  542. }
  543.  
  544. initPlayerStats(room.getPlayerList()[0]) // lazy lol, i'll fix it later
  545. initPlayerStats(init);
  546.  
  547. room.onPlayerLeave = function(player) {
  548. updateAdmins();
  549. }
  550.  
  551.  
  552.  
  553. room.onPlayerJoin = function(player) {
  554. updateAdmins(); // Gives admin to the first player who join the room if there's no one
  555. initPlayerStats(player); // Set new player's stat
  556. room.sendChat("Witaj " + player.name + " ! Komendy: !help, !adminhelp, !rankhelp o !gkhelp" )
  557. }
  558.  
  559. var redTeam;
  560. var blueTeam;
  561. room.onGameStart = function() {
  562. [redTeam,blueTeam] = whichTeam();
  563. ballCarrying = initBallCarrying(redTeam, blueTeam);
  564. }
  565.  
  566. room.onPlayerTeamChange = function(player){
  567. if (room.getScores() != null){
  568. if (1 <= player.team <= 2) ballCarrying.set(player.name, [0, player.team]);
  569. }
  570. }
  571.  
  572.  
  573.  
  574. room.onPlayerChat = function(player, message) {
  575. if (mutedPlayers.includes(player.name)) return false;
  576. let spacePos = message.search(" ");
  577. let command = message.substr(0, spacePos !== -1 ? spacePos : message.length);
  578. if (commands.hasOwnProperty(command) == true) return commands[command](player, message);
  579.  
  580. }
  581.  
  582.  
  583.  
  584.  
  585. room.onPlayerBallKick = function (player){
  586. whoTouchedLast = player;
  587. }
  588.  
  589. var kickOff = false;
  590. var hasFinished = false;
  591.  
  592. room.onGameTick = function() {
  593.  
  594. setInterval(isOvertime, 5000, hasFinished);
  595.  
  596. if (kickOff == false) { // simplest comparison to not charge usulessly the tick thing
  597. if (room.getScores().time != 0){
  598. kickOff = true;
  599. gk = isGk();
  600. room.sendChat("GK RED: " + gk[0].name + ", GK BLUE: " + gk[1].name)
  601. }
  602. }
  603. if (goalScored == false){
  604. whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
  605. }
  606. if (whoTouchedLast != undefined) {
  607.  
  608. if (ballCarrying.get(whoTouchedLast.name)) {
  609. ballCarrying.get(whoTouchedLast.name)[0] += 1/60;
  610. }
  611.  
  612. if ( whoTouchedLast.id != whoTouchedBall[0].id){
  613. whoTouchedBall[1] = whoTouchedBall[0];
  614. whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
  615. }
  616. }
  617. }
  618.  
  619. room.onTeamGoal = function(team){ // Write on chat who scored and when.
  620.  
  621. goalScored = true;
  622. var time = room.getScores().time;
  623. var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
  624. time = m + ":" + floor(s); // MM:SS format
  625. var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
  626. var assist = "";
  627. if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
  628.  
  629.  
  630. room.sendChat("GOL! Strzelcem " + whoTouchedBall[0].name +
  631. assist + ownGoal + " w " +
  632. time + " do bramki " + team_name(team));
  633.  
  634. if (ownGoal != "") {
  635. stats.get(whoTouchedBall[0].name)[4] += 1;
  636. } else {
  637. stats.get(whoTouchedBall[0].name)[0] += 1;
  638. }
  639.  
  640. if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].name)[1] += 1;
  641.  
  642.  
  643. if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
  644. scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
  645. whoTouchedBall = [init, init];
  646. whoTouchedLast = undefined;
  647. }
  648.  
  649. room.onPositionsReset = function(){
  650. goalScored = false;
  651. }
  652.  
  653. room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
  654. if (scores.blue == 0 && gk[0].position != null && hasFinished == false) stats.get(gk[0].name)[5] += 1;
  655. if (scores.red == 0 && gk[1].position != null && hasFinished == false) stats.get(gk[1].name)[5] += 1;
  656. if (scores.red > scores.blue) {
  657. updateWinLoseStats(redTeam, blueTeam);
  658. }
  659. else{ updateWinLoseStats(blueTeam, redTeam); }
  660.  
  661. room.sendChat("Gole:")
  662. for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
  663. room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
  664. }
  665. teamPossFun();
  666. }
  667.  
  668. room.onGameStop = function(){
  669. scorers = undefined;
  670. whoTouchedBall = [init, init];
  671. whoTouchedLast = undefined;
  672. gk = [init, init];
  673. kickOff = false;
  674. hasFinished = false;
  675. }
  676.  
  677. room.onStadiumChange = function(newStadiumName, byPlayer) {
  678. if (newStadiumName != "Futsal 4x4") {
  679. room.setCustomStadium(futsal);
  680. }
  681. }
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688. // Made by Grandes Ligas HaxBall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement