Melvor Auto Equip

Automatically switch equipment sets based on the enemy's attack style

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Melvor Auto Equip
// @namespace    http://tampermonkey.net/
// @version      0.21.0.0
// @description  Automatically switch equipment sets based on the enemy's attack style
// @author		Chrono
// @match		https://*.melvoridle.com/*
// @exclude		https://wiki.melvoridle.com*
// @noframes
// ==/UserScript==

function AutoEquip() {

    const MELEE = 0; // 0 is the 1st set
    const RANGED = 1; //1 is the second set
    const MAGIC = 2; //2 is the third (last) set

    console.log("Auto-Equip Running");

    // Store a reference to the game's createNewEnemy function
    combatManager._createNewEnemy = combatManager.createNewEnemy;
    // Overwrite the game's createNewEnemy function to inject the changeEquipmentSet function in it
    combatManager.createNewEnemy = () => {

        combatManager._createNewEnemy();
        try {
            var style = combatManager.enemy.attackType;

            if (style == 'melee') // && player.selectedEquipmentSet!=MAGIC)
            {
                //console.log("Equipping Magic Set");
                player.changeEquipmentSet(MAGIC);
            }
            else if (style == 'ranged') // && player.selectedEquipmentSet!=MELEE)
            {
                //console.log("Equipping Melee Set");
                player.changeEquipmentSet(MELEE);
            }
            else if (style == 'magic') // && player.selectedEquipmentSet!=RANGED)
            {
                //console.log("Equipping Ranged Set");
                player.changeEquipmentSet(RANGED);
            }

        } catch (e) {
            console.error(e);
        }
    };

};

(function () {
    function injectScript(main) {
        const scriptElement = document.createElement('script');
        scriptElement.textContent = `try {(${main})();} catch (e) {console.log(e);}`;
        document.body.appendChild(scriptElement).parentNode.removeChild(scriptElement);
    }

    function loadScript() {
        if ((window.isLoaded && !window.currentlyCatchingUp)
            || (typeof unsafeWindow !== 'undefined' && unsafeWindow.isLoaded && !unsafeWindow.currentlyCatchingUp)) {
            // Only load script after game has opened
            clearInterval(scriptLoader);
            injectScript(AutoEquip);
        }
    }
    const scriptLoader = setInterval(loadScript, 200);
})();