MV Yanfly's ShopMenuCore "In Possession" for equipped items.

Hey all, I was wondering if there is a way to make Yanfly's ShopMenuCore have currently equipped items considered "In Possession" for the sake of the shop menu. This confused me during a playtest and it would probably confuse players as well thinking they did not have a piece of equipment even if a character already had it equipped. (Re-asked this from the regular question thread since it might be more in depth)
so far I know, possession checks the inventory, so if you have one
equiped, you do have it, if nothing there and has 1, your possession
count is 1.

it is doable to make that check, but I don't have time now to check,
if no answer yet, I check tomorrow and see how it can be done.
so far I know, possession checks the inventory, so if you have one
equiped, you do have it, if nothing there and has 1, your possession
count is 1.

it is doable to make that check, but I don't have time now to check,
if no answer yet, I check tomorrow and see how it can be done.
Dunno if I have any other plugins that would somehow change how that checked but yeah as far as I can tell, it says 0 if you have 0 in inventory but one is equipped. Looking forward to what you come up with, thank you!
so far I know, possession checks the inventory, so if you have one
equiped, you do have it, if nothing there and has 1, your possession
count is 1.
by default, the engine doesnt count equipped gear as being in the party's possession. the shop's possession is handled by $gameParty.numItems and that only looks at the inventory. Equipped gear isnt there. $gameParty.hasItem does check both all actors and the inventory, so that might be where the confusion is from?
so that might be where the confusion is from?
I didn't know it was handles seperately, so basicly what you say, the only edit
to be made for possession is to make the $gameParty.number to $gameParty.hasItem
for check?

it would make some sense, as I though the "hasItem" is to use outside if it was
in your inventory and another like "isEquiped" to see if you had it on you to make
the count.

but good to know though =)
by default, the engine doesnt count equipped gear as being in the party's possession. the shop's possession is handled by $gameParty.numItems and that only looks at the inventory. Equipped gear isnt there. $gameParty.hasItem does check both all actors and the inventory, so that might be where the confusion is from?


Tried to find numitems in the code but didn't see it anywhere... however I did see a line with the word possession... though I'm not sure what I need to change.
Tried to find numitems in the code but didn't see it anywhere
its not in the plugin. as mentioned, its in the base engine within the objects.js file.

however I did see a line with the word possession
nothing to worry about there. drawPosession() isnt introduced by the plugin. that is also a base engine function within the windows.js file.
It just sets up some text formatting and then prints the text for whatever you named your posessions within the database alongside the number returned by $gameParty.numItems() for the current item
its not in the plugin. as mentioned, its in the base engine within the objects.js file.


nothing to worry about there. drawPosession() isnt introduced by the plugin. that is also a base engine function within the windows.js file.
It just sets up some text formatting and then prints the text for whatever you named your posessions within the database alongside the number returned by $gameParty.numItems() for the current item


Oh... well if/when you have the time I'm not at all well versed with where/what I would need to edit in the windows js.
turns out numItems() is used in gainItem() in order to determine how much of an item you get. so instead of making changes there as well, this'll just change what drawPosession() displays.

Code:
Window_ShopStatus.prototype.drawPossession = function(x, y) {
  var width = this.contents.width - this.textPadding() - x;
  var possessionWidth = this.textWidth('0000');
  this.changeTextColor(this.systemColor());
  this.drawText(TextManager.possession, x, y, width - possessionWidth);
  this.resetTextColor();
 
  var count = $gameParty.numItems(this._item)
  if (DataManager.isWeapon(this._item) || DataManager.isArmor(this._item))
    $gameParty.members().forEach(actor =>
      actor.equips().forEach(equip => {
        if (this._item === equip) count++;
      }) 
    );

  this.drawText(count, x, y, width, 'right');
};
turns out numItems() is used in gainItem() in order to determine how much of an item you get. so instead of making changes there as well, this'll just change what drawPosession() displays.

Code:
Window_ShopStatus.prototype.drawPossession = function(x, y) {
  var width = this.contents.width - this.textPadding() - x;
  var possessionWidth = this.textWidth('0000');
  this.changeTextColor(this.systemColor());
  this.drawText(TextManager.possession, x, y, width - possessionWidth);
  this.resetTextColor();
 
  var count = $gameParty.numItems(this._item)
  if (DataManager.isWeapon(this._item) || DataManager.isArmor(this._item))
    $gameParty.members().forEach(actor =>
      actor.equips().forEach(equip => {
        if (this._item === equip) count++;
      })
    );

  this.drawText(count, x, y, width, 'right');
};


Am I just supposed to paste your code over this portion? That's what I attempted and I don't notice a change so I assume that I did it wrong.

Code:
Window_ShopStatus.prototype.drawPossession = function(x, y) {
    var width = this.contents.width - this.textPadding() - x;
    var possessionWidth = this.textWidth('0000');
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.possession, x, y, width - possessionWidth);
    this.resetTextColor();
    this.drawText($gameParty.numItems(this._item), x, y, width, 'right');
};
Am I just supposed to paste your code over this portion?
I thought you might have been given snippets before so i didnt mention it. You were to use a text editor to save the text as a .js file and load it into your project as a plugin.

You shouldnt manually change anything within your projects core js files. All changes made should be done with plugins.

That being said...
I don't notice a change so I assume that I did it wrong.
Unless you forgot to save, the next likely reason would be that you have a plugin in your list that overwrites the changes as well. That too should be solved by loading what i gave you as a plugin, but youd load it at the bottom of your list

EDIT: you wouldn't happen to be using yanfly's item core? its the only yanfly one that comes to mind that'd alter it.
I thought you might have been given snippets before so i didnt mention it. You were to use a text editor to save the text as a .js file and load it into your project as a plugin.

You shouldnt manually change anything within your projects core js files. All changes made should be done with plugins.

That being said...

Unless you forgot to save, the next likely reason would be that you have a plugin in your list that overwrites the changes as well. That too should be solved by loading what i gave you as a plugin, but youd load it at the bottom of your list

EDIT: you wouldn't happen to be using yanfly's item core? its the only yanfly one that comes to mind that'd alter it.
I do have the item core, I'll try it as plugin tomorrow. (Did keep the regular windows.js as a backup of course)

@Robro33 EDIT: I tried the core in the plugin list near the bottom and also above item core.

When below item core, it does not display possession of items that are equipped or unequipped and when placed above item core it functions as the default with only showing unequipped items in possession.
I was looking around in the script call section and found this bit...
$gameParty.hasItem(item, includeEquip)

In the YEP_ItemCore.js I changed the line that says

var value = $gameParty.numIndependentItems(baseItem);

to

var value = $gameParty.hasItem(baseItem,true);

It DOES recognize if the party has the item equipped or not now, but just says true or false instead of listing the quantity. (This is with your plugin code turned off)

I think I'm in the right section of code now at least and while I see the other options for checking items in the script calls list DO NOT include equipment... I'm sure there's a way to use these that I don't know to make what I want to do work.

It is still showing a quantity for regular items, just not equipment.



(This is what the code surrounding it looks like after I changed that bit for testing.)
Code:
Window_ShopStatus.prototype.drawIndependentPossession = function(x, y) {
    var width = this.contents.width - this.textPadding() - x;
    var baseItem = DataManager.getBaseItem(this._item);
    var value = $gameParty.hasItem(baseItem,true);
    value = Yanfly.Util.toGroup(value);
    var possessionWidth = this.textWidth(value);
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.possession, x, y, width - possessionWidth);
    this.resetTextColor();
    this.drawText(value, x, y, width, 'right');
It DOES recognize if the party has the item equipped or not now, but just says true or false instead of listing the quantity. (This is with your plugin code turned off)
yep. thats all the function does. it just says if its in the inventory or if an actor in the party is equipped with it. it does nothing to the effect of counting. my plugin wouldnt change hasItem()

the reason i brought up yanfly's item core before was because you hadnt mentioned using it and its a plugin i thought would make changes to drawPossession(). any changes made has to be made around that one, as independent weapons and armors would not be accounted if not. looking into the item core now, where did you place my plugin?

it looks as if if it were loaded before the item core it would work, but it would still need a similar change to drawIndependentPossession() to add the logic i added into numItems() to look at the equipment of the actors with a slight adjustment.
you cant directly compare the the shop item to the actors' gear as theyre independent items and are their own $data entries, so realistically youd have to check the baseItemId and the etype.

Code:
if (this._item.etypeId === equip.etypeId && this._item.id === equip.baseItemId) count++;
So basically...

revert my previous change to the ItemCore.js (Back to default)

change the line in your plugin code

if (this._item === equip) count++;
to
if (this._item.etypeId === equip.etypeId && this._item.id === equip.baseItemId) count++;

and place it above the ItemCore.js in the list?

I tried that and it didn't work, but let me know if you meant something else because I'm just kind of throwing things here hoping since I don't understand a lot of this stuff X_X. Thank you so much.

yep. thats all the function does. it just says if its in the inventory or if an actor in the party is equipped with it. it does nothing to the effect of counting. my plugin wouldnt change hasItem()

the reason i brought up yanfly's item core before was because you hadnt mentioned using it and its a plugin i thought would make changes to drawPossession(). any changes made has to be made around that one, as independent weapons and armors would not be accounted if not. looking into the item core now, where did you place my plugin?

it looks as if if it were loaded before the item core it would work, but it would still need a similar change to drawIndependentPossession() to add the logic i added into numItems() to look at the equipment of the actors with a slight adjustment.
you cant directly compare the the shop item to the actors' gear as theyre independent items and are their own $data entries, so realistically youd have to check the baseItemId and the etype.

Code:
if (this._item.etypeId === equip.etypeId && this._item.id === equip.baseItemId) count++;
I tried that and it didn't work
thats my bad. i wasnt testing anything and wasnt being clear in my throwing ideas out. since drawIndependentPossession() was introduced by the item plugin, then it tracks that making a plugin and loading it before then does absolutely nothing 🤣

so square one - since you to use item core and you make use of independent items, we dont need to touch drawPossession() at all as all your gear is independent. so looking at drawIndependentPossession, you need alter it so that the possessions shown for independent items includes all of of your actors' gear
Code:
Window_ShopStatus.prototype.drawIndependentPossession = function(x, y) {
    var width = this.contents.width - this.textPadding() - x;
    var baseItem = DataManager.getBaseItem(this._item);
    var value = $gameParty.numIndependentItems(baseItem);
    value = Yanfly.Util.toGroup(value);
   
    $gameParty.members().forEach(actor =>
      actor.equips().forEach(equip => {
        if (equip && this._item.etypeId === equip.etypeId && this._item.id === equip.baseItemId) value++;
      })
    );
   
    var possessionWidth = this.textWidth(value);
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.possession, x, y, width - possessionWidth);
    this.resetTextColor();
    this.drawText(value, x, y, width, 'right');
};
load that after the item core so that it overwrites it
load that after the item core so that it overwrites it

Thank you! Works like a charm when buying new equipment.

(I did notice it doesn't list the the total number in possession when selling if you have 1 equipped and 1 in inventory it will say 1, but honestly that's fine by me, it kinda makes more sense when selling to have the number listed as the non-equipped number, it's more important to me that the player does not buy duplicate equipment thinking they didn't own one yet.)

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-shopmenucore-in-possession-for-equipped-items.175375/