Guest User

Untitled

a guest
May 25th, 2015
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. // ==UserScript==
  2. // @name CAW CAW FLAG LIGHTS
  3. // @include http://*.koalabeast.com:*
  4. // @include http://*.jukejuice.com:*
  5. // @include http://*.newcompte.fr:*
  6. // @version 0.2
  7. // ==/UserScript==
  8.  
  9. /*
  10. * CAW CAW Flag Lights by ??
  11. * Edited by ScHoolball Q
  12. * Colors adjusted by ----)
  13. */
  14.  
  15. var game = 0;
  16. red = 0,
  17. blue = 0,
  18. flags = {},
  19. oldCSS = "",
  20. css = "",
  21. flagHeld = 0,
  22. lastFlagHeld = 0;
  23.  
  24. var blueCSS = {background: "linear-gradient(90deg, rgba(0,0,0,1), rgba(0,0,200,1))"};
  25.  
  26. var redCSS = {background: "linear-gradient(90deg, rgba(200,0,0,1), rgba(0,0,0,1))"};
  27.  
  28. var redBlueCSS = {background: "linear-gradient(90deg, rgba(200,0,0,1), rgba(0,0,200,1))"};
  29.  
  30. var greyCSS = {background: "linear-gradient(90deg, rgba(0,0,0,1), rgba(0,0,0,1))"};
  31.  
  32. var yellowRedCSS = {background: "linear-gradient(90deg, rgba(255,255,0,1), rgba(0,0,0,1))"};
  33.  
  34. var yellowBlueCSS = {background: "linear-gradient(90deg, rgba(0,0,0,1), rgba(255,255,0,1))"};
  35.  
  36. var yellowRedBlueCSS = {background: "linear-gradient(90deg, rgba(255,255,0,1), rgba(255,255,0,1))"};
  37.  
  38. init();
  39.  
  40. function init() {
  41.  
  42. // default values
  43. $("html").css("background-color", "rgba(0,0,0,0.25)");
  44. $("html").css(greyCSS);
  45.  
  46. if (!tagpro.map) return setTimeout(function(){init();},0);
  47.  
  48. checkPlayers();
  49.  
  50. tagpro.socket.on("p", function(message) {
  51.  
  52. if(!Array.isArray(message)) message = [message];
  53.  
  54. for (var i = 0; i < message.length; i++) {
  55. var data = message[i].u;
  56.  
  57. if(data !== undefined) {
  58.  
  59. if (tagpro)
  60.  
  61. for(var j = 0; j < data.length; j++) {
  62. if(data[j].flag || typeof data[j].flag == "object") { // a flag exists
  63. flagHeld = 1;
  64. checkPlayers();
  65. }
  66. }
  67. }
  68. }
  69. if(!flagHeld && lastFlagHeld) {setColor(0,0,0); flagHeld = 0;} // what type of game doesn't matter
  70. lastFlagHeld = flagHeld;
  71. });
  72. }
  73.  
  74. function checkPlayers() {
  75.  
  76. var oldgame = game, oldred = red, oldblue = blue;
  77.  
  78. game = 1, red = 0, blue = 0; // assume CTF game
  79.  
  80. for (var id in tagpro.players) {
  81. var player = tagpro.players[id];
  82.  
  83. /*
  84. * FYI:
  85. *
  86. * player.flag == null, no flag (CTF && NF)
  87. * player.flag == 1, red flag (CTF)
  88. * player.flag == 2, blue flag (CTF)
  89. * player.flag == 3, yellow flag (NF)
  90. *
  91. * player.team == 1, red team
  92. * player.team == 2, blue team
  93. */
  94.  
  95. switch (player.flag) {
  96. case 3: // NF Games
  97. game = 0;
  98. case 2: // CTF Games
  99. case 1:
  100. if (player.team == 1) red = 1;
  101. else if (player.team == 2) blue = 1;
  102. }
  103. }
  104.  
  105. if (oldgame !== game || oldred !== red || oldblue !== blue) {
  106. setColor(game, red, blue);
  107. }
  108. }
  109.  
  110. function setColor (game, red, blue) {
  111.  
  112. css = greyCSS; // by default
  113.  
  114. if (game === 0) { // NF Games
  115. if (red && blue) css = yellowRedBlueCSS;
  116. else if (red) css = redCSS;
  117. else if (blue) css = blueCSS;
  118. } else if (game === 1) { // CTF Games
  119. if (red && blue) css = redBlueCSS;
  120. else if (red) css = redCSS;
  121. else if (blue) css = blueCSS;
  122. }
  123.  
  124. if (css != oldCSS) {
  125. $("html").css(css);
  126. oldCSS = css;
  127. }
  128.  
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment