TagPro Flair Trails and Spin

Have sick trails for all your flairs just like the arc reactor. (Without having to level up) But wait there's more. You can also have your flairs spin like the level 4 donor flair absolutely free.

  1. // ==UserScript==
  2. // @name TagPro Flair Trails and Spin
  3. // @version 0.3.1
  4. // @description Have sick trails for all your flairs just like the arc reactor. (Without having to level up) But wait there's more. You can also have your flairs spin like the level 4 donor flair absolutely free.
  5. // @match *://*.koalabeast.com/*
  6. // @author Pindelta
  7. // @supportURL https://www.reddit.com/message/compose/?to=Pindelta
  8. // @require https://greasyfork.org/scripts/371240-TPUL.js
  9. // @namespace https://github.com/Pindelta/TagPro-Flair-Trails-and-Spin
  10.  
  11. // ==/UserScript==
  12.  
  13. // - v0.3.1: code refactoring and cleanup
  14. // - v0.3.0: added settings menu in the in-game settings
  15. // - v0.2.2: fixed arc reactor flair not showing it's original trail, you don't need to put your display name anymore
  16. // - v0.2.1: changed included domains to *://*.koalabeast.com/*, which should encompass all koalabeast url variations
  17. // - v0.2.0: added https://koalabeast.com* to list of domains, added option to apply spin effect to all balls
  18.  
  19. // ========= SETTINGS =========
  20. // All settings can be configured from the settings in TagPro!
  21.  
  22. // ========= END OF SETTINGS =========
  23.  
  24. const customTrailDefinition = {
  25. acceleration: { x: 0, y: 0 },
  26. addAtBack: false,
  27. alpha: { start: 1, end: 0 },
  28. blendMode: "normal",
  29. color: { start: "#ffffff", end: "#ffffff" },
  30. emitterLifetime: -1,
  31. frequency: 0.001,
  32. lifetime: { min: 0.25, max: 0.25 },
  33. maxParticles: 500,
  34. maxSpeed: 0,
  35. noRotation: true,
  36. pos: { x: 0, y: 0 },
  37. rotationSpeed: { min: 0, max: 0 },
  38. scale: { start: 1, end: 0.25, minimumScaleMultiplier: 1 },
  39. spawnType: "point",
  40. speed: { start: 0, end: 0, minimumSpeedMultiplier: 1 },
  41. startRotation: { min: 0, max: 0 },
  42. };
  43.  
  44. /* global tagpro, tagproConfig, $, tpul */
  45.  
  46. tagpro.ready(function () {
  47. if (tpul.playerLocation == "profile") {
  48. $("#settings, .card:first").before(
  49. `<div id=flair-trail-and-spin-select class="profile-settings block">
  50. <h3 class=header-title>Flair Trail and Spin</h3>
  51. <form class=form-horizontal>
  52. <div class=form-group></div>
  53. </div>
  54. <hr>
  55. <div id=save-group class=form-group></div>`
  56. );
  57.  
  58. $("#flair-trail-and-spin-select .form-group:first").append(
  59. `<label class="col-sm-4 control-label">Effects</label>
  60. <div class="col-sm-8" style="margin-bottom: 15px">
  61. <div class="checkbox">
  62. <label for="spin">
  63. <input id="spin" name="spin" type="checkbox" checked="">
  64. Enable Flair Spin
  65. </label>
  66. </div>
  67. <div class="checkbox">
  68. <label for="trail">
  69. <input id="trail" name="trail" type="checkbox" checked="">
  70. Enable Flair Trail
  71. </label>
  72. </div>
  73. </div>
  74. <label class="col-sm-4 control-label">Apply Effects To All Players</label>
  75. <div class="col-sm-8">
  76. <div class="checkbox">
  77. <label for="spinToAll">
  78. <input id="spinToAll" name="spinToAll" type="checkbox" checked="">
  79. Flair Spin
  80. </label>
  81. </div>
  82. </div>`
  83. );
  84.  
  85. $("#flair-trail-and-spin-select")
  86. .find("input")
  87. .each(function () {
  88. var name = $(this).prop("name");
  89. $(this).prop("checked", $.cookie(name) == "true");
  90. })
  91. .prop("disabled", false);
  92.  
  93. $("#save-group").append(
  94. '<div class="col-sm-12 text-right"><div id=script-status style="display: none;">Settings saved!</div><button id="scriptScriptSettings" class="btn" type="button">Save Script Settings'
  95. );
  96. $("#script-status").css("margin-bottom", "20px");
  97.  
  98. $("#save-group button").on("click", function () {
  99. // Save settings to site cookies
  100. $("#flair-trail-and-spin-select")
  101. .find("input")
  102. .each(function () {
  103. var name = $(this).prop("name"),
  104. checked = $(this).prop("checked");
  105. $.cookie(name, checked, {
  106. expires: 36500,
  107. path: "/",
  108. domain: tagproConfig.cookieHost,
  109. });
  110. });
  111.  
  112. // Show text to indicate settings were saved
  113. $("#script-status").slideDown();
  114. setTimeout(function () {
  115. $("#script-status").slideUp();
  116. }, 3e3);
  117. });
  118. }
  119.  
  120. if (tpul.playerLocation === "game") {
  121. const spinFlair = $.cookie("spin") ? $.cookie("spin") : false;
  122. const useTrail = $.cookie("trail") ? $.cookie("trail") : false;
  123. const addSpinToAllBalls = $.cookie("spinToAll")
  124. ? $.cookie("spinToAll")
  125. : false;
  126.  
  127. // Override the drawFlair function
  128. tagpro.renderer.drawFlair = function (player) {
  129. const isYourBall = player.id === tagpro.playerId; // check if this is your ball
  130.  
  131. player.sprites.flair &&
  132. player.sprites.flair.flairName !== player.flair &&
  133. (player.sprites.info.removeChild(player.sprites.flair),
  134. (player.sprites.flair = null));
  135.  
  136. if (player.flair && !player.sprites.flair) {
  137. var n = "flair-" + player.flair.x + "," + player.flair.y,
  138. r = tagpro.renderer.getFlairTexture(n, player.flair);
  139. (player.sprites.flair = new PIXI.Sprite(r)),
  140. (player.sprites.flair.pivot.x = 8),
  141. (player.sprites.flair.pivot.y = 8),
  142. (player.sprites.flair.x = 20),
  143. (player.sprites.flair.y = -9),
  144. player.sprites.info.addChild(player.sprites.flair),
  145. (player.sprites.flair.flairName = player.flair),
  146. (player.sprites.rotation = 0),
  147. (player.rotateFlairSpeed = 0);
  148.  
  149. const shouldActivateTrail = useTrail && isYourBall; // we should activate the trail if the setting is set to true and this is your ball
  150. const isArcReactorFlair = player.flair.description === "Arc Reactor";
  151. if (!tagpro.renderer.options.disableParticles) {
  152. if (isArcReactorFlair) {
  153. createPixiEmitter(
  154. tagpro.renderer.particleTexture,
  155. tagpro.particleDefinitions.arcReactor,
  156. player
  157. );
  158. } else if (shouldActivateTrail) {
  159. createPixiEmitter(r, customTrailDefinition, player);
  160. }
  161. }
  162. }
  163.  
  164. const shouldActivateSpin = spinFlair && (isYourBall || addSpinToAllBalls);
  165. if (
  166. player.sprites.flair &&
  167. (player.flair.description === "Level 4 Donor" || shouldActivateSpin)
  168. ) {
  169. player.lastFrame ||
  170. (player.lastFrame = { "s-captures": 0, "s-tags": 0 });
  171. if (
  172. player.lastFrame["s-captures"] !== player["s-captures"] ||
  173. player.lastFrame["s-tags"] !== player["s-tags"]
  174. )
  175. (player.tween = new Tween(0.4, -0.38, 4e3, "quadOut")),
  176. (player.rotateFlairSpeed = player.tween.getValue());
  177. player.rotateFlairSpeed > 0.02 &&
  178. (player.rotateFlairSpeed = player.tween.getValue()),
  179. (player.rotateFlairSpeed = Math.max(0.02, player.rotateFlairSpeed)),
  180. (player.sprites.flair.rotation += player.rotateFlairSpeed),
  181. (player.lastFrame["s-captures"] = player["s-captures"]),
  182. (player.lastFrame["s-tags"] = player["s-tags"]);
  183. }
  184.  
  185. !player.flair &&
  186. player.sprites.flair &&
  187. player.sprites.info.removeChild(player.sprites.flair);
  188.  
  189. if (player.flairEmitter) {
  190. var s = player.sprite.visible && !player.dead,
  191. o = s;
  192.  
  193. (player.flairEmitter.emit = s),
  194. player.flairEmitter.updateOwnerPos(player.x + 20, player.y - 9),
  195. o && player.flairEmitter.resetPositionTracking();
  196. }
  197. };
  198.  
  199. function createPixiEmitter(particleTexture, particleDefinition, player) {
  200. var i = new PIXI.particles.Emitter(
  201. tagpro.renderer.layers.midground,
  202. [particleTexture],
  203. particleDefinition
  204. );
  205. tagpro.renderer.emitters.push(i),
  206. (player.flairEmitter = i),
  207. (player.flairEmitter.keep = !0);
  208. }
  209. }
  210. });