Diep.io Auto-leveler Bot (Improved)

Improved auto-leveler bot for Diep.io. Press Q to toggle.

  1. // ==UserScript==
  2. // @name Diep.io Auto-leveler Bot (Improved)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Improved auto-leveler bot for Diep.io. Press Q to toggle.
  6. // @author Mi300 (Improved by AI)
  7. // @match https://diep.io/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @license Apache License 2.0
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. const ARENA_WIDTH = 26000;
  15. const ARENA_HEIGHT = 26000;
  16. const T4_BASE_WIDTH = 3900;
  17. const T4_BASE_HEIGHT = 3900;
  18.  
  19. const T2_BASES = [
  20. { id: 0, name: "blue", hex: "#00b2e1", x: 0, y: 0, cX: 0, cY: 0, dirX: 1, dirY: 1 },
  21. { id: 3, name: "red", hex: "#f14e54", x: 23500, y: 0, cX: ARENA_WIDTH, cY: ARENA_HEIGHT, dirX: -1, dirY: 1 },
  22. ];
  23.  
  24. const T4_BASES = [
  25. { id: 0, name: "blue", hex: "#00b2e1", x: 0, y: 0, cX: 0, cY: 0, dirX: 1, dirY: 1 },
  26. { id: 1, name: "purple", hex: "#bf7ff5", x: 22100, y: 0, cX: 0, cY: ARENA_HEIGHT, dirX: -1, dirY: 1 },
  27. { id: 2, name: "green", hex: "#00e16e", x: 0, y: 22100, cX: ARENA_WIDTH, cY: 0, dirX: 1, dirY: -1 },
  28. { id: 3, name: "red", hex: "#f14e54", x: 22100, y: 22100, cX: ARENA_WIDTH, cY: ARENA_HEIGHT, dirX: -1, dirY: -1 },
  29. ];
  30.  
  31. alert("Auto Leveler: Press Q to toggle on / off.");
  32.  
  33. let OMG = setInterval(function () {
  34. if (!window.input) return;
  35. clearInterval(OMG);
  36.  
  37. const canvas = document.getElementById("canvas");
  38. const ctx = canvas.getContext("2d");
  39. let baseArea = null;
  40. let inBase = false;
  41. let toggled = false;
  42. let is2T = false;
  43. let lastCheck = Date.now();
  44. let minimapArrow = [0, 0];
  45. let minimapPos = [0, 0];
  46. let minimapDim = [0, 0];
  47. let playerPos = [0, 0];
  48.  
  49. document.addEventListener("keydown", function (e) {
  50. if (e.key === "q") {
  51. toggled = !toggled;
  52. setTimeout(() => {
  53. input.key_up(87); // W
  54. input.key_up(83); // S
  55. input.key_up(65); // A
  56. input.key_up(68); // D
  57. }, 200);
  58. }
  59. });
  60.  
  61. function getCentre(vertices) {
  62. return vertices.reduce((acc, vertex) => [acc[0] + vertex[0], acc[1] + vertex[1]], [0, 0])
  63. .map(sum => sum / vertices.length);
  64. }
  65.  
  66. function getDist(t1, t2) {
  67. const distX = t1[0] - t2[0];
  68. const distY = t1[1] - t2[1];
  69. return [Math.hypot(distX, distY), distX, distY];
  70. }
  71.  
  72. function getClosest(entities) {
  73. return entities.reduce((acc, entity) => {
  74. const dist = getDist(entity[0], [canvas.width / 2, canvas.height / 2])[0];
  75. return dist < getDist(acc[0], [canvas.width / 2, canvas.height / 2])[0] ? entity : acc;
  76. }, [[0, 0], Infinity]);
  77. }
  78.  
  79. function move(aimTarget, moveTarget) {
  80. if (!window.input || !window.input.should_prevent_unload()) return;
  81.  
  82. input.mouse(...aimTarget);
  83. input.key_down(1); // Shoot
  84.  
  85. const moveTargetDistance = getDist(moveTarget, [canvas.width / 2, canvas.height / 2]);
  86.  
  87. // Horizontal movement
  88. if (moveTargetDistance[1] > 0) {
  89. input.key_down(68); // D
  90. input.key_up(65); // A
  91. } else if (moveTargetDistance[1] < 0) {
  92. input.key_up(68); // D
  93. input.key_down(65); // A
  94. } else {
  95. input.key_up(68); // D
  96. input.key_up(65); // A
  97. }
  98.  
  99. // Vertical movement
  100. if (moveTargetDistance[2] > 0) {
  101. input.key_down(83); // S
  102. input.key_up(87); // W
  103. } else if (moveTargetDistance[2] < 0) {
  104. input.key_up(83); // S
  105. input.key_down(87); // W
  106. } else {
  107. input.key_up(83); // S
  108. input.key_up(87); // W
  109. }
  110. }
  111.  
  112. function main() {
  113. if (!toggled) return;
  114. window.requestAnimationFrame(main);
  115.  
  116. playerPos = getPlayerPos();
  117. getBase(playerPos);
  118.  
  119. if (Date.now() - lastCheck > 2000) is2T = true;
  120. else is2T = false;
  121.  
  122. if (!input.should_prevent_unload()) {
  123. window.input.try_spawn(localStorage.name);
  124. }
  125.  
  126. getCurrentTargets();
  127. }
  128.  
  129. window.requestAnimationFrame(main);
  130. }, 400);