Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Scoreboard Power Ups
- // @version 0.1
- // @description Display the number of power ups and tagpros grabbed by each player on scoreboard.
- // @author yank
- // @include http://tagpro-*.koalabeast.com:*
- // @include http://tangent.jukejuice.com:*
- // @include http://*.newcompte.fr:*
- // ==/UserScript==
- //
- // Increase width of scoreboard.
- //
- $('#options').css('width', '930px');
- //
- // Add PUPs and TPs to scoreboard header.
- //
- $('#stats').find('tbody').find('tr').find('th:contains("Rank Pts")').after('<th name="s-tagpros">Tagpros</th>').after('<th name="s-pups">Powerups</th>');
- //
- // Add empty columns to player stats row templates.
- //
- $('#stats').find('.template').find('td:last-child').before('<td></td>').before('<td></td>');
- tagpro.ready(function() {
- //
- // Threshold for lifetime of a powerup. Needs to be greater than 20 or we could incorrectly
- // double count some powerups.
- //
- var POWERUP_TIME_THRESHOLD = 20.5;
- var uiDraw = tagpro.ui.update;
- //
- // Given a player name and score, identify the player's id so their
- // pup and tagpro stats can be grabbed.
- //
- function identifyPlayerIdForRow(name, score, support) {
- for (var id in tagpro.players) {
- var player = tagpro.players[id];
- if (player.name == name && player.score == score && player['s-support'] == support) {
- return id;
- }
- }
- }
- tagpro.events.register({
- modifyScoreUI: function() {
- //
- // Iterate rows in scoreboard and fill in pups/tagpros stats.
- //
- var current = $('.template').next();
- for (var id in tagpro.players) {
- var name = current.children().eq(0).find('.scoreName').text();
- var score = parseInt(current.children().eq(1).text());
- var support = parseInt(current.children().eq(10).text());
- var id = identifyPlayerIdForRow(name, score, support);
- current.children().eq(12).html(tagpro.players[id]['s-pups']);
- current.children().eq(13).html(tagpro.players[id]['s-tagpros']);
- current = current.next();
- }
- }
- });
- tagpro.ui.update = function() {
- for (var id in tagpro.players) {
- var player = tagpro.players[id];
- //
- // Init s-pups and s-tagpros
- //
- if (!player['s-pups']) {
- player['s-pups'] = 0;
- }
- if (!player['s-tagpros']) {
- player['s-tagpros'] = 0;
- }
- //
- // Just picked up powerup. Note the timestamp.
- //
- if (player.bomb && !player.prevBomb) {
- player.bombTime = Date.now();
- }
- if (player.grip && !player.prevGrip) {
- player.gripTime = Date.now();
- }
- if (player.tagpro && !player.prevTagpro) {
- player.tagproTime = Date.now();
- }
- //
- // Powerup has run out/been defused.
- //
- if (!player.bomb && player.prevBomb) {
- var seconds = (Date.now() - player.bombTime) / 1000;
- player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
- }
- if (!player.grip && player.prevGrip) {
- var seconds = (Date.now() - player.gripTime) / 1000;
- player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
- }
- if (!player.tagpro && player.prevTagpro) {
- var seconds = (Date.now() - player.tagproTime) / 1000;
- var numPups = Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
- player['s-pups'] += numPups;
- player['s-tagpros'] += numPups;
- }
- player.prevBomb = player.bomb;
- player.prevGrip = player.grip;
- player.prevTagpro = player.tagpro;
- }
- return uiDraw.apply(this, arguments);
- };
- //
- // At end of game, add up all active powerups
- //
- tagpro.socket.on("end", function() {
- for (var id in tagpro.players) {
- var player = tagpro.players[id];
- if (player.bomb) {
- var seconds = (Date.now() - player.bombTime) / 1000;
- player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
- }
- if (player.grip) {
- var seconds = (Date.now() - player.gripTime) / 1000;
- player['s-pups'] += Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
- }
- if (player.tagpro) {
- var seconds = (Date.now() - player.tagproTime) / 1000;
- var numPups = Math.ceil(seconds / POWERUP_TIME_THRESHOLD);
- player['s-pups'] += numPups;
- player['s-tagpros'] += numPups;
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement