Advertisement
Guest User

pup totals

a guest
Jun 2nd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Scoreboard Power Ups
  3. // @version 0.1
  4. // @description Display the number of power ups and tagpros grabbed by each player on scoreboard.
  5. // @author yank
  6. // @include http://tagpro-*.koalabeast.com:*
  7. // @include http://tangent.jukejuice.com:*
  8. // @include http://*.newcompte.fr:*
  9. // ==/UserScript==
  10.  
  11. //
  12. // Increase width of scoreboard.
  13. //
  14. $('#options').css('width', '930px');
  15.  
  16. //
  17. // Add PUPs and TPs to scoreboard header.
  18. //
  19. $('#stats').find('tbody').find('tr').find('th:contains("Rank Pts")').after('<th name="s-tagpros">Tagpros</th>').after('<th name="s-pups">Powerups</th>');
  20.  
  21. //
  22. // Add empty columns to player stats row templates.
  23. //
  24. $('#stats').find('.template').find('td:last-child').before('<td></td>').before('<td></td>');
  25.  
  26. tagpro.ready(function() {
  27. //
  28. // Threshold for lifetime of a powerup. Needs to be greater than 20 or we could incorrectly
  29. // double count some powerups.
  30. //
  31. var POWERUP_TIME_THRESHOLD = 20.5;
  32. var uiDraw = tagpro.ui.update;
  33.  
  34. //
  35. // Given a player name and score, identify the player's id so their
  36. // pup and tagpro stats can be grabbed.
  37. //
  38. function identifyPlayerIdForRow(name, score, support) {
  39. for (var id in tagpro.players) {
  40. var player = tagpro.players[id];
  41. if (player.name == name && player.score == score && player['s-support'] == support) {
  42. return id;
  43. }
  44. }
  45. }
  46.  
  47. tagpro.events.register({
  48. modifyScoreUI: function() {
  49. //
  50. // Iterate rows in scoreboard and fill in pups/tagpros stats.
  51. //
  52. var current = $('.template').next();
  53. for (var id in tagpro.players) {
  54. var name = current.children().eq(0).find('.scoreName').text();
  55. var score = parseInt(current.children().eq(1).text());
  56. var support = parseInt(current.children().eq(10).text());
  57. var id = identifyPlayerIdForRow(name, score, support);
  58.  
  59. current.children().eq(12).html(tagpro.players[id]['s-pups']);
  60. current.children().eq(13).html(tagpro.players[id]['s-tagpros']);
  61. current = current.next();
  62. }
  63. }
  64. });
  65.  
  66. tagpro.ui.update = function() {
  67. for (var id in tagpro.players) {
  68. var player = tagpro.players[id];
  69.  
  70. //
  71. // Init s-pups and s-tagpros
  72. //
  73. if (!player['s-pups']) {
  74. player['s-pups'] = 0;
  75. }
  76.  
  77. if (!player['s-tagpros']) {
  78. player['s-tagpros'] = 0;
  79. }
  80.  
  81. //
  82. // Just picked up powerup. Note the timestamp.
  83. //
  84. if (player.bomb && !player.prevBomb) {
  85. player.bombTime = Date.now();
  86. }
  87.  
  88. if (player.grip && !player.prevGrip) {
  89. player.gripTime = Date.now();
  90. }
  91.  
  92. if (player.tagpro && !player.prevTagpro) {
  93. player.tagproTime = Date.now();
  94. }
  95.  
  96. //
  97. // Powerup has run out/been defused.
  98. //
  99. if (!player.bomb && player.prevBomb) {
  100. var seconds = (Date.now() - player.bombTime) / 1000;
  101. player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
  102. }
  103.  
  104. if (!player.grip && player.prevGrip) {
  105. var seconds = (Date.now() - player.gripTime) / 1000;
  106. player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
  107. }
  108.  
  109. if (!player.tagpro && player.prevTagpro) {
  110. var seconds = (Date.now() - player.tagproTime) / 1000;
  111. var numPups = Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
  112. player['s-pups'] += numPups;
  113. player['s-tagpros'] += numPups;
  114. }
  115.  
  116.  
  117. player.prevBomb = player.bomb;
  118. player.prevGrip = player.grip;
  119. player.prevTagpro = player.tagpro;
  120. }
  121. return uiDraw.apply(this, arguments);
  122. };
  123.  
  124. //
  125. // At end of game, add up all active powerups
  126. //
  127. tagpro.socket.on("end", function() {
  128. for (var id in tagpro.players) {
  129. var player = tagpro.players[id];
  130. if (player.bomb) {
  131. var seconds = (Date.now() - player.bombTime) / 1000;
  132. player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
  133. }
  134.  
  135. if (player.grip) {
  136. var seconds = (Date.now() - player.gripTime) / 1000;
  137. player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
  138. }
  139.  
  140. if (player.tagpro) {
  141. var seconds = (Date.now() - player.tagproTime) / 1000;
  142. var numPups = Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
  143. player['s-pups'] += numPups;
  144. player['s-tagpros'] += numPups;
  145. }
  146. }
  147. });
  148. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement