SHARE
TWEET

kutass

a guest May 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 BEZRANKINGU.PL", maxPlayers: 14, playerName : "BANDZIOREK", public : true});
  12. var futsal = `{"name":"fut4/q","width":790,"height":480,"bg":{"type":"hockey","width":700,"height":430,"kickOffRadius":100},"vertexes":[{"x":-700,"y":430,"cMask":["ball"]},{"x":-700,"y":115,"cMask":["ball"]},{"x":-700,"y":-115},{"x":-700,"y":-430,"cMask":["ball"]},{"x":700,"y":430,"cMask":["ball"]},{"x":700,"y":115,"cMask":["ball"]},{"x":700,"y":-115,"cMask":["ball"]},{"x":700,"y":-430,"cMask":["ball"]},{"x":0,"y":446,"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"x":0,"y":100,"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"x":0,"y":-100,"bCoef":0,"cMask":[]},{"x":0,"y":-446,"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"x":-740,"y":-105,"bCoef":0.1},{"x":-700,"y":-240,"bCoef":0,"cMask":[]},{"x":-500,"y":-50,"bCoef":0,"cMask":[]},{"x":700,"y":-240,"bCoef":0,"cMask":[]},{"x":500,"y":-50,"bCoef":0,"cMask":[]},{"x":-700,"y":240,"bCoef":0,"cMask":[]},{"x":-500,"y":50,"bCoef":0,"cMask":[]},{"x":700,"y":240,"bCoef":0,"cMask":[]},{"x":500,"y":50,"bCoef":0,"cMask":[]},{"x":700,"y":430,"cMask":["ball"]},{"x":700,"y":-430,"cMask":["ball"]},{"x":0,"y":430,"bCoef":0,"cMask":[]},{"x":0,"y":-430,"bCoef":0,"cMask":[]},{"x":0,"y":100,"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"x":0,"y":-100,"bCoef":0.1,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"x":709,"y":-115,"cMask":["ball"]},{"x":709,"y":-430,"cMask":["ball"]},{"x":-709,"y":-115,"cMask":["ball"]},{"x":-709,"y":-430,"cMask":["ball"]},{"x":-709,"y":115,"cMask":["ball"]},{"x":-709,"y":430,"cMask":["ball"]},{"x":709,"y":115,"cMask":["ball"]},{"x":709,"y":430,"cMask":["ball"]},{"x":-700,"y":115},{"x":-740,"y":105,"bCoef":0.1},{"x":-740,"y":-105,"bCoef":0.1},{"x":-750,"y":-15,"bCoef":0.1},{"x":-750,"y":-15,"bCoef":0.1,"cMask":["blue","ball"]},{"x":-750,"y":15,"bCoef":0.1,"cMask":["blue","ball"]},{"x":-750,"y":15,"bCoef":0.1},{"x":-740,"y":105,"bCoef":0.1},{"x":750,"y":-15,"bCoef":0.1,"cMask":["red","ball"]},{"x":750,"y":15,"bCoef":0.1,"cMask":["red","ball"]},{"x":740,"y":105},{"x":700,"y":115,"bCoef":0.1},{"x":740,"y":-105},{"x":700,"y":-115,"bCoef":0.1},{"x":750,"y":-15,"bCoef":0.1},{"x":740,"y":-105,"bCoef":0.1},{"x":740,"y":105,"bCoef":0.1},{"x":750,"y":15,"bCoef":0.1}],"segments":[{"v0":0,"v1":1,"vis":false,"cMask":["ball"]},{"v0":2,"v1":3,"vis":false,"cMask":["ball"]},{"v0":4,"v1":5,"vis":false,"cMask":["ball"]},{"v0":6,"v1":7,"vis":false,"cMask":["ball"]},{"v0":8,"v1":9,"bCoef":0.1,"vis":false,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"v0":9,"v1":10,"bCoef":0.1,"curve":180,"curveF":6.123233995736766e-17,"vis":false,"cMask":["red","blue"],"cGroup":["blueKO"]},{"v0":10,"v1":9,"bCoef":0.1,"curve":180,"curveF":6.123233995736766e-17,"vis":false,"cMask":["red","blue"],"cGroup":["redKO"]},{"v0":10,"v1":11,"bCoef":0.1,"vis":false,"cMask":["red","blue"],"cGroup":["redKO","blueKO"]},{"v0":12,"v1":2,"bCoef":0.1,"curve":35,"curveF":3.1715948023632126,"color":"FFFFFF"},{"v0":13,"v1":14,"bCoef":0,"curve":85,"curveF":1.0913085010692714,"cMask":[],"color":"FFFFFF"},{"v0":16,"v1":15,"bCoef":0,"curve":85,"curveF":1.0913085010692714,"cMask":[],"color":"FFFFFF"},{"v0":18,"v1":17,"bCoef":0,"curve":85,"curveF":1.0913085010692714,"cMask":[],"color":"FFFFFF"},{"v0":19,"v1":20,"bCoef":0,"curve":85,"curveF":1.0913085010692714,"cMask":[],"color":"FFFFFF"},{"v0":14,"v1":18,"bCoef":0,"cMask":[],"color":"FFFFFF"},{"v0":16,"v1":20,"bCoef":0,"cMask":[],"color":"FFFFFF"},{"v0":1,"v1":0,"cMask":["ball"],"color":"FFFFFF"},{"v0":5,"v1":4,"cMask":["ball"],"color":"FFFFFF"},{"v0":2,"v1":3,"cMask":["ball"],"color":"FFFFFF"},{"v0":6,"v1":7,"cMask":["ball"],"color":"FFFFFF"},{"v0":0,"v1":21,"cMask":["ball"],"color":"FFFFFF"},{"v0":3,"v1":22,"cMask":["ball"],"color":"FFFFFF"},{"v0":23,"v1":24,"bCoef":0,"cMask":[],"color":"FFFFFF"},{"v0":9,"v1":10,"bCoef":0,"curve":180,"curveF":6.123233995736766e-17,"cMask":[],"color":"FFFFFF"},{"v0":26,"v1":25,"bCoef":0,"curve":180,"curveF":6.123233995736766e-17,"cMask":[],"color":"FFFFFF"},{"v0":2,"v1":1,"bCoef":0,"cMask":[],"color":"FFFFFF"},{"v0":6,"v1":5,"bCoef":0,"cMask":[],"color":"FFFFFF"},{"v0":27,"v1":28,"vis":false,"cMask":["ball"],"color":"FFFFFF"},{"v0":29,"v1":30,"vis":false,"cMask":["ball"],"color":"FFFFFF"},{"v0":31,"v1":32,"vis":false,"cMask":["ball"],"color":"FFFFFF"},{"v0":33,"v1":34,"vis":false,"cMask":["ball"],"color":"FFFFFF"},{"v0":35,"v1":36,"bCoef":0.1,"curve":35,"curveF":3.1715948023632126,"color":"FFFFFF"},{"v0":38,"v1":37,"bCoef":0.1,"curve":10,"curveF":11.430052302761343,"color":"FFFFFF"},{"v0":39,"v1":40,"bCoef":0.1,"cMask":["blue","ball"],"color":"CCCCCC"},{"v0":42,"v1":41,"bCoef":0.1,"curve":10,"curveF":11.430052302761343,"color":"FFFFFF"},{"v0":43,"v1":44,"bCoef":0.1,"cMask":["red","ball"],"color":"CCCCCC"},{"v0":45,"v1":46,"bCoef":0.1,"curve":35,"curveF":3.1715948023632126,"color":"FFFFFF"},{"v0":48,"v1":47,"bCoef":0.1,"curve":35,"curveF":3.1715948023632126,"color":"FFFFFF"},{"v0":50,"v1":49,"bCoef":0.1,"curve":10,"curveF":11.430052302761343,"color":"FFFFFF"},{"v0":52,"v1":51,"bCoef":0.1,"curve":10,"curveF":11.430052302761343,"color":"FFFFFF"}],"planes":[{"normal":[0,1],"dist":-430,"cMask":["ball"]},{"normal":[0,-1],"dist":-430,"cMask":["ball"]},{"normal":[0,1],"dist":-479,"bCoef":0.2},{"normal":[0,-1],"dist":-479,"bCoef":0.2},{"normal":[1,0],"dist":-790,"bCoef":0.2},{"normal":[-1,0],"dist":-790,"bCoef":0.2}],"goals":[{"p0":[-709,-115],"p1":[-709,115],"team":"red"},{"p0":[709,115],"p1":[709,-115],"team":"blue"}],"discs":[{"pos":[-700,115],"radius":5,"bCoef":1,"invMass":0},{"pos":[-700,-115],"radius":5,"bCoef":1,"invMass":0},{"pos":[700,115],"radius":5,"bCoef":1,"invMass":0},{"pos":[700,-115],"radius":5,"bCoef":1,"invMass":0}],"playerPhysics":{"acceleration":0.105,"kickingAcceleration":0.075,"kickStrength":6},"ballPhysics":{"radius":6.4},"spawnDistance":225}`;
  13. room.setCustomStadium(futsal);
  14. room.setScoreLimit(3);
  15. room.setTimeLimit(5);
  16.  
  17.  
  18. /*
  19.     Functions
  20. */
  21. // If there are no admins left in the room give admin to one of the remaining players.
  22. function updateAdmins() {
  23.   // Get all players except the host (id = 0 is always the host)
  24.   var players = room.getPlayerList().filter((player) => player.id != 0 );
  25.   if ( players.length == 0 ) return; // No players left, do nothing.
  26.   if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  27.   room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  28. }
  29.  
  30. function initPlayerStats(player){
  31.     if (stats.get(player.name)) return;
  32.     stats.set(player.name, [0, 0, 0, 0, 0, 0]) // goals, assists, wins, loses, og, cs
  33. }
  34.  
  35.  
  36.  
  37. /*
  38. for commands
  39. */
  40.  
  41. function swapFun(player){
  42.     if (player.admin == true){
  43.         if (room.getScores() == null) {
  44.             players = room.getPlayerList();
  45.             for (i = 0; i < players.length; i++){
  46.                 if (players[i].team == 1){
  47.                     room.setPlayerTeam(players[i].id, 2);
  48.                 }
  49.                 else if (players[i].team == 2){
  50.                     room.setPlayerTeam(players[i].id, 1);
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58. function pushMuteFun(player, message){ // !mute Anddy
  59.     // Prevent somebody to talk in the room (uses the nickname, not the id)
  60.     // need to be admin
  61.     if (player.admin == true){
  62.         if (!(mutedPlayers.includes(message.substr(6)))) mutedPlayers.push(message.substr(6));
  63.     }
  64. }
  65.  
  66.  
  67. function gotMutedFun(player){
  68.     if (mutedPlayers.includes(player.name)){
  69.         return true;
  70.     }
  71. }
  72.  
  73. function unmuteFun(player, message){ // !unmute Anddy
  74.     // Allow somebody to talk if he has been muted
  75.     // need to be admin
  76.     if (player.admin == true){
  77.         pos = mutedPlayers.indexOf(message.substr(9));
  78.         mutedPlayers.splice(pos, 1);
  79.     }
  80. }
  81.  
  82. function adminFun(player, message){ // !admin Anddyisthebest
  83.     // Gives admin to the person who type this password
  84.  
  85.     room.setPlayerAdmin(player.id, true);
  86.     return false; // The message won't be displayed
  87. }
  88.  
  89. function putPauseFun() { // p
  90.     room.pauseGame(true);
  91. }
  92.  
  93. function unPauseFun() { // !p
  94.     room.pauseGame(false);
  95. }
  96.  
  97. function helpFun() { // !help
  98.     room.sendChat('Komendy: "p", "!p" , "!stats Nickname", "!ranking", "!poss", "!resetstats", "!adminhelp", "!gkhelp", "!rankhelp"');
  99. }
  100.  
  101. function adminHelpFun() {
  102.     room.sendChat('Komendy: "!mute Player", "!unmute Player", ' +
  103.     '"!clearbans", "!rr", "!swap" ')
  104. }
  105.  
  106.  
  107. function gkHelpFun() { // !gkhelp
  108.     room.sendChat('Gracz najbliższy własnej bramki zostaje uznany bramkarzem).')
  109. }
  110. function rankHelpFun() { // !gkhelp
  111.     room.sendChat("Zdobądź punkty! Gol: 1 pkt, Asysta: 1 pkt, Win: 1 pkt, cs: 1 pkt, Lose: -1 pkt, Og: -1 pkt.")
  112. }
  113.  
  114.  
  115. function statsFun(player, message){ // !stats Anddy
  116.     if (stats.get(message.substr(7))){
  117.         sendStats(message.substr(7));
  118.     } else{ return false;}
  119. }
  120.  
  121. function rankFun() { // !ranking
  122.     string = ranking();
  123.     room.sendChat("Ranking: " + string);
  124. }
  125.  
  126. function resetStatsFun (player){ // !resetstats
  127.     if (rankingCalc(player.name) > 0){
  128.         stats.set(player.name, [0,0,0,0,0,0]);
  129.         room.sendChat("Twoje statystyki zostały zresetowane! ")
  130.     }
  131.     else (room.sendChat("Musisz mieć pozytywny bilans."))
  132. }
  133.  
  134. function clearFun(player){ // !clear
  135.     if (player.admin == true) room.clearBans();
  136. }
  137.  
  138. function resetFun(player){
  139.     if (player.admin == true){
  140.         room.stopGame();
  141.         room.startGame();
  142.     }
  143. }
  144.  
  145. function gkFun(player){ // !gk
  146.  
  147.     if (room.getScores() != null && room.getScores().time < 60){
  148.         if (player.team == 1) {
  149.             gk[0] = player;
  150.         }
  151.         else if (player.team == 2){
  152.             gk[1] = player;
  153.         }
  154.     }
  155.     return;
  156. }
  157.  
  158.  
  159. function closeFun(player){
  160.     if (player.name == "ADMIN CHUJ"){ // artificially generate an error in order to close the room
  161.         stats.crash();
  162.     }
  163. }
  164.  
  165.  
  166.  
  167. /*
  168.     For ranking
  169. */
  170.  
  171. function rankingCalc(player){
  172.     return stats.get(player)[0] * 1 + stats.get(player)[1] * 1 +
  173.             stats.get(player)[2] * 1 + stats.get(player)[5] * 1 -
  174.             stats.get(player)[3] * 1 - stats.get(player)[4] * 1;
  175. }
  176.  
  177. function ranking(){
  178.  
  179.     var overall = [];
  180.     players = Array.from(stats.keys());
  181.     for (var i = 2; i < players.length; i++) {
  182.         score = rankingCalc(players[i])
  183.         // Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts
  184.         overall.push({name: players[i], value: score});
  185.     }
  186.     overall.sort(function(a,b){
  187.         return b.value - a.value;
  188.     })
  189.     string = "";
  190.  
  191.     for (var i = 0; i < overall.length; i++) {
  192.         if (overall[i].value != 0){
  193.             string += i+1 + ") " + overall[i].name + ": " + overall[i].value + " pts, ";
  194.         }
  195.     }
  196.     return string;
  197. }
  198.  
  199. function sendStats(name){
  200.     ps = stats.get(name); // stands for playerstats
  201.     room.sendChat(name + ": Gole: " + ps[0] + ", Asysty: " + ps[1]
  202.     + ", Samobóje: " + ps[4] + ", Czyste konta: " + ps[5] + ", Wygrane: " + ps[2] + ", Przegrane: " + ps[3] +
  203.     " Punkty: " + rankingCalc(name));
  204. }
  205.  
  206.  
  207. function whichTeam(){ // gives the players in the red or blue team
  208.     var players = room.getPlayerList();
  209.     var redTeam = players.filter(player => player.team == 1);
  210.     var blueTeam = players.filter(player => player.team == 2);
  211.     return [redTeam, blueTeam]
  212. }
  213.  
  214.  
  215.  
  216. function isGk(){ // gives the mosts backward players before the first kickOff
  217.     var players = room.getPlayerList();
  218.     var min = players[0];
  219.     min.position = {x: room.getBallPosition().x + 60}
  220.     var max = min;
  221.  
  222.     for (var i = 0; i < players.length; i++) {
  223.         if (players[i].position != null){
  224.             if (min.position.x > players[i].position.x) min = players[i];
  225.             if (max.position.x < players[i].position.x) max = players[i];
  226.         }
  227.     }
  228.     return [min, max]
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235. function updateWinLoseStats(winners, losers){
  236.     for (var i = 0; i < winners.length; i++) {
  237.         stats.get(winners[i].name)[2] += 1;
  238.     }
  239.     for (var i = 0; i < losers.length; i++) {
  240.         stats.get(losers[i].name)[3] += 1;
  241.     }
  242. }
  243.  
  244. function initBallCarrying(redTeam, blueTeam){
  245.     var ballCarrying = new Map();
  246.     var playing = redTeam.concat(blueTeam);
  247.     for (var i = 0; i < playing.length; i++) {
  248.         ballCarrying.set(playing[i].name, [0, playing[i].team]); // secs, team, %
  249.     }
  250.     return ballCarrying;
  251. }
  252.  
  253.  
  254.  
  255. function updateTeamPoss(value){
  256.     if (value[1] == 1) redPoss += value[0];
  257.     if (value[1] == 2) bluePoss += value[0];
  258. }
  259.  
  260. var bluePoss;
  261. var redPoss;
  262. function teamPossFun(){
  263.     if (room.getScores() == null) return false;
  264.     bluePoss = 0;
  265.     redPoss = 0
  266.     ballCarrying.forEach(updateTeamPoss);
  267.     redPoss = Math.round((redPoss / room.getScores().time) * 100);
  268.     bluePoss = Math.round((bluePoss / room.getScores().time) * 100);
  269.     room.sendChat("Posiadanie piłki:  RED " + redPoss + "% - BLUE " + bluePoss + "% "  );
  270.  
  271. }
  272.  
  273.  
  274.  
  275. /*
  276. For the game
  277. */
  278.  
  279. // Gives the last player who touched the ball, works only if the ball has the same
  280. // size than in classics maps.
  281. var radiusBall = 10;
  282. var triggerDistance = radiusBall + 15 + 0.1;
  283. function getLastTouchTheBall(lastPlayerTouched, time) {
  284.     var ballPosition = room.getBallPosition();
  285.     var players = room.getPlayerList();
  286.     for(var i = 0; i < players.length; i++) {
  287.         if(players[i].position != null) {
  288.             var distanceToBall = pointDistance(players[i].position, ballPosition);
  289.             if(distanceToBall < triggerDistance) {
  290.                 lastPlayerTouched = players[i];
  291.                 return lastPlayerTouched;
  292.             }
  293.         }
  294.     }
  295.     return lastPlayerTouched;
  296.  
  297. }
  298.  
  299.  
  300.  
  301. // Calculate the distance between 2 points
  302. function pointDistance(p1, p2) {
  303.     var d1 = p1.x - p2.x;
  304.     var d2 = p1.y - p2.y;
  305.     return Math.sqrt(d1 * d1 + d2 * d2);
  306. }
  307.  
  308. function isOvertime(){
  309.     scores = room.getScores();
  310.     if (scores != null){
  311.         if (scores.timeLimit != 0){
  312.             if (scores.time > scores.timeLimit){
  313.                 if (scores.red == 0 && hasFinished == false){
  314.                     stats.get(gk[0].name)[5] += 1;
  315.                     stats.get(gk[1].name)[5] += 1;
  316.                     hasFinished = true;
  317.                 }
  318.             }
  319.         }
  320.     }
  321. }
  322. // return: the name of the team who took a goal
  323. var team_name = team => team == 1 ? "Blue" : "Red";
  324.  
  325. // return: whether it's an OG
  326. var isOwnGoal = (team, player) => team != player.team ? " (samobój)" : "";
  327.  
  328. // return: a better display of the second when a goal is scored
  329. var floor = s => s < 10 ? "0" + s : s;
  330.  
  331. // return: whether there's an assist
  332. var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (Asysta: " + playerList[1].name + ")" : "";
  333.  
  334.  
  335.  
  336. /*
  337. Events
  338. */
  339. var stats = new Map(); // map where will be set all player stats
  340. var mutedPlayers = []; // Array where will be added muted players
  341. var init = "init"; // Smth to initialize smth
  342. init.id = 0; // Faster than getting host's id with the method
  343. init.name = "init";
  344. var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
  345. var whoTouchedLast; // var representing the last player who touched the ball
  346. var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
  347. var gk = [init, init];
  348. var goalScored = false;
  349.  
  350. var commands = {
  351.     // Command that doesnt need to know players attributes.
  352.     "!help": helpFun,
  353.     "!gkhelp": gkHelpFun,
  354.     "!adminhelp": adminHelpFun,
  355.     "!rankhelp": rankHelpFun,
  356.     "!ranking": rankFun,
  357.     "p": putPauseFun,
  358.     "!p": unPauseFun,
  359.     "!poss": teamPossFun,
  360.  
  361.     // Command that need to know who is the player.
  362.     "!resetstats": resetStatsFun,
  363.     "!gk": gkFun,
  364.     "!bettingexpert": adminFun,
  365.  
  366.     // Command that need to know if a player is admin.
  367.     "!swap": swapFun,
  368.     "!rr": resetFun,
  369.     "!clear": clearFun,
  370.     "!close": closeFun,
  371.  
  372.     // Command that need to know what's the message.
  373.     "!stats": statsFun,
  374.  
  375.     // Command that need to know who is the player and what's the message.
  376.     "!mute" : pushMuteFun,
  377.     "!unmute": unmuteFun
  378.  
  379. }
  380.  
  381. initPlayerStats(room.getPlayerList()[0]) // lazy lol, i'll fix it later
  382. initPlayerStats(init);
  383.  
  384. room.onPlayerLeave = function(player) {
  385.   updateAdmins();
  386. }
  387.  
  388.  
  389.  
  390. room.onPlayerJoin = function(player) {
  391.     updateAdmins(); // Gives admin to the first player who join the room if there's no one
  392.     initPlayerStats(player); // Set new player's stat
  393.     room.sendChat("Witaj " + player.name + " ! Komendy: !help, !adminhelp, !rankhelp o !gkhelp" )
  394. }
  395.  
  396. var redTeam;
  397. var blueTeam;
  398. room.onGameStart = function() {
  399.     [redTeam,blueTeam] = whichTeam();
  400.     ballCarrying = initBallCarrying(redTeam, blueTeam);
  401. }
  402.  
  403. room.onPlayerTeamChange = function(player){
  404.     if (room.getScores() != null){
  405.         if (1 <= player.team <= 2) ballCarrying.set(player.name, [0, player.team]);
  406.     }
  407. }
  408.  
  409.  
  410.  
  411. room.onPlayerChat = function(player, message) {
  412.     if (mutedPlayers.includes(player.name)) return false;
  413.     let spacePos = message.search(" ");
  414.     let command = message.substr(0, spacePos !== -1 ? spacePos : message.length);
  415.     if (commands.hasOwnProperty(command) == true) return commands[command](player, message);
  416.  
  417. }
  418.  
  419.  
  420.  
  421.  
  422. room.onPlayerBallKick = function (player){
  423.     whoTouchedLast = player;
  424. }
  425.  
  426. var kickOff = false;
  427. var hasFinished = false;
  428.  
  429. room.onGameTick = function() {
  430.  
  431.     setInterval(isOvertime, 5000, hasFinished);
  432.  
  433.     if (kickOff == false) { // simplest comparison to not charge usulessly the tick thing
  434.         if (room.getScores().time != 0){
  435.             kickOff = true;
  436.             gk = isGk();
  437.             room.sendChat("GK RED: " + gk[0].name + ", GK BLUE: " + gk[1].name)
  438.         }
  439.     }
  440.     if (goalScored == false){
  441.         whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
  442.     }
  443.     if (whoTouchedLast != undefined) {
  444.  
  445.         if (ballCarrying.get(whoTouchedLast.name)) {
  446.             ballCarrying.get(whoTouchedLast.name)[0] += 1/60;
  447.         }
  448.  
  449.         if  ( whoTouchedLast.id != whoTouchedBall[0].id){
  450.             whoTouchedBall[1] = whoTouchedBall[0];
  451.             whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
  452.         }
  453.     }
  454. }
  455.  
  456. room.onTeamGoal = function(team){ // Write on chat who scored and when.
  457.  
  458.     goalScored = true;
  459.     var time = room.getScores().time;
  460.     var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
  461.     time = m + ":" + floor(s); // MM:SS format
  462.     var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
  463.     var assist = "";
  464.     if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
  465.  
  466.  
  467.     room.sendChat("GOL! Strzelcem " + whoTouchedBall[0].name +
  468.      assist + ownGoal + " w " +
  469.      time + " do bramki " + team_name(team));
  470.  
  471.      if (ownGoal != "") {
  472.          stats.get(whoTouchedBall[0].name)[4] += 1;
  473.      } else {
  474.          stats.get(whoTouchedBall[0].name)[0] += 1;
  475.      }
  476.  
  477.     if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].name)[1] += 1;
  478.  
  479.  
  480.     if (scorers == undefined) scorers = new Map(); // Initializing dict of scorers
  481.     scorers.set(scorers.size + 1 +") " + whoTouchedLast.name, [time, assist, ownGoal])
  482.     whoTouchedBall = [init, init];
  483.     whoTouchedLast = undefined;
  484. }
  485.  
  486. room.onPositionsReset = function(){
  487.     goalScored = false;
  488. }
  489.  
  490. room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
  491.     if (scores.blue == 0 && gk[0].position != null && hasFinished == false) stats.get(gk[0].name)[5] += 1;
  492.     if (scores.red == 0 && gk[1].position != null  && hasFinished == false) stats.get(gk[1].name)[5] += 1;
  493.     if (scores.red > scores.blue) {
  494.         updateWinLoseStats(redTeam, blueTeam);
  495.     }
  496.     else{ updateWinLoseStats(blueTeam, redTeam); }
  497.  
  498.     room.sendChat("Gole:")
  499.     for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
  500.         room.sendChat(key + " " + value[1] + value[2] + ": " + value[0]);
  501.     }
  502.     teamPossFun();
  503. }
  504.  
  505. room.onGameStop = function(){
  506.     scorers = undefined;
  507.     whoTouchedBall = [init, init];
  508.     whoTouchedLast = undefined;
  509.     gk = [init, init];
  510.     kickOff = false;
  511.     hasFinished = false;
  512. }
  513.  
  514. room.onStadiumChange = function(newStadiumName, byPlayer) {
  515.     if (newStadiumName != "fut4/q") {
  516.         room.setCustomStadium(futsal);
  517.     }
  518. }
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. // Made by Grandes Ligas HaxBall
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top