Greasy Fork

Fortnite Xbox Cloud Aim Assist with GUI and FOV Control

Fortnite on Xbox Cloud with GUI and FOV control.

目前为 2024-12-11 提交的版本。查看 最新版本

// ==UserScript==
// @name         Fortnite Xbox Cloud Aim Assist with GUI and FOV Control
// @namespace    http://tampermonkey.net/
// @version      20
// @description  Fortnite on Xbox Cloud with GUI and FOV control.
// @author       Your Name
// @match        https://www.xbox.com/en-US/play/launch/fortnite/BT5P2X999VH2
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Default configuration values
    const config = {
        enemySelector: '.enemy-class', // Replace with actual enemy selector
        playerSelector: '.PlayerInfo-module__container___ROgVL', // Replace with actual player selector
        aimInterval: 100, // Interval in milliseconds for aim checks
        aimSmoothing: 0.2, // Smoothing factor for more natural aim adjustments
        fov: 60 // Field of View for the aimbot in degrees
    };

    // Add GUI overlay to control FOV and smoothing
    const guiStyle = `
        position: fixed;
        top: 10px;
        right: 10px;
        background: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 10px;
        border-radius: 10px;
        z-index: 1000;
    `;
    const sliderStyle = `
        margin: 5px 0;
    `;

    const gui = document.createElement('div');
    gui.style.cssText = guiStyle;

    // FOV slider
    const fovLabel = document.createElement('label');
    fovLabel.innerText = 'FOV: ';
    const fovSlider = document.createElement('input');
    fovSlider.type = 'range';
    fovSlider.min = 20;
    fovSlider.max = 180;
    fovSlider.value = config.fov;
    fovSlider.style.cssText = sliderStyle;
    fovSlider.addEventListener('input', () => {
        config.fov = fovSlider.value;
        fovValue.innerText = `${config.fov}°`;
    });
    const fovValue = document.createElement('span');
    fovValue.innerText = `${config.fov}°`;

    // Smoothing slider
    const smoothingLabel = document.createElement('label');
    smoothingLabel.innerText = 'Aim Smoothing: ';
    const smoothingSlider = document.createElement('input');
    smoothingSlider.type = 'range';
    smoothingSlider.min = 0;
    smoothingSlider.max = 1;
    smoothingSlider.step = 0.05;
    smoothingSlider.value = config.aimSmoothing;
    smoothingSlider.style.cssText = sliderStyle;
    smoothingSlider.addEventListener('input', () => {
        config.aimSmoothing = smoothingSlider.value;
        smoothingValue.innerText = config.aimSmoothing;
    });
    const smoothingValue = document.createElement('span');
    smoothingValue.innerText = config.aimSmoothing;

    // Append the elements to the GUI
    gui.appendChild(fovLabel);
    gui.appendChild(fovSlider);
    gui.appendChild(fovValue);
    gui.appendChild(document.createElement('br'));
    gui.appendChild(smoothingLabel);
    gui.appendChild(smoothingSlider);
    gui.appendChild(smoothingValue);

    // Add the GUI to the page
    document.body.appendChild(gui);

    /**
     * Calculate the angle between two points.
     * @param {number} targetX - Target X coordinate.
     * @param {number} targetY - Target Y coordinate.
     * @param {number} playerX - Player X coordinate.
     * @param {number} playerY - Player Y coordinate.
     * @returns {number} Angle in degrees.
     */
    function calculateAngle(targetX, targetY, playerX, playerY) {
        return Math.atan2(targetY - playerY, targetX - playerX) * (180 / Math.PI);
    }

    /**
     * Smoothly rotate the player towards the enemy.
     * @param {number} angle - The calculated angle to rotate the player.
     */
    function smoothAim(angle) {
        const player = document.querySelector(config.playerSelector);
        if (player) {
            const currentRotation = parseFloat(player.style.transform.replace('rotate(', '').replace('deg)', '')) || 0;
            const targetRotation = angle;
            const smoothedRotation = currentRotation + (targetRotation - currentRotation) * config.aimSmoothing;
            player.style.transform = `rotate(${smoothedRotation}deg)`;
        }
    }

    /**
     * Check if the enemy is within the player's Field of View (FOV).
     * @param {number} angle - The angle between the player and the enemy.
     * @returns {boolean} Whether the enemy is within the FOV.
     */
    function isWithinFov(angle) {
        return Math.abs(angle) <= (config.fov / 2);
    }

    /**
     * Aim at the closest enemy based on the player's position.
     */
    function aimAtEnemies() {
        const enemy = document.querySelector(config.enemySelector);
        const player = document.querySelector(config.playerSelector);

        // Ensure enemy and player elements exist
        if (!enemy || !player) {
            console.warn('Enemy or player element not found.');
            return;
        }

        // Get bounding rectangles of the enemy and player
        const enemyRect = enemy.getBoundingClientRect();
        const playerRect = player.getBoundingClientRect();

        // Calculate center coordinates for both the enemy and player
        const enemyX = enemyRect.x + enemyRect.width / 2;
        const enemyY = enemyRect.y + enemyRect.height / 2;
        const playerX = playerRect.x + playerRect.width / 2;
        const playerY = playerRect.y + playerRect.height / 2;

        // Calculate the angle to aim at the enemy
        const angle = calculateAngle(enemyX, enemyY, playerX, playerY);

        // If the enemy is within the FOV, aim at them
        if (isWithinFov(angle)) {
            smoothAim(angle);
            console.log(`Aimed at enemy: angle = ${angle.toFixed(2)} degrees`);
        }
    }

    /**
     * Initialize the aim assist functionality.
     */
    function initializeAimAssist() {
        console.log('Aim Assist Initialized');
        setInterval(aimAtEnemies, config.aimInterval);
    }

    // Start the aim assist script
    initializeAimAssist();
})();