Krunker.IO AimLock

Locks aim to the nearest player in krunker.io

  1. // ==UserScript==
  2. // @name Krunker.IO AimLock
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.47
  5. // @description Locks aim to the nearest player in krunker.io
  6. // @author Hrishidagoar
  7. // @match *://krunker.io/*
  8. // @icon https://www.google.com/s2/favicons?domain=krunker.io
  9. // @grant none
  10. // @run-at document-end
  11. // @require https://unpkg.com/three@latest/build/three.min.js
  12. // @antifeature ads
  13. // ==/UserScript==
  14.  
  15. const tempVector = new THREE.Vector3();
  16.  
  17. const tempObject = new THREE.Object3D();
  18.  
  19. tempObject.rotation.order = 'YXZ';
  20.  
  21. const geometry = new THREE.SphereGeometry( 10 );
  22.  
  23. const material = new THREE.MeshLambertMaterial( {
  24. color: 'red',
  25. wireframe: true
  26. } );
  27.  
  28. const meshes = [];
  29.  
  30. let isActive = true;
  31.  
  32. let scene;
  33.  
  34. WeakMap.prototype.set = new Proxy( WeakMap.prototype.set, {
  35. apply( target, thisArgs, args ) {
  36.  
  37. if ( args[ 0 ].type === 'Scene' && args[ 0 ].name === 'Main' ) {
  38.  
  39. scene = args[ 0 ];
  40.  
  41. }
  42.  
  43. return Reflect.apply( ...arguments );
  44.  
  45. }
  46. } );
  47.  
  48. function animate() {
  49.  
  50. window.requestAnimationFrame( animate );
  51.  
  52. if ( isActive === false || scene === undefined ) {
  53.  
  54. return;
  55.  
  56. }
  57.  
  58. const players = [];
  59.  
  60. let myPlayer;
  61.  
  62. for ( let i = 0; i < scene.children.length; i ++ ) {
  63.  
  64. const child = scene.children[ i ];
  65.  
  66. if ( child.type === 'Object3D' ) {
  67.  
  68. try {
  69.  
  70. if ( child.children[ 0 ].children[ 0 ].type === 'PerspectiveCamera' ) {
  71.  
  72. myPlayer = child;
  73.  
  74. } else {
  75.  
  76. players.push( child );
  77.  
  78. }
  79.  
  80. } catch ( err ) {}
  81.  
  82. }
  83.  
  84. }
  85.  
  86. if ( players.length < 2 ) {
  87.  
  88. return;
  89.  
  90. }
  91.  
  92. let targetPlayer;
  93. let minDistance = Infinity;
  94.  
  95. for ( let i = 0; i < players.length; i ++ ) {
  96.  
  97. const player = players[ i ];
  98.  
  99. if ( player.position.x === myPlayer.position.x && player.position.z === myPlayer.position.z ) {
  100.  
  101. continue;
  102.  
  103. }
  104.  
  105. if ( player.firstTime !== true ) {
  106.  
  107. const mesh = new THREE.Mesh( geometry, material );
  108.  
  109. meshes.push( mesh );
  110.  
  111. player.add( mesh );
  112.  
  113. player.firstTime = true;
  114.  
  115. }
  116.  
  117. const distance = player.position.distanceTo( myPlayer.position );
  118.  
  119. if ( distance < minDistance ) {
  120.  
  121. targetPlayer = player;
  122.  
  123. minDistance = distance;
  124.  
  125. }
  126.  
  127. }
  128.  
  129. if ( targetPlayer === undefined ) {
  130.  
  131. return;
  132.  
  133. }
  134.  
  135. tempVector.setScalar( 0 );
  136.  
  137. targetPlayer.children[ 0 ].children[ 0 ].localToWorld( tempVector );
  138.  
  139. tempObject.position.copy( myPlayer.position );
  140.  
  141. tempObject.lookAt( tempVector );
  142.  
  143. myPlayer.children[ 0 ].rotation.x = - tempObject.rotation.x;
  144. myPlayer.rotation.y = tempObject.rotation.y + Math.PI;
  145.  
  146. }
  147.  
  148. animate();
  149.  
  150. window.addEventListener( 'keydown', function ( event ) {
  151.  
  152. if ( String.fromCharCode( event.keyCode ) === 'G' ) {
  153.  
  154. isActive = ! isActive;
  155.  
  156. for ( let i = 0; i < meshes.length; i ++ ) {
  157.  
  158. meshes[ i ].visible = isActive;
  159.  
  160. }
  161.  
  162. }
  163.  
  164. } );
  165.  
  166. const shouldShowAd = window.localStorage.showAd !== false && new URLSearchParams( window.location.search ).get( 'showAd' ) !== 'false';
  167.  
  168. const el = document.createElement( 'div' );
  169.  
  170. el.innerHTML = `<style>
  171.  
  172. .dialog {
  173. position: absolute;
  174. left: 50%;
  175. top: 50%;
  176. padding: 20px;
  177. background: rgba(0, 0, 0, 0.8);
  178. border: 6px solid rgba(0, 0, 0, 0.2);
  179. color: #fff;
  180. transform: translate(-50%, -50%);
  181. text-align: center;
  182. z-index: 999999;
  183. }
  184.  
  185. .dialog * {
  186. color: #fff;
  187. }
  188.  
  189. .close {
  190. position: absolute;
  191. right: 5px;
  192. top: 5px;
  193. width: 20px;
  194. height: 20px;
  195. opacity: 0.5;
  196. cursor: pointer;
  197. }
  198.  
  199. .close:before, .close:after {
  200. content: ' ';
  201. position: absolute;
  202. left: 50%;
  203. top: 50%;
  204. width: 100%;
  205. height: 20%;
  206. transform: translate(-50%, -50%) rotate(-45deg);
  207. background: #fff;
  208. }
  209.  
  210. .close:after {
  211. transform: translate(-50%, -50%) rotate(45deg);
  212. }
  213.  
  214. .close:hover {
  215. opacity: 1;
  216. }
  217.  
  218. .btn {
  219. cursor: pointer;
  220. padding: 0.5em;
  221. background: red;
  222. border: 3px solid rgba(0, 0, 0, 0.2);
  223. margin-bottom: 5px;
  224. }
  225.  
  226. .btn:active {
  227. transform: scale(0.8);
  228. }
  229.  
  230. </style>
  231. <div class="dialog">${shouldShowAd ? `<big>Loading ad...</big>` : `<div class="close" onclick="this.parentNode.style.display='none';"></div>
  232. <big>== Aimlocker ==</big>
  233. <br>
  234. <br>
  235. [G] to toggle aimlock
  236. <br>
  237. <br>
  238. By Zertalious
  239. <br>
  240. <br>
  241. <div class="btn" onclick="window.open('https://discord.gg/K24Zxy88VM')">Discord</div>
  242. <div class="btn" onclick="window.open('https://www.instagram.com/zertalious/', '_blank')">Instagram</div>
  243. <div class="btn" onclick="window.open('https://twitter.com/Zertalious', '_blank')">Twitter</div>
  244. <div class="btn" onclick="window.open('https://greasyfork.org/en/users/662330-zertalious', '_blank')">More scripts</div>
  245. ` }
  246. </div>`;
  247.  
  248. while ( el.children.length > 0 ) {
  249.  
  250. document.body.appendChild( el.children[ 0 ] );
  251.  
  252. }
  253.