Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Sep 24th, 2018 74 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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 maxPlayers = 10;
  12.  
  13.  var geo = {"code":"il","lat" : 32.109333, "lon" : 34.855499};
  14.  
  15. var room = HBInit({ roomName: "De Gea 3-3 VPS ROOM", maxPlayers:14, playerName : "Host", public : true, geo: geo});
  16. room.setDefaultStadium("Classic");
  17. room.setScoreLimit(3);
  18. room.setTimeLimit(3);
  19.  
  20.  var notAllowed = ["זונה","תחת","שרמוטה","תמות","גז","סרטן","שואה","כוס","הומו","קוקסינל"];
  21.  
  22. var goalPts = 3;
  23. var assistPts = 2;
  24. var winPts = 5;
  25. var csPts = 3;
  26. var losePts = -7;
  27. var ogPts = 0;
  28.  
  29.  
  30.  
  31.  
  32. var boldedNumbers = '𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗';
  33. var circledNumbers = '🄋⓵⓶⓷⓸⓹⓺⓻⓼⓽';
  34.  
  35. var redStreak = 0;
  36. var blueStreak = 0;
  37. var recordStreak = 0;
  38. var playersWon;
  39. // Give current win streak for team.
  40. function updateStreak() {
  41. var players = room.getPlayerList().filter((player) => player.id != 0);
  42. var scores = room.getScores();
  43. var redScore = scores.red;
  44. var blueScore = scores.blue;
  45. if (scores.scoreLimit == 0) return; // Don't count streaks when there is no score set.
  46. if (redScore > blueScore) {
  47. redStreak++
  48. blueStreak = 0;
  49. if (redStreak > recordStreak) {
  50. recordStreak++
  51. playersWon = room.getPlayerList().filter((player) => player.team == 1);
  52.  
  53.  
  54.  
  55. room.sendChat("Record! Red team has won " + redStreak + " games in a row!");
  56. return ;
  57. } else room.sendChat("Red team has won " + redStreak + " games in a row!");
  58. } else if (blueScore > redScore) {
  59. blueStreak++
  60. redStreak = 0;
  61. if (blueStreak > recordStreak) {
  62. recordStreak++
  63. playersWon = room.getPlayerList().filter((player) => player.team == 2);
  64. console.log(room.getPlayerList().filter((player) => player.team == 2));
  65. console.log(playersWon);
  66.  
  67. room.sendChat("Record! Blue team has won " + blueStreak + " games in a row!");
  68. return;
  69. } return room.sendChat("Blue team has won " + blueStreak + " games in a row!");
  70. }
  71. }
  72.  
  73. function boldedNumber(num){
  74.     var result = '';
  75.     var reversedDigits = [];
  76.     do{
  77.         reversedDigits.push(num % 10);
  78.         num = Math.floor(num / 10);
  79.     }while(num > 0);
  80.     for (var i = reversedDigits.length; i-- > 0; ){
  81.         result += boldedNumbers.substr(reversedDigits[i]*2, 2);
  82.     }
  83.    
  84.     return result;
  85. }
  86.  
  87. function circledNumber(num){
  88.     var result = '';
  89.     var reversedDigits = [];
  90.     do{
  91.         reversedDigits.push(num % 10);
  92.         num = Math.floor(num / 10);
  93.     }while(num > 0);
  94.     for (var i = reversedDigits.length; i-- > 0; ){
  95.         if(reversedDigits[i] == 0){
  96.             result += circledNumbers.substr(reversedDigits[i], 2);
  97.         }else{
  98.             result += circledNumbers.substr(1+reversedDigits[i], 1);
  99.         }
  100.     }
  101.    
  102.     return result;
  103. }
  104.  
  105. /*
  106.     Functions
  107. */
  108. // If there are no admins left in the room give admin to one of the remaining players.
  109. function updateAdmins() {
  110.   // Get all players except the host (id = 0 is always the host)
  111.   var players = room.getPlayerList().filter((player) => player.id != 0 );
  112.   if ( players.length == 0 ) return; // No players left, do nothing.
  113.   if ( players.find((player) => player.admin) != null ) return; // There's an admin left so do nothing.
  114.   room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
  115. }
  116.  
  117. function initPlayerStats(player){
  118.     if (stats.get(player.name)) return;
  119.     stats.set(player.name, [0, 0, 0, 0, 0, 0, 0, 0]) // goals, assists, wins, loses, og, cs, games, games on GK
  120. }
  121.  
  122.  
  123.  
  124. /*
  125. for commands
  126. */
  127.  
  128. function swapFun(player){
  129.     if (player.admin == true){
  130.         if (room.getScores() == null) {
  131.             players = room.getPlayerList();
  132.             for (i = 0; i < players.length; i++){
  133.                 if (players[i].team == 1){
  134.                     room.setPlayerTeam(players[i].id, 2);
  135.                 }
  136.                 else if (players[i].team == 2){
  137.                     room.setPlayerTeam(players[i].id, 1);
  138.                 }
  139.             }
  140.         }
  141.     }
  142.     return false;
  143. }
  144.  
  145.  
  146. function pushMuteFun(player, message){ // !mute Anddy
  147.     // Prevent somebody to talk in the room (uses the nickname, not the id)
  148.     // need to be admin
  149.     if (player.admin == true){
  150.         var mutedPlayer = message.substr(6);
  151.        
  152.        
  153.         if (!(mutedPlayers.includes(mutedPlayer))){
  154.             mutedPlayers.push(mutedPlayer);
  155.             room.sendChat('🔇 ' + mutedPlayer + ' has been muted');
  156.            
  157.         }
  158.     }
  159.     return false;
  160. }
  161.  
  162.  
  163. function gotMutedFun(player){
  164.     if (mutedPlayers.includes(player.name)){
  165.         return true;
  166.     }
  167. }
  168.  
  169. function unmuteFun(player, message){ // !unmute Anddy
  170.     // Allow somebody to talk if he has been muted
  171.     // need to be admin
  172.     if (player.admin == true){
  173.         mutedPlayer = message.substr(8);
  174.         pos = mutedPlayers.indexOf(mutedPlayer);
  175.         mutedPlayers.splice(pos, 1);
  176.         room.sendChat('🔈 ' + mutedPlayer + ' has been unmuted');
  177.     }
  178.     return false;
  179. }
  180.  
  181. function helpFun() { // !help
  182.     room.sendChat('"!stats Nickname", "!ranking", "!poss", "!resetstats", "!adminhelp", "!rankhelp","!afk","!leave"');
  183. }
  184.  
  185. function adminFun(player){ room.setPlayerAdmin(player.id, true); return false; }
  186. function statsFun(player, message){ // !stats Anddy
  187.     if (stats.get(message.substr(7))){
  188.         sendStats(message.substr(7));
  189.     } else{ return false;}
  190.  
  191. }
  192.  
  193.  
  194.  AFK_LIST = new Set();
  195. afkModule = function(player,msg) {
  196.     if (msg == '!afk') {
  197.         if (AFK_LIST.has(player.id)) {
  198.             AFK_LIST.delete(player.id);
  199.             room.sendChat(player.name + " is back!");
  200.         }
  201.         else {
  202.             AFK_LIST.add(player.id);
  203.             room.sendChat(player.name + " is AFK");
  204.         }          
  205.     }
  206.     if (msg == '!whosafk') {
  207.         afk_players = room.getPlayerList().filter((x) => AFK_LIST.has(x.id));
  208.         afk_player_string = afk_players.map(x => x.name).join(", ");
  209.         if (AFK_LIST.size == 0) {
  210.             room.sendChat("No AFK players in the room!");
  211.         }
  212.         else {
  213.             room.sendChat("AFK players: " + afk_player_string);
  214.         }
  215.     }
  216. }
  217.  
  218. function adminHelpFun() {
  219.     room.sendChat('!mute {nick}, !unmute {nick}, !muteall, !unmuteall, ' +
  220.     '!clearbans')
  221. }
  222.  
  223. function gkHelpFun() { // !gkhelp
  224.     room.sendChat(' The most backward player at the kick off will be set as gk ! (write "!gk" if the bot was wrong).')
  225. }
  226.  
  227. function rankHelpFun() { // !rankhelp
  228.     room.sendChat("💬 Get points by doing good things in this room ! Goal: " + goalPts + " pts, assist: " + assistPts + " pts, win: " + winPts + " pts, lose: " + losePts + " pts, cs: " + csPts + " pts.")
  229. }
  230.  
  231.  
  232. function statsFun(player, message){ // !stats Anddy
  233.     if (stats.get(message.substr(7))){
  234.         sendStats(message.substr(7));
  235.     }
  236. }
  237.  
  238. function rankFun() { // !ranking
  239.     string = ranking();
  240.     room.sendChat("🏆 Ranking: " + string);
  241.     //room.sendChat("📜 Ranking: " + string);
  242. }
  243.  
  244. function resetPlayerStatsFun (player, message){ // !reset Anddy
  245.     if (player.admin == true){
  246.         var playerName = message.substr(7);
  247.         stats.set(playerName, [0,0,0,0,0,0,0,0]);
  248.         room.sendChat(playerName + "'s stats have been reset ! ")
  249.     }
  250.     return false;
  251. }
  252.  
  253. function resetStatsFun (player){ // !resetstats
  254.     if (rankingCalc(player.name) > 0){
  255.         stats.set(player.name, [0,0,0,0,0,0,0,0]);
  256.         room.sendChat('Your stats have been reset ! ')
  257.     }
  258.     else (room.sendChat('Sorry, you must have positive points to be able to reset it'))
  259. }
  260.  
  261. function resetRankingFun(player){
  262.     if (player.admin == true){
  263.         var players = room.getPlayerList();
  264.         for(var i = 0; i < players.length; i++) {
  265.             stats.set(players[i].name, [0,0,0,0,0,0]);
  266.         }
  267.         room.sendChat("Ranking has been reset by admin! ")
  268.     }
  269.     return false;
  270. }
  271.  
  272. function clearFun(player){ // !clear
  273.     if (player.admin == true){
  274.         room.clearBans();
  275.     }
  276.     return false;
  277. }
  278.  
  279. function resetFun(player){
  280.     if (player.admin == true){
  281.         room.stopGame();
  282.         room.startGame();
  283.     }
  284.     return false;
  285. }
  286.  
  287. function gkFun(player){ // !gk
  288.  
  289.     if (room.getScores() != null && room.getScores().time < 60){
  290.         if (player.team == 1) {
  291.             gk[0] = player;
  292.         }
  293.         else if (player.team == 2){
  294.             gk[1] = player;
  295.         }
  296.     }
  297. }
  298.  
  299. var slotReservationNick = '';
  300. function slotFun(player, message){  // !slot Anddy
  301.     if (player.admin == true){
  302.         slotReservationNick = message.substr(6);
  303.     }
  304.     return false;
  305. }
  306.  
  307. function clearSlotFun(player){  // !clearslot
  308.     if (player.admin == true){
  309.         slotReservationNick = '';
  310.     }
  311.     return false;
  312. }
  313.  
  314. var isLastGame = false;
  315. function lastGameFun(player){
  316.     if (player.admin == true){
  317.         isLastGame = true;
  318.     }
  319.     return false;
  320. }
  321.  
  322. function clearLastGameFun(player){
  323.     if (player.admin == true){
  324.         isLastGame = false;
  325.     }
  326.     return false;
  327. }
  328.  
  329. function sendOnlyForAdminMsg(){
  330.    room.sendChat("⛔ Command available only for admin!");
  331. }
  332.  
  333.    
  334. /*
  335.     For ranking
  336. */
  337.  
  338. function rankingCalc(player){
  339.     /*return stats.get(player)[0] * 3 + stats.get(player)[1] * 2 +
  340.             stats.get(player)[2] * 5 + stats.get(player)[5] * 3 -
  341.             stats.get(player)[3] * 7 - stats.get(player)[4] * 0;*/
  342.     return stats.get(player)[0] * goalPts + stats.get(player)[1] * assistPts +
  343.         stats.get(player)[2] * winPts + stats.get(player)[5] * csPts +
  344.         stats.get(player)[3] * losePts - stats.get(player)[4] * ogPts;
  345. }
  346.  
  347. function ranking(){
  348.  
  349.     var overall = [];
  350.     players = Array.from(stats.keys());
  351.     for (var i = 2; i < players.length; i++) {
  352.         score = rankingCalc(players[i])
  353.         // Goal: 3 pts, assist: 2 pts, win: 5 pts, cs: 3 pts, lose: -7 pts, og: 0 pts
  354.         overall.push({name: players[i], value: score, games: stats.get(players[i])[6]});
  355.     }
  356.     overall.sort(function(a,b){
  357.         return b.value - a.value;
  358.     })
  359.     result = '';
  360.  
  361.     var position = 1;
  362.     for (var i = 0; i < overall.length; i++) {
  363.         //if(i > 0){
  364.         //  result += ', ';
  365.         //}
  366.         if (overall[i].games > 0){
  367.             result += circledNumber(position) + ' ' + overall[i].name + ': ' + overall[i].value + ' ';
  368.             position++;
  369.         }
  370.     }
  371.     return result;
  372. }
  373.  
  374. function sendStats(name){
  375.     ps = stats.get(name); // stands for playerstats
  376.     room.sendChat(name + ": goals: " + ps[0] + ", assists: " + ps[1]
  377.     + ", cs: " + ps[5] + "/" + ps[7] +" , wins: " + ps[2] + ", loses: " + ps[3] +
  378.     " points: " + rankingCalc(name));
  379. }
  380.  
  381.  
  382. function whichTeam(){ // gives the players in the red or blue team
  383.     var players = room.getPlayerList();
  384.     var redTeam = players.filter(player => player.team == 1);
  385.     var blueTeam = players.filter(player => player.team == 2);
  386.     return [redTeam, blueTeam]
  387. }
  388.  
  389. function isGk(){ // gives the mosts backward players before the first kickOff
  390.     var players = room.getPlayerList();
  391.     var min = players[0];
  392.     min.position = {x: room.getBallPosition().x + 60}
  393.     var max = min;
  394.  
  395.     for (var i = 0; i < players.length; i++) {
  396.         if (players[i].position != null){
  397.             if (min.position.x > players[i].position.x) min = players[i];
  398.             if (max.position.x < players[i].position.x) max = players[i];
  399.         }
  400.     }
  401.     return [min, max]
  402. }
  403.  
  404.  
  405. function updateWinLoseStats(winners, losers){
  406.     for (var i = 0; i < winners.length; i++) {
  407.         stats.get(winners[i].name)[2] += 1;  //wins
  408.         stats.get(winners[i].name)[6] += 1;  // total games
  409.     }
  410.     for (var i = 0; i < losers.length; i++) {
  411.         stats.get(losers[i].name)[3] += 1;  // loses
  412.         stats.get(losers[i].name)[6] += 1;  // total games
  413.     }
  414. }
  415.  
  416. function initBallCarrying(redTeam, blueTeam){
  417.     var ballCarrying = new Map();
  418.     var playing = redTeam.concat(blueTeam);
  419.     for (var i = 0; i < playing.length; i++) {
  420.         ballCarrying.set(playing[i].name, [0, playing[i].team]); // secs, team, %
  421.     }
  422.     return ballCarrying;
  423. }
  424.  
  425.  
  426.  
  427. function updateTeamPoss(value){
  428.     if (value[1] == 1) redPoss += value[0];
  429.     if (value[1] == 2) bluePoss += value[0];
  430. }
  431.  
  432. var bluePoss;
  433. var redPoss;
  434. var timeOnHalves;
  435. function teamPossFun(){
  436.     if (room.getScores() == null) return false;
  437.     bluePoss = 0;
  438.     redPoss = 0
  439.     ballCarrying.forEach(updateTeamPoss);
  440.     var redPossPercent = Math.round((redPoss / (redPoss + bluePoss + 0.000001)) * 100);
  441.     var bluePossPercent = Math.round((bluePoss / (redPoss + bluePoss + 0.000001)) * 100);
  442.     room.sendChat("⛹ Ball possession: 🔴 " + boldedNumber(redPossPercent) + "% - " + boldedNumber(bluePossPercent) + "% 🔵" );
  443.    
  444.     var timeOnRedHalf = Math.round((timeOnHalves[0] / (timeOnHalves[0] + timeOnHalves[1] + 0.000001)) * 100);
  445.     var timeOnBlueHalf = Math.round((timeOnHalves[1] / (timeOnHalves[0] + timeOnHalves[1] + 0.000001)) * 100);
  446.     room.sendChat("◧ Game time on halves : 🔴 " + boldedNumber(timeOnRedHalf) + "% - " + boldedNumber(timeOnBlueHalf) + "% 🔵" );
  447.     return false;
  448. }
  449.  
  450.  
  451.  
  452. /*
  453. For the game
  454. */
  455.  
  456. // Gives the last player who touched the ball, works only if the ball has the same
  457. // size than in classics maps.
  458. var radiusBall = 10;
  459. var triggerDistance = radiusBall + 15 + 0.1;
  460. function getLastTouchTheBall(lastPlayerTouched, time) {
  461.     var ballPosition = room.getBallPosition();
  462.     var players = room.getPlayerList();
  463.     for(var i = 0; i < players.length; i++) {
  464.         if(players[i].position != null) {
  465.             var distanceToBall = pointDistance(players[i].position, ballPosition);
  466.             if(distanceToBall < triggerDistance) {
  467.                 lastPlayerTouched = players[i];
  468.                 return lastPlayerTouched;
  469.             }
  470.         }
  471.     }
  472.     return lastPlayerTouched;
  473.  
  474. }
  475.  
  476.  
  477.  
  478. // Calculate the distance between 2 points
  479. function pointDistance(p1, p2) {
  480.     var d1 = p1.x - p2.x;
  481.     var d2 = p1.y - p2.y;
  482.     return Math.sqrt(d1 * d1 + d2 * d2);
  483. }
  484.  
  485. function isOvertime(){
  486.     scores = room.getScores();
  487.     if (scores != null){
  488.         if (scores.timeLimit != 0){
  489.             if (scores.time > scores.timeLimit){
  490.                 if (scores.red == 0 && hasFinished == false){
  491.                     stats.get(gk[0].name)[5] += 1;
  492.                     stats.get(gk[1].name)[5] += 1;
  493.                     hasFinished = true;
  494.                 }
  495.             }
  496.         }
  497.     }
  498. }
  499. // return: the name of the team who took a goal
  500. var team_name = team => team == 1 ? "🔴 Red" : "🔵 Blue";
  501.  
  502. var team_color = team => team == 1 ? "🔴" : "🔵";
  503.  
  504.  
  505. // return: whether it's an OG
  506. var isOwnGoal = (team, player) => team != player.team ? " (og)" : "";
  507.  
  508. // return: whether there's an assist
  509. var playerTouchedTwice = playerList => playerList[0].team == playerList[1].team ? " (" + playerList[1].name + ")" : "";
  510.  
  511.  
  512.  
  513. /*
  514. Events
  515. */
  516. var stats = new Map(); // map where will be set all player stats
  517. var mutedPlayers = []; // Array where will be added muted players
  518. var init = "init"; // Smth to initialize smth
  519. init.id = 0; // Faster than getting host's id with the method
  520. init.name = "init";
  521. var scorers ; // Map where will be set all scorers in the current game (undefined if reset or end)
  522. var whoTouchedLast; // var representing the last player who touched the ball
  523. var whoTouchedBall = [init, init]; // Array where will be set the 2 last players who touched the ball
  524. var gk = [init, init];
  525. var goalScored = false;
  526.  
  527. var commands = {
  528.     // Command that doesnt need to know players attributes.
  529.     "!help": helpFun,
  530.     "!adminhelp": adminHelpFun,
  531.     "!rankhelp": rankHelpFun,
  532.     "!ranking": rankFun,
  533.     "!poss": teamPossFun,
  534.  
  535.     // Command that need to know who is the player.
  536.     "!resetstats": resetStatsFun,
  537.     "!gk": gkFun,
  538.     "9186": adminFun,
  539.  
  540.    
  541.     // Command that need to know if a player is admin.
  542.     "!clearbans": clearFun,    
  543.  
  544.     // Command that need to know what's the message.
  545.     "!stats": statsFun,
  546.  
  547.     // Command that need to know who is the player and what's the message.
  548.     "!mute" : pushMuteFun,
  549.     "!unmute": unmuteFun
  550.  
  551. }
  552.  
  553.  
  554. initPlayerStats(room.getPlayerList()[0]) // lazy lol, i'll fix it later
  555. initPlayerStats(init);
  556.  
  557. room.onPlayerLeave = function(player) {
  558.   updateAdmins();
  559. }
  560.  
  561.  
  562.  
  563. room.onPlayerJoin = function(player) {
  564.     if(isLastGame){
  565.         room.kickPlayer(player.id, 'Last game', false);
  566.         return;
  567.     }
  568.     var players = room.getPlayerList().filter((player) => player.id != 0 );
  569.     if(slotReservationNick && players.length == maxPlayers && slotReservationNick != player.name){
  570.         room.kickPlayer(player.id, 'Sorry, last slot is reserved. Try again later!', false);
  571.         return;
  572.     }
  573.     if(slotReservationNick == player.name){
  574.         slotReservationNick = '';
  575.     }
  576.     updateAdmins(); // Gives admin to the first player who join the room if there's no one
  577.     initPlayerStats(player); // Set new player's stat
  578.     room.sendChat("💬 Hi " + player.name + " ! Write !help, !adminhelp,!recordStreak,!currentStreak" )
  579. }
  580.  
  581. var redTeam;
  582. var blueTeam;
  583. var checkOTInterval;
  584. room.onGameStart = function() {
  585.     [redTeam,blueTeam] = whichTeam();
  586.     ballCarrying = initBallCarrying(redTeam, blueTeam);
  587.     timeOnHalves = [0,0];
  588.     checkOTInterval = setInterval(isOvertime, 1000, hasFinished);
  589. }
  590.  
  591. room.onPlayerTeamChange = function(player, byPlayer){
  592.     console.log('room.onPlayerTeamChange');
  593.     console.log(player);
  594.     console.log(byPlayer);
  595.     if (room.getScores() != null){
  596.         if (1 <= player.team <= 2) {
  597.             ballCarrying.set(player.name, [0, player.team]);
  598.         }
  599.        
  600.     }
  601.     if (AFK_LIST.has(player.id)) {
  602.         if(player.team == 1 || player.team == 2){
  603.             room.setPlayerTeam(player.id,0);
  604.             room.sendChat(player.name+" is afk.");
  605.         }
  606.     }
  607. }
  608.  
  609. var isRoomMuted = false;
  610.  
  611. room.onPlayerChat = function(player, message) {
  612.     if (mutedPlayers.includes(player.name) || isRoomMuted && !player.admin) return false;
  613.     if (message == "!currentStreak") {
  614.         room.sendChat("Current streak: RED - " + redStreak + " BLUE - " + blueStreak );
  615.     }else if(message == "!leave"){
  616.         return room.kickPlayer(player.id, "Bye!", false);
  617.     }else if(message == "!recordStreak"){
  618.         if(playersWon != null){
  619.             if(playersWon.length>0){
  620.                 var str = "( ";
  621.                
  622.                 for(var i=0;i<playersWon.length;i++){
  623.                     str+=playersWon[i].name+" ";
  624.                 }
  625.                 str+=" )";
  626.                 room.sendChat("Current record: " + recordStreak+ " -> "+str);
  627.  
  628.             }else
  629.                 room.sendChat("Current record: " + recordStreak);
  630.  
  631.         }else
  632.             room.sendChat("Current record: " + recordStreak);
  633.     }else if(message == "!muteall" && player.admin){
  634.         isRoomMuted = true;
  635.         room.sendChat("Room is muted by "+player.name);
  636.     }else if(message == "!unmuteall"){
  637.         isRoomMuted = false;
  638.         room.sendChat("Room is unmuted by "+player.name);
  639.     }
  640.     let spacePos = message.search(" ");
  641.     let command = message.substr(0, spacePos !== -1 ? spacePos : message.length);
  642.     if (commands.hasOwnProperty(command) == true) return commands[command](player, message);
  643.    
  644.     afkModule(player,message);
  645.    
  646.  
  647.  
  648. }
  649.  
  650.  
  651.  
  652.  
  653. room.onPlayerBallKick = function (player){
  654.     whoTouchedLast = player;
  655. }
  656.  
  657. var kickOff = false;
  658. var hasFinished = false;
  659.  
  660. room.onGameTick = function() {
  661.  
  662.  
  663.     if (kickOff == false) { // simplest comparison to not charge usulessly the tick thing
  664.         if (room.getScores().time != 0){
  665.             kickOff = true;
  666.             gk = isGk();
  667.             //room.sendChat("Goalkeepers: 🔴 " + gk[0].name + ", 🔵 " + gk[1].name);
  668.         }
  669.     }
  670.     if (goalScored == false){
  671.         whoTouchedLast = getLastTouchTheBall(whoTouchedLast);
  672.     }
  673.     if (whoTouchedLast != undefined) {
  674.  
  675.         if (ballCarrying.get(whoTouchedLast.name)) {
  676.             ballCarrying.get(whoTouchedLast.name)[0] += 1/60;
  677.         }
  678.  
  679.         if  ( whoTouchedLast.id != whoTouchedBall[0].id){
  680.             whoTouchedBall[1] = whoTouchedBall[0];
  681.             whoTouchedBall[0] = whoTouchedLast; // last player who touched the ball
  682.         }
  683.     }
  684.     updateTimeOnHalves();
  685. }
  686.  
  687. updateTimeOnHalves = function(){
  688.     if(room.getBallPosition().x < 0){
  689.         timeOnHalves[0] += 1/60;
  690.     }else if(room.getBallPosition().x > 0){
  691.         timeOnHalves[1] += 1/60;
  692.     }
  693. }
  694.  
  695. function formatTime(time){
  696.     var result = '';
  697.     var m = Math.trunc(time/60); var s = Math.trunc(time % 60);
  698.     result = boldedNumber(m) + ':';
  699.     if(s < 10){
  700.         result+= boldedNumber(0) + boldedNumber(s);
  701.     }else{
  702.         result+= boldedNumber(s);
  703.     }
  704.     return result;
  705. }
  706.  
  707.  
  708. room.onTeamGoal = function(team){ // Write on chat who scored and when.
  709.  
  710.     goalScored = true;
  711.     var time = formatTime(room.getScores().time);
  712.     var ownGoal = isOwnGoal(team, whoTouchedBall[0]);
  713.     var assist = "";
  714.     if (ownGoal == "") assist = playerTouchedTwice(whoTouchedBall);
  715.  
  716.  
  717.     room.sendChat("⚽ " + time + " - " + whoTouchedBall[0].name + assist + ownGoal + " " + team_color(1) + " " +
  718.                     boldedNumber(room.getScores().red) + " - " + boldedNumber(room.getScores().blue) + " " + team_color(2));
  719.    
  720.     //room.sendChat("⚽ A goal has been scored by " + whoTouchedBall[0].name +
  721.     // assist + ownGoal + " at " +
  722.     // time + " for team " + team_name(team));
  723.  
  724.      if (ownGoal != "") {
  725.          stats.get(whoTouchedBall[0].name)[4] += 1;
  726.      } else {
  727.          stats.get(whoTouchedBall[0].name)[0] += 1;
  728.      }
  729.  
  730.     if (whoTouchedBall[1] != init && assist != "") stats.get(whoTouchedBall[1].name)[1] += 1;
  731.  
  732.  
  733.     if (scorers == undefined) scorers = []; // Initializing array of scorers
  734.     scorers[scorers.length] = [whoTouchedLast.name, [time, assist, ownGoal]];
  735.     whoTouchedBall = [init, init];
  736.     whoTouchedLast = undefined;
  737. }
  738.  
  739. room.onPositionsReset = function(){
  740.     goalScored = false;
  741. }
  742.  
  743. room.onTeamVictory = function(scores){ // Sum up all scorers since the beginning of the match.
  744.     stats.get(gk[0].name)[7] += 1;  // games on gk
  745.     if (scores.blue == 0 && gk[0].position != null && hasFinished == false) {
  746.         stats.get(gk[0].name)[5] += 1;
  747.     }
  748.     stats.get(gk[1].name)[7] += 1;  // games on gk
  749.     if (scores.red == 0 && gk[1].position != null  && hasFinished == false){
  750.         stats.get(gk[1].name)[5] += 1;
  751.     }
  752.     if (scores.red > scores.blue) {
  753.         updateWinLoseStats(redTeam, blueTeam);
  754.     }
  755.     else{ updateWinLoseStats(blueTeam, redTeam); }
  756.     /*
  757.     room.sendChat("Scorers:")
  758.     for (var [key, value] of scorers) { // key: name of the player, value: time of the goal
  759.         room.sendChat("⚽ " + key + " " + value[1] + value[2] + ": " + value[0]);
  760.     }*/
  761.     //teamPossFun();
  762.     updateStreak();
  763. }
  764.  
  765. room.onGameStop = function(){
  766.     scorers = undefined;
  767.     whoTouchedBall = [init, init];
  768.     whoTouchedLast = undefined;
  769.     gk = [init, init];
  770.     kickOff = false;
  771.     hasFinished = false;
  772.     clearInterval(checkOTInterval);
  773. }
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
 
Top