Advertisement
MekhiMaraghYT

Diep.io New script 2020

Apr 14th, 2020
32,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. // ==UserScript==
  2. // @name SBB's take on scripting.
  3. // @include *://diep.io/*
  4. // @author SBB
  5. // @description Makes some tanks more powerful (Tri-angle branch, spread shot, penta shot, octo tank, gunner trapper, streamliner).
  6. // @connect diep.io
  7. // @namespace aaa
  8. // @version 0.0.1.20200227000440
  9. // ==/UserScript==
  10.  
  11. /*
  12. How to Use:
  13. Press Shift+R to cycle through the tanks.
  14. Press Shift+Q to disable/enable the script.
  15. Press I to hide the dialog. (The script remains functional, though).
  16. Hold rightclick to activate . For best results, leave autofire off for a bit before doing so.
  17. Note: This calibration may break for Triple Twin, and is unnecessary for Streamliner.
  18. */
  19. (function(){//info
  20. if(window.updateInfo) return;
  21.  
  22.  
  23. var info = {};
  24. var info_container = document.createElement("div");
  25. info_container.style.position = "fixed";
  26. info_container.style.color = "white";
  27. info_container.style["pointer-events"] = "none";
  28. document.body.appendChild(info_container);
  29.  
  30. function toggle_info_container(e){
  31. if(e.key == "i"){
  32. info_container.style.display = info_container.style.display=="block" ? "none" : "block";
  33. }
  34. }
  35. window.addEventListener("keyup", toggle_info_container);
  36.  
  37. window.updateInfo = function(key, value){
  38. if(!value) delete info[key];
  39. else info[key] = value;
  40. var s = "";
  41. for(var _key in info){
  42. s += info[_key] + "\n";
  43. }
  44. info_container.innerText = s;
  45. };
  46. })();
  47.  
  48.  
  49. (function(){
  50. var cycleRate = 0.003125; // ms^-1
  51. var maxAngle = Math.PI * 45 / 180;
  52. var NCANNON = 3;
  53. var angleUnit = maxAngle / (NCANNON - 1);
  54.  
  55. var tankData = [
  56. {name: "Tri-angle", cycleRate: 0.003095, maxAngle: Math.PI * 135 / 180, NCANNON: 2},
  57. {name: "Penta", cycleRate: 0.003095, maxAngle: Math.PI * 45 / 180, NCANNON: 3},
  58. {name: "SpreadShot", cycleRate: 0.001515, maxAngle: Math.PI * 75 / 180, NCANNON: 6},
  59. {name: "Octo", cycleRate: 0.003095, maxAngle: Math.PI * 45 / 180, NCANNON: 2},
  60. {name: "GunnerTrapper",cycleRate: 0.015, maxAngle: Math.PI, NCANNON: 2},
  61. {name: "TripleTwin", cycleRate: 0.003125, maxAngle: Math.PI * 180 / 180, NCANNON: 2},
  62. {name: "Streamliner", cycleRate: 0.0625, maxAngle: Math.PI * 15 / 180, NCANNON: 3},
  63. ];
  64. var tankIndex = 0;
  65.  
  66. var measuring = false;
  67.  
  68. var effective = false;
  69. var frameRequest;
  70.  
  71. var canvas = window.document.getElementById("canvas");
  72.  
  73. var mouseX;
  74. var mouseY;
  75. var a = 0;
  76. var startA = 0;
  77. var artificialMouseMove = false;
  78.  
  79. var disabled = false;
  80.  
  81. function onMouseDown(e){
  82. if(e.button == 2){
  83. if(!effective){
  84. startA = a - 50;
  85. mouseX = e.clientX;
  86. mouseY = e.clientY;
  87. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: mouseX, clientY: mouseY}));
  88. }
  89. effective = true;
  90. }
  91. }
  92.  
  93. function onMouseUp(e){
  94. if(e.button == 2){
  95. if(effective){
  96. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: mouseX, clientY: mouseY}));
  97. }
  98. effective = false;
  99. }
  100. }
  101.  
  102. function onMouseMove(e){
  103. if(effective){
  104. if(!artificialMouseMove){
  105. e.stopPropagation();
  106. mouseX = e.clientX;
  107. mouseY = e.clientY;
  108. }
  109. }else{
  110. mouseX = e.clientX;
  111. mouseY = e.clientY;
  112. }
  113. }
  114.  
  115. function update(_a){
  116. frameRequest = window.requestAnimationFrame(update);
  117. a = _a;
  118.  
  119. if(effective){
  120. var da = a - startA;
  121. var state = Math.floor(cycleRate * da * NCANNON) % (NCANNON * 2);
  122. var state1 = state % NCANNON;
  123. var state2 = Math.floor(state / NCANNON);
  124. var angle = angleUnit * state1 * (state1 % 2 == state2 ? 1 : -1);
  125.  
  126. var cx = window.innerWidth / 2;
  127. var cy = window.innerHeight / 2;
  128. var sin = Math.sin(angle);
  129. var cos = Math.cos(angle);
  130.  
  131. var x = mouseX - cx;
  132. var y = mouseY - cy;
  133. var _x = cos * x - sin * y;
  134. var _y = sin * x + cos * y;
  135. x = _x + cx;
  136. y = _y + cy;
  137.  
  138. artificialMouseMove = true;
  139. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x, clientY: y}));
  140. artificialMouseMove = false;
  141. }
  142. }
  143.  
  144. function onKeyUp(e){
  145. if(e.key == "Q"){
  146. disabled = !disabled;
  147. if(disabled){
  148. if(measuring){
  149. cycleRate = 1 / measure.terminate();
  150. measuring = false;
  151. } else stop();
  152. }else start();
  153. window.updateInfo && window.updateInfo("off", disabled ? "Disabled." : null);
  154. return;
  155. }
  156.  
  157. if(disabled) return;
  158.  
  159. if(e.key == "R"){
  160. changeTank((tankIndex + 1) % tankData.length);
  161. }
  162. }
  163.  
  164. function changeTank(index){
  165. var data = tankData[index];
  166. tankIndex = index;
  167.  
  168. cycleRate = data.cycleRate; // ms^-1
  169. maxAngle = data.maxAngle;
  170. NCANNON = data.NCANNON;
  171. angleUnit = maxAngle / (NCANNON - 1);
  172. window.updateInfo && window.updateInfo("changeTank", "Tank: " + data.name);
  173. }
  174.  
  175. function init(){
  176. window.addEventListener("keyup", onKeyUp);
  177. start();
  178. changeTank(0);
  179. }
  180.  
  181. function start(){
  182. canvas.addEventListener("mousedown", onMouseDown);
  183. canvas.addEventListener("mouseup", onMouseUp);
  184. window.addEventListener("mousemove", onMouseMove, true);
  185. frameRequest = window.requestAnimationFrame(update);
  186. }
  187.  
  188. function stop(){
  189. canvas.removeEventListener("mousedown", onMouseDown);
  190. canvas.removeEventListener("mouseup", onMouseUp);
  191. window.removeEventListener("mousemove", onMouseMove, true);
  192. window.cancelAnimationFrame(frameRequest);
  193. effective = false;
  194. }
  195.  
  196.  
  197. init();
  198.  
  199. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement