Krunker.IO AimLock

Locks aim to the nearest player in krunker.io

当前为 2021-11-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Krunker.IO AimLock
// @namespace    http://tampermonkey.net/
// @version      0.0.3
// @description  Locks aim to the nearest player in krunker.io
// @author       Zertalious (Zert)
// @match        *://krunker.io/*
// @icon         https://www.google.com/s2/favicons?domain=krunker.io
// @grant        none
// @require      https://unpkg.com/three@latest/build/three.min.js
// ==/UserScript==

const tempVector = new THREE.Vector3();

const tempObject = new THREE.Object3D();

tempObject.rotation.order = 'YXZ';

const geometry = new THREE.SphereGeometry( 10 );

const material = new THREE.MeshLambertMaterial( { 
	color: 'red', 
	wireframe: true 
} );

const meshes = [];

let isActive = true;

let scene;

WeakMap.prototype.set = new Proxy( WeakMap.prototype.set, {
	apply( target, thisArgs, args ) {

		if ( args[ 0 ].type === 'Scene' && args[ 0 ].name === 'Main' ) {

			scene = args[ 0 ];

		}

		return Reflect.apply( ...arguments );

	}
} );

function animate() {

	window.requestAnimationFrame( animate );

	if ( isActive === false || scene === undefined ) {

		return;

	}

	const players = [];

	let myPlayer;

	for ( let i = 0; i < scene.children.length; i ++ ) {

		const child = scene.children[ i ];

		if ( child.type === 'Object3D' ) {

			try {

				if ( child.children[ 0 ].children[ 0 ].type === 'PerspectiveCamera' ) {

					myPlayer = child;

				} else {

					players.push( child );

				}

			} catch ( err ) {}

		}

	}

	if ( players.length < 2 ) {

		return;

	}

	let targetPlayer;
	let minDistance = Infinity;

	for ( let i = 0; i < players.length; i ++ ) {

		const player = players[ i ];

		if ( player.position.x === myPlayer.position.x && player.position.z === myPlayer.position.z ) {

			continue;

		}

		if ( player.firstTime !== true ) {

			const mesh = new THREE.Mesh( geometry, material );

			meshes.push( mesh );

			player.add( mesh );

			player.firstTime = true;

		}

		const distance = player.position.distanceTo( myPlayer.position );

		if ( distance < minDistance ) {

			targetPlayer = player;

			minDistance = distance;

		}

	}

	if ( targetPlayer === undefined ) {

		return;

	}

	tempVector.setScalar( 0 );

	targetPlayer.children[ 0 ].children[ 0 ].localToWorld( tempVector );

	tempObject.position.copy( myPlayer.position );

	tempObject.lookAt( tempVector );

	myPlayer.children[ 0 ].rotation.x = - tempObject.rotation.x;
	myPlayer.rotation.y = tempObject.rotation.y + Math.PI;

}

animate();

window.addEventListener( 'keydown', function ( event ) {

	if ( String.fromCharCode( event.keyCode ) === 'G' ) {

		isActive = ! isActive;

		for ( let i = 0; i < meshes.length; i ++ ) {

			meshes[ i ].visible = isActive;

		}

	}

} )