Krunker.IO AimLock

Locks aim to the nearest player in krunker.io

目前为 2021-09-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Krunker.IO AimLock
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description Locks aim to the nearest player in krunker.io
  6. // @author Zertalious (Zert)
  7. // @match *://krunker.io/*
  8. // @icon https://www.google.com/s2/favicons?domain=krunker.io
  9. // @grant none
  10. // @require https://unpkg.com/three@latest/build/three.min.js
  11. // ==/UserScript==
  12.  
  13. const tempVector = new THREE.Vector3();
  14.  
  15. const tempObject = new THREE.Object3D();
  16.  
  17. tempObject.rotation.order = 'YXZ';
  18.  
  19. const geometry = new THREE.SphereGeometry( 10 );
  20.  
  21. const material = new THREE.MeshLambertMaterial( {
  22. color: 'red',
  23. wireframe: true
  24. } );
  25.  
  26. const meshes = [];
  27.  
  28. let isActive = true;
  29.  
  30. let scene;
  31.  
  32. WeakMap.prototype.set = new Proxy( WeakMap.prototype.set, {
  33. apply( target, thisArgs, args ) {
  34.  
  35. if ( args[ 0 ].type === 'Scene' && args[ 0 ].name === 'Main' ) {
  36.  
  37. scene = args[ 0 ];
  38.  
  39. }
  40.  
  41. return Reflect.apply( ...arguments );
  42.  
  43. }
  44. } );
  45.  
  46. function animate() {
  47.  
  48. window.requestAnimationFrame( animate );
  49.  
  50. if ( isActive === false || scene === undefined ) {
  51.  
  52. return;
  53.  
  54. }
  55.  
  56. const players = [];
  57.  
  58. let myPlayer;
  59.  
  60. for ( let i = 0; i < scene.children.length; i ++ ) {
  61.  
  62. const child = scene.children[ i ];
  63.  
  64. if ( child.type === 'Object3D' ) {
  65.  
  66. try {
  67.  
  68. if ( child.children[ 0 ].children[ 0 ].type === 'PerspectiveCamera' ) {
  69.  
  70. myPlayer = child;
  71.  
  72. } else {
  73.  
  74. players.push( child );
  75.  
  76. }
  77.  
  78. } catch ( err ) {}
  79.  
  80. }
  81.  
  82. }
  83.  
  84. if ( players.length < 2 ) {
  85.  
  86. return;
  87.  
  88. }
  89.  
  90. let targetPlayer;
  91. let minDistance = Infinity;
  92.  
  93. for ( let i = 0; i < players.length; i ++ ) {
  94.  
  95. const player = players[ i ];
  96.  
  97. if ( player.position.x === myPlayer.position.x && player.position.z === myPlayer.position.z ) {
  98.  
  99. continue;
  100.  
  101. }
  102.  
  103. if ( player.firstTime !== true ) {
  104.  
  105. const mesh = new THREE.Mesh( geometry, material );
  106.  
  107. meshes.push( mesh );
  108.  
  109. player.add( mesh );
  110.  
  111. player.firstTime = true;
  112.  
  113. }
  114.  
  115. const distance = player.position.distanceTo( myPlayer.position );
  116.  
  117. if ( distance < minDistance ) {
  118.  
  119. targetPlayer = player;
  120.  
  121. minDistance = distance;
  122.  
  123. }
  124.  
  125. }
  126.  
  127. if ( targetPlayer === undefined ) {
  128.  
  129. return;
  130.  
  131. }
  132.  
  133. tempVector.setScalar( 0 );
  134.  
  135. targetPlayer.children[ 0 ].children[ 0 ].localToWorld( tempVector );
  136.  
  137. tempObject.position.copy( myPlayer.position );
  138.  
  139. tempObject.lookAt( tempVector );
  140.  
  141. myPlayer.children[ 0 ].rotation.x = - tempObject.rotation.x;
  142. myPlayer.rotation.y = tempObject.rotation.y + Math.PI;
  143.  
  144. }
  145.  
  146. animate();
  147.  
  148. window.addEventListener( 'keydown', function ( event ) {
  149.  
  150. if ( String.fromCharCode( event.keyCode ) === 'G' ) {
  151.  
  152. isActive = ! isActive;
  153.  
  154. for ( let i = 0; i < meshes.length; i ++ ) {
  155.  
  156. meshes[ i ].visible = isActive;
  157.  
  158. }
  159.  
  160. }
  161.  
  162. } )