MV Help fixing a plugin snippet someone made in a thread

So I came across this thread here, where someone provided a little snippet that hides augments that are already slotted, effectively preventing the player from stacking augments. (Using Yanfly's AttachAugment plugin.)

At a glance this works fine. If you try to add the same augment item in another slot, it won't show it.

1692366686095.png

1692366699178.png


However, if you happen to have another slot filled with a different augment...

1692366733308.png

1692366783220.png


Trying to replace "ATK Starter" shows "MHP Starter" despite it already being used in slot 2.

This is of course an exploit that's an issue, so I'm looking for someone who could potentially fix this up.

(Here's the code for convenience.)

Code:
Window_AugmentItemList.prototype.makeItemList = function() {
    this._data = $gameParty.allItems().filter(function(item) {
        return this.includes(item);
    }, this);
    if (this._item && this._item.augmentSlotItems[this._slotId] !== 'none') {
        this._data.unshift(null);
    }

    if (this._data.length === 0) return;
    alreadyAttached = this._item.augmentSlotItems;


    for (i=0; i< this._data.length; i++){
        if (this._data[i]) var keyWord = "item "+this._data[i].id
        for (j=0; j<alreadyAttached.length; j++){
            if (alreadyAttached[j] === keyWord) this._data.splice(i,1);
        };
    };
};

Thanks in advance. 😀
Can you please explain how the first set of screenshots shows the code working as desired?

It looks like you are putting your cursor on the installed ATK Starter, clicking to replace/remove it, and it's not showing the ability to replace it with another ATK Starter. That shouldn't require any modifications to the code.

Do I misunderstand?

I just want to make sure it's established that this code is doing something correct to begin with, before trying to modify it.
Can you please explain how the first set of screenshots shows the code working as desired?

It looks like you are putting your cursor on the installed ATK Starter, clicking to replace/remove it, and it's not showing the ability to replace it with another ATK Starter. That shouldn't require any modifications to the code.

Do I misunderstand?

I just want to make sure it's established that this code is doing something correct to begin with, before trying to modify it.
Ahh I probably didn't make the best shots there huh. It indeed hides the "ATK Starter" as intended.

The problem starts when you have something in slot 2 and then try replacing "Attack Starter" again. As you can see in the screenshot, it shows that you can slot a "MHP Starter" in slot 1 despite it already being present in slot 2, when it should now technically hide both augments, as they are already slotted, resulting in the possibility of slotting 2 "MHP Starters".

1692377662129.png


1692377672877.png

1692377684162.png


Strangely enough I can not do the same thing when trying to slot 2 "ATK Starters".

The items are correctly set up notetag-wise so I'm not quite sure what's up here.
Ahh I probably didn't make the best shots there huh. It indeed hides the "ATK Starter" as intended.
My point is, do you need code for that to not happen? It would seem common sense that you can't replace an augment with another version of itself - that's not "stacking," that's "pointless" 😛

The problem starts when you have something in slot 2 and then try replacing "Attack Starter" again. As you can see in the screenshot, it shows that you can slot a "MHP Starter" in slot 1 despite it already being present in slot 2
Yes, I got that part of it, which is why I was asking whether this code snippet is doing anything to begin with.

Strangely enough I can not do the same thing when trying to slot 2 "ATK Starters".
That is strange, and certainly points to the items being configured differently; or there being some sort of edge case not caught by the added code.

Can you provide an example project to mess with? (just remember not to include the actual Yanfly plugins)
My point is, do you need code for that to not happen? It would seem common sense that you can't replace an augment with another version of itself - that's not "stacking," that's "pointless"
Oh, now I see the confusion. Screenshot no.2 is not me clicking on the slot that already has "ATK Starter". It's the empty slot 2, showing only "MHP Starter" as advertised.
Can you provide an example project to mess with?
I don't think I can. This is all based on yanfly plugins as well as my own personal commissioned plugins. Removing any of it crashes the game.

The only difference between the augments items are the effects.
1692378492144.png

1692378503433.png
So you're saying you can't duplicate this in a fresh project with just the Yanfly Item and Augment plugins? (plus the new snippet)

That would point to a conflict with something else you have in there.
So you're saying you can't duplicate this in a fresh project with just the Yanfly Item and Augment plugins? (plus the new snippet)

That would point to a conflict with something else you have in there.
Hmm. I suppose that would work, but not consider my custom menu. The question I would have then is what do you want a sample project for, that doesn't include the yanfly plugins. That would essentially be an empty project with just the snippet?
Basically I'm willing to help troubleshoot but I don't want to set up the database and notetags and everything 😛

Are both of the augments in the Item category of the database?

Looking at the plugin, it allows you to install any category (item/weapon/armor) but the code above would only remove Items from the list, it looks like it doesn't consider weapons or armor at all.
Basically I'm willing to help troubleshoot but I don't want to set up the database and notetags and everything 😛

Are both of the augments in the Item category of the database?

Looking at the plugin, it allows you to install any category (item/weapon/armor) but the code above would only remove Items from the list, it looks like it doesn't consider weapons or armor at all.
Yeah they are items (always intended to be anyway). I've seen the note about it on the original post. It only works as long the augments are items. They did want to make updates, provided OP checked in to report if the code was working or not, but they never did.

It's the only thing I found that let's me prevent slotting multiple of the same augments.
Okay...just reading through it, this part looks like fishy logic to me. Try replacing this line:
Code:
        if (this._data[i]) var keyWord = "item "+this._data[i].id

with this:
Code:
        if (!this._data[i]) continue;
        var keyWord = "item "+this._data[i].id;
Looks like no change at all. (Is the space after "item intentional?)

edit: I removed the space after "item, this seems to break the thing. I can now slot everything however I want again. There are no errors in the console tho.
Yes, the space is intentional, that matches the formatting in the Yanfly code.

Original thread: https://forums.rpgmakerweb.com/threads/help-fixing-a-plugin-snippet-someone-made-in-a-thread.160389/