MZ Auto Unequip Items script needed

Evening All,

I am using Gabes Equip Requirements plugin to determine when certain weapons and armors can be equipped by my actors.

However one thing I've noticed is that if an item is unavailable due to its requirement not being met:

1689384780369.png


It will be greyed out. This is Great!

Because the Actors need a Bow equipped first

1689384843599.png


and then voila:

1689384865255.png


1689384883436.png


However, if I now unequip the bow:

1689384909731.png


The Arrows will remain equipped.


What I need is a script (or plugin if needed) that can accomplish 2 things:


1) Unequip items from Actors if the Actor loses access to the Armor Type Associated with it.

For Example if Archer Class gives the Arrow armor type, once the actor is no longer that class, any Arrow Armors should be automatically unequipped. This only needs to occur/refresh on the equip screen.

2) Unequip Items from Actors that no longer meet the requirements dictated via the Gabes Equip Requirements plugin.

The Armor "Great Shield" requires at least 20 ATK to equip using a note tag from the plugin.

<require attack 20>

If the Actor has 20 Attack and equips the Great Shield, should their Attack for any reason fall below 20 in the equip screen, the Great Shield should be automatically unequipped.


The first I imagine is simplish, the 2nd might take some leg work.


Good luck!
You have a special armor type just for arrows, I assume? Just dont put that type in the traits of the actor or the class, but put it in the traits of your bows.

This way they cant be equiped, unless you have a bow equiped, and should unequip when you unequip the bow.
You have a special armor type just for arrows, I assume? Just dont put that type in the traits of the actor or the class, but put it in the traits of your bows.

This way they cant be equiped, unless you have a bow equiped, and should unequip when you unequip the bow.


That would unfortunately only potentially solve for half the problem tho.

The bigger concern i have is the note tag checks since those are a lot more nuanced then simply matching traits since I do want to be able to specific equipment reliant on others to be used.

For Example:


1689389426165.png


Via note tag I can determine that Academy Bade 2 can only be equipped if Badge 1 is already equipped.

That requirement is easy enough to set up. But that should also mean that If Badge 1 is unequipped, than Badge 2 is removed automatically as well. That's less of a RPG Maker issues, and more about the plugin itself that I shared ^
Hey,

It looks like these problems can actually be fixed by enabling the "Hide Unavailable Equipment?" option of the plugin, if that is an acceptable trade off.

But if you still want to display the other items a quick fix could be maybe something like this:
Spoiler
Code:
/*:
 * @plugindesc Show "relevant" equip items in the equipment menu even if
 *   they cannot be equipped due to other plugins restrictions.
 */

Game_BattlerBase.prototype.isRelevantEquipItem = function(item) {
    if (!item) {
        return false;
    } else if (DataManager.isWeapon(item)) {
        return this.isEquipWtypeOk(item.wtypeId) &&
        !this.isEquipTypeSealed(item.etypeId);
    } else if (DataManager.isArmor(item)) {
        return this.isEquipAtypeOk(item.atypeId) &&
        !this.isEquipTypeSealed(item.etypeId);
    } else {
        return false;
    }
};

// Redefined:
Window_EquipItem.prototype.includes = function(item) {
    if (item === null) {
        return true;
    }
    return (
        this._actor &&
        this._actor.isRelevantEquipItem(item) &&
        item.etypeId === this.etypeId()
    );
};

(function() {
    const old = Window_EquipItem.prototype.isEnabled;
    Window_EquipItem.prototype.isEnabled = function(item) {
        return old.call(this, item) && this._actor.canEquip(item);
    };
})();
(This code is a bit heavy handed and would probably need adjusting if you have other plugins that modify equippability, but should hopefully work for now)

Edit: Forgot some braces.
It looks like these problems can actually be fixed by enabling the "Hide Unavailable Equipment?" option of the plugin, if that is an acceptable trade off.
This can do the job. I mainly want to keep them viewable so Players dont lose track of the fact that those items are in inventory since a lot of management is happening in the equip screen.

Enabling that also seems to conflict with Item Equips Core for some reason. But I can likely live without the plugin worst comes too.

I'll take a crack at the script but
function() {
I forsee this rando function call out being an issue without a name
I'll take a crack at the script but
Oh, woops, should have done another syntax check, sorry. Forgot to add braces around the function. The functions purpose is only to encapsulate the "old" constant so it does not become a global variable.

The script should be used as a plugin, and because it replaces a function it might need be placed above certain plugins in the plugin list (before plugins that might extend the function Window_EquipItem.prototype.includes)

Enabling that also seems to conflict with Item Equips Core for some reason.
I'm not sure if I'll be of much help with that since I don't actually use the RMMZ and VisuStella does not publicize their code as far as I know. I don't see any obvious points for conflict in Gabes plugin either, but out of curiousity: how does this conflict look like?

Original thread: https://forums.rpgmakerweb.com/threads/auto-unequip-items-script-needed.159334/