MV YEP_Core Engine Max Item bypass for Equipment error.

Hello everyone o/


So I've got Yep Core engine plugin which allows me to set a limit to how many items or in this case, equipment the player can buy by placing the notetag <Max Item: 1>

I'm using this for Dungeon equipment (weapons, armour, leg gear) that can only be brought once.

It works fine buuuuuut.

Obsidian sword, brought, bought can't buy again. Shop won't let me purchase this again.

I go equip Obsidian sword, but now it's equipped, I can purchase it again as I think the plugin sees that it's not in my inventory anymore so it think it's can be brought again.

So I know the plugin can detect if it's in the players inventory so I would like a snippet to allow the plugin to check to see if the item is equipped also.


if it helps, the item can't be sold either, so once brought, that's it, can't be brought again nor sold.

Thank you everyone.

---------------

Quick update, I'm using Yeps shop core as well and from what the shop menu scene is telling me is possession is 0 when the item is equipped.
Does the same thing happen when you're not using the Shop Core? Or is the error in the Shop Core?

Note: The word is "bought," not "brought."
Yeah turned off the shop core and it's still treating it the same as not being in possession when equipped.
Does the same thing happen when you're not using the Shop Core? Or is the error in the Shop Core?
its as they say. the function that counts the party's independent item count in the item core doesnt count equipped items, and the shop menu plugin doesnt alter it

so... you can try this. it works fine in a test project, but it added an ungodly amount of startup time to my main project. YMMV. someone else might know of a better way to go about it.

Spoiler
Code:
var _newNumItems = Game_Party.prototype.numIndependentItems;
Game_Party.prototype.numIndependentItems = function(baseItem) {
    var value = _newNumItems.call(this, baseItem);
    if (!DataManager.isIndependent(baseItem)) return value;
    if (DataManager.isWeapon(baseItem)){
      value += $gameParty.members().reduce((a,b) =>
        a+b.weapons().reduce((c,d) =>
          d.baseItemId===baseItem.id? c+1 : c ,0)
      ,0)
    }
    if (DataManager.isArmor(baseItem)){
      value += $gameParty.members().reduce((a,b) =>
        a+b.armors().reduce((c,d) =>
          d.baseItemId===baseItem.id? c+1 : c ,0)
      ,0)
    }
    return value;
};

since its an item thats only bought one time ever and cant be discarded, you could sidestep the shop, throw together an event that gives the player the weapon in exchange for gold, and then flip a switch so that its never offered again
Hmm, maybe there're other plugins out there that can have limited quantity
For example,
So that's nothing to do with any of your plugins - that's how the actual game engine works.

It's just harder to see because of the higher limit, but you'd see the exact same thing if you make a chest that gives you 99 Short Swords; equip one, you'd be able to buy one more. Shops only look at the party's inventory. The item carried limit is carried by the party, not by individual actors.

its as they say. the function that counts the party's independent item count in the item core doesnt count equipped items, and the shop menu plugin doesnt alter it
I don't think it has anything specific to do with independent items, shops just reference $gameParty.maxItems() and $gameParty.numItems(), neither of which look at equipped items. It's intentional.

You can change it so that numItems() includes equipped items, but if you have a lot of actors in your database it might end up producing lag like you said.

Haven't tested this, so there might be a typo snuck in, but:

Code:
Game_Party.prototype.numItems = function(item)
{
    var container = this.itemContainer(item);
    let numHeld = container ? container[item.id] || 0 : 0;
    if (container == this._weapons)
        $gameActors._data.forEach(actor =>
        {
             if (actor)
                actor.weapons().forEach(weapon => {if (weapon.id == item.id || weapon.baseItemId && weapon.baseItemId == item.id) numHeld++;});
        });
    else if (container == this._armors)
        $gameActors._data.forEach(actor =>
        {
             if (actor)
                actor.armors().forEach(armor=> {if (armor.id == item.id || armor.baseItemId && armor.baseItemId == item.id) numHeld++;});
        });
    return numHeld;
};
Hmm, maybe there're other plugins out there that can have limited quantity
They would do the same thing unless they implement a change like the above.
Yeah, but that plugin let you change conditions of the items. So combine with some scripts it is possible.
since its an item thats only bought one time ever and cant be discarded, you could sidestep the shop, throw together an event that gives the player the weapon in exchange for gold, and then flip a switch so that its never offered again

Yeah if it was for a couple of items that idea wouldn't seem so bad, but its for 4 dungeons, with 9 items each shop. But thanks for the sugestion. ^^


So that's nothing to do with any of your plugins - that's how the actual game engine works.

It's just harder to see because of the higher limit, but you'd see the exact same thing if you make a chest that gives you 99 Short Swords; equip one, you'd be able to buy one more. Shops only look at the party's inventory. The item carried limit is carried by the party, not by individual actors.


I don't think it has anything specific to do with independent items, shops just reference $gameParty.maxItems() and $gameParty.numItems(), neither of which look at equipped items. It's intentional.

You can change it so that numItems() includes equipped items, but if you have a lot of actors in your database it might end up producing lag like you said.

Haven't tested this, so there might be a typo snuck in, but:

Code:
Game_Party.prototype.numItems = function(item)
{
    var container = this.itemContainer(item);
    let numHeld = container ? container[item.id] || 0 : 0;
    if (container == this._weapons)
        $gameActors._data.forEach(actor =>
        {
             if (actor)
                actor.weapons().forEach(weapon => {if (weapon.id == item.id || weapon.baseItemId && weapon.baseItemId == item.id) numHeld++;});
        });
    else if (container == this._armors)
        $gameActors._data.forEach(actor =>
        {
             if (actor)
                actor.armors().forEach(armor=> {if (armor.id == item.id || armor.baseItemId && armor.baseItemId == item.id) numHeld++;});
        });
    return numHeld;
};

They would do the same thing unless they implement a change like the above.

Works a treat my good sir.

Original thread: https://forums.rpgmakerweb.com/threads/yep_core-engine-max-item-bypass-for-equipment-error.170606/