Working AFK script 2024!

set Afk spot with Q, toggle afk with R

  1. // ==UserScript==
  2. // @name Working AFK script 2024!
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description set Afk spot with Q, toggle afk with R
  6. // @author r!PsAw
  7. // @match https://diep.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=diep.io
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. //minimap Arrow Hook
  14. function windowScaling() {
  15. const a = canvas.height / 1080;
  16. const b = canvas.width / 1920;
  17. return b < a ? a : b;
  18. }
  19.  
  20. //credits to mi300
  21. function hook(target, callback){
  22.  
  23. function check(){
  24. window.requestAnimationFrame(check)
  25.  
  26. const func = CanvasRenderingContext2D.prototype[target]
  27.  
  28. if(func.toString().includes(target)){
  29.  
  30. CanvasRenderingContext2D.prototype[target] = new Proxy (func, {
  31. apply (method, thisArg, args) {
  32. callback(thisArg, args)
  33.  
  34. return Reflect.apply (method, thisArg, args)
  35. }
  36. });
  37. }
  38. }
  39. window.requestAnimationFrame(check)
  40. }
  41.  
  42. let minimapArrow = [0, 0];
  43. let square_pos = [0, 0]
  44. let leaderArrow = [0, 0];
  45. let minimapPos = [0, 0];
  46. let minimapDim = [0, 0];
  47.  
  48. let calls = 0;
  49. let points = [];
  50.  
  51. hook('beginPath', function(thisArg, args){
  52. calls = 1;
  53. points = [];
  54. });
  55. hook('moveTo', function(thisArg, args){
  56. if (calls == 1) {
  57. calls+=1;
  58. points.push(args)
  59. } else {
  60. calls = 0;
  61. }
  62. });
  63. hook('lineTo', function(thisArg, args){
  64. if (calls >= 2 && calls <= 6) {
  65. calls+=1;
  66. points.push(args)
  67. } else {
  68. calls = 0;
  69. }
  70. });
  71.  
  72.  
  73. function getCentre(vertices) {
  74. let centre = [0, 0];
  75. vertices.forEach (vertex => {
  76. centre [0] += vertex[0]
  77. centre [1] += vertex[1]
  78. });
  79. centre[0] /= vertices.length;
  80. centre[1] /= vertices.length;
  81. return centre;
  82. }
  83.  
  84. hook('fill', function(thisArg, args){
  85. if(calls >= 4 && calls <= 6) {
  86. if(thisArg.fillStyle === "#000000" && thisArg.globalAlpha > 0.9){
  87. minimapArrow = getCentre(points);
  88. window.M_X = minimapArrow[0];
  89. window.M_Y = minimapArrow[1];
  90. square_pos = [minimapArrow[0]-(12.5*windowScaling()), minimapArrow[1]-(7*windowScaling())];
  91. return;
  92. }else if(thisArg.fillStyle === "#000000" && thisArg.globalAlpha === 0.3499999940395355 || thisArg.fillStyle === window.choose_color && thisArg.globalAlpha === 0.3499999940395355){
  93. thisArg.fillStyle = window.choose_color;
  94. leaderArrow = getCentre(points);
  95. window.L_X = leaderArrow[0];
  96. window.L_Y = leaderArrow[1];
  97. return;
  98. }
  99. } else {
  100. calls = 0;
  101. }
  102. });
  103.  
  104. hook('strokeRect', function(thisArg, args) {
  105. const t = thisArg.getTransform();
  106. minimapPos = [t.e, t.f];
  107. minimapDim = [t.a, t.d];
  108. });
  109.  
  110.  
  111. //key press functions
  112. const RAW_MAPPING = [
  113. "KeyA",
  114. "KeyB",
  115. "KeyC",
  116. "KeyD",
  117. "KeyE",
  118. "KeyF",
  119. "KeyG",
  120. "KeyH",
  121. "KeyI",
  122. "KeyJ",
  123. "KeyK",
  124. "KeyL",
  125. "KeyM",
  126. "KeyN",
  127. "KeyO",
  128. "KeyP",
  129. "KeyQ",
  130. "KeyR",
  131. "KeyS",
  132. "KeyT",
  133. "KeyU",
  134. "KeyV",
  135. "KeyW",
  136. "KeyX",
  137. "KeyY",
  138. "KeyZ",
  139. "ArrowUp",
  140. "ArrowLeft",
  141. "ArrowDown",
  142. "ArrowRight",
  143. "Tab",
  144. "Enter",
  145. "NumpadEnter",
  146. "ShiftLeft",
  147. "ShiftRight",
  148. "Space",
  149. "Numpad0",
  150. "Numpad1",
  151. "Numpad2",
  152. "Numpad3",
  153. "Numpad4",
  154. "Numpad5",
  155. "Numpad6",
  156. "Numpad7",
  157. "Numpad8",
  158. "Numpad9",
  159. "Digit0",
  160. "Digit1",
  161. "Digit2",
  162. "Digit3",
  163. "Digit4",
  164. "Digit5",
  165. "Digit6",
  166. "Digit7",
  167. "Digit8",
  168. "Digit9",
  169. "F2",
  170. "End",
  171. "Home",
  172. "Semicolon",
  173. "Comma",
  174. "NumpadComma",
  175. "Period",
  176. "Backslash",
  177. ];
  178.  
  179. function key_down(keyString) {
  180. const index = RAW_MAPPING.indexOf(keyString);
  181. if (index === -1) {
  182. console.error(`Invalid key string: ${keyString}`);
  183. return;
  184. }
  185. const result = index + 1; // Add 1 to the index as per your requirement
  186. input.onKeyDown(result);
  187. }
  188.  
  189. function key_up(keyString) {
  190. const index = RAW_MAPPING.indexOf(keyString);
  191. if (index === -1) {
  192. console.error(`Invalid key string: ${keyString}`);
  193. return;
  194. }
  195. const result = index + 1; // Add 1 to the index as per your requirement
  196. input.onKeyUp(result);
  197. }
  198.  
  199. //AFK logic
  200. let afk = false;
  201. let moving = false;
  202. let your_pos = {x: 0, y: 0};
  203. let goal = {x: 0, y: 0};
  204.  
  205. document.onkeydown = function(e) {
  206. //console.log(e.key);
  207. if(e.key === "q" || e.key === "Q"){
  208. set_goal(your_pos.x, your_pos.y);
  209. }else if(e.key === "r" || e.key === "R"){
  210. afk = !afk;
  211. }
  212. };
  213.  
  214. function get_your_pos(){
  215. window.requestAnimationFrame(get_your_pos);
  216. your_pos.x = minimapArrow[0];
  217. your_pos.y = minimapArrow[1];
  218. }
  219. window.requestAnimationFrame(get_your_pos);
  220.  
  221. function set_goal(x, y){
  222. console.log("set_goal");
  223. goal.x = x;
  224. goal.y = y;
  225. }
  226.  
  227. function move_to_goal() {
  228. console.log(`YOU: x: ${your_pos.x} y: ${your_pos.y} GOAL x: ${goal.x} y: ${goal.y}`);
  229. if (afk) {
  230. if (your_pos.x > goal.x) {
  231. key_up("KeyD");
  232. key_down("KeyA");
  233. } else {
  234. key_up("KeyA");
  235. key_down("KeyD");
  236. }
  237. if (your_pos.y > goal.y) {
  238. key_up("KeyS");
  239. key_down("KeyW");
  240. } else {
  241. key_up("KeyW");
  242. key_down("KeyS");
  243. }
  244. moving = true;
  245. }else{
  246. if(moving){
  247. key_up("KeyW");
  248. key_up("KeyA");
  249. key_up("KeyS");
  250. key_up("KeyD");
  251. moving = false;
  252. }
  253. }
  254. }
  255. setInterval(move_to_goal, 100);