MV Yanfly Change Battle Equip Modification?

So, context: Yanfly's Change Battle Equip script/plugin allows you to change out equipment in the middle of combat. But I've noticed a quirk - in VX Ace, if you didn't actually mess with your character's equipment and exited the change equipment menu, you didn't actually get nailed with the cooldown that prevents you from accessing the menu again.

I thought that was neat and assumed by default this feature was in the MV plugin equivalent of the script, but not so, after doing some tests.

Ruby:
    $game_party.menu_actor = actor
    previous_equips = actor.equips.clone
    index = @actor_command_window.index
    actor.set_equip_cooldown if previous_equips != actor.equips

I've tried to recreate this code with its Javascript counterpart, but so far nothing's coming to mind.
Try this.

Go to line 383, make a new line, and paste
Code:
    BattleManager.actor().previousEquips = BattleManager.actor().equips().clone();
Delete line 385.

Go to line 154, add an open brace after the conditional:
1717040317031.png


Then add a line and paste:
Code:
        if (member.previousEquips)
        {
            if (member.previousEquips != member.equips())
                member.setBattleEquipChange(true);
            delete member.previousEquips;
        }
    }

So you should end up with:
1717040444782.png


I haven't tested it, but it could do the trick.
Hmm. So unfortunately, @ATT_Turan, I did what you said to the letter and unfortunately the new method doesn't seem to update the equip swap cooldown.
I did what you said to the letter and unfortunately the new method doesn't seem to update the equip swap cooldown.
change battle equip isnt the only plugin that writes a BattleManager.refreshAllBattlers function. idk if youre using any others that do, but the passive state plugin as an example will overwrite the one in the battle equip plugin with what would have been the same exact function otherwise since its loaded after it. take your modified version of the function, save it as a separate plugin and load it last.

if (member.previousEquips != member.equips())
i dont think that works in this case. I remember it being a hassle to compare arrays containing objects before. you might have to use JSON.stringify on both or loop through each element of one of the equip arrays and compare it to each element of the other to compare the arrays
Good point, @Robro33 - so then we can compare them manually. (I'd have to look up the stringify stuff)

Code:
        if (member.previousEquips)
        {
            for (let i = 0; i < Math.max(member.previousEquips.length, member.equips().length); i++)
            {
                if (member.previousEquips[i] != member.equips()[i])
                {
                    member.setBattleEquipChange(true);
                    break;
                }
            }
            delete member.previousEquips;
        }
    }
So @Robro33 @ATT_Turan , you've both been an excellent help as I've gotten it to work now.

The new scriptlet from Turan and the knowledge to move the Change Equip plugin further down the list allow it to work with no (immediate) glitches, which is more than enough of a success for me.

Thread is solved.
This thread is closed due to being reported as solved. If you need it reopened, let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-change-battle-equip-modification.169112/