Guest User

Untitled

a guest
Jul 26th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Server Count
  3. // @version 0
  4. // @description The 2nd best userscript to ever grace the TagPro community.
  5. // @include http://*.koalabeast.com:*
  6. // @author Zagd
  7. // ==/UserScript==
  8.  
  9. //README
  10. //Sends an in-game message with server player/game count information, when someone (including yourself) send '!sc' into the game chat.
  11.  
  12. var timeout; // Global timeout function reference.
  13.  
  14. tagpro.ready(function() {
  15. var now;
  16. var lastMessage = 0;
  17. var timeDiff;
  18. tagpro.socket.on('chat', function(data) {
  19. if (data.message == "!sc") {
  20. var myId = tagpro.playerId;
  21.  
  22. // 20 second cooldown.
  23. now = new Date();
  24. timeDiff = now - lastMessage;
  25. if (timeDiff > 20000 || lastMessage === 0) {
  26.  
  27. server = window.location.href.substring(window.location.href.indexOf('tagpro-')+7, window.location.href.indexOf('.koalabeast.com'));
  28. $.ajax({
  29. url: "http://tagpro-" + server + ".koalabeast.com/stats",
  30. type: "get",
  31. dataType: "jsonp",
  32. success: function(stats) {
  33. theMessage = "On " + server.charAt(0).toUpperCase() + server.slice(1) + ", there are currently " + stats.players + " players and " + stats.games + " games.";
  34. }
  35. });
  36.  
  37. // Delay the sending by 500 + 100 * myId, so that each player in game with this script will send at different times.
  38. timeout = setTimeout(function(){tagpro.socket.emit("chat",{message:theMessage,toAll:true});}, 500 + 100 * myId);
  39.  
  40. lastMessage = new Date();
  41. }
  42. }
  43. if (/^On .*, there are currently .* players and .* games.$/.test(data.message)) {
  44. clearTimeout(timeout);
  45. }
  46. });
  47. });
Add Comment
Please, Sign In to add comment