Equipped weapons aren't counting

Hi everybody!

I tried count the number of swords I have (only one, equipped), but didn't worked using event commands, as you can see in the spoiler.

Spoiler
2FN7TCW.png


NOQsOsS.png


qsGad0P.png
Then, I tried using "script", but didn't work either with this > $gameParty.numItems($dataWeapons[1]).

I imagine that be some error, or missing part in some plugin, because if the same is happening with event commands... or I did something wrong? o-o
I might be mistaken, but I don't think it counts the items you have equipped. This can be tested in a shop for example. You could buy a sword and it will say "in possession: 1" but when you equip it, it will say "0". You could do a script call to force unequip the sword and then run the event...but that could be disorienting for the player when their sword is removed randomly :X
It's probably part of the translation - in Ace, that option was translated as "Item in inventory", and that is indeed what this function does - it only counts in inventory, not when equipped.
Ah, well. Thanks for the explanation, both.

And, there would be a way of count all weapons/armors including equipped? In the true, this is to a item weight plugin. I only tested using events. A way counting equipped weapons + weapons in inventary solve my problem.
If your sword is weapon id 8,

Code:
Control Variables: [001: Sword Count] = $gameParty.numItems($dataWeapons[8]) + $gameParty.members().select(function(actor) { return actor.equips().contains($dataWeapons[8]) }).length
If that's too long, do this:

Code:
Control Variables: [001: Sword Count] = Swords in InventoryControl Variables: [001: Sword Count] += $gameParty.members().select(function(a) { return a.equips().contains($dataWeapons[8]) }).length
Thanks, Shaz, but both ways result in this error, using in event command or in the plugin.

axpUXws.jpg



EDIT: I got it. After try much, I learned to make function calls, created a to count equipped items and after added the unequipped. Thos worked for me, then...  solved.
Can lock this topic... I think
 

Code:
Window_ItemWeight.prototype.countEquippedWeapons = function(weaponId) {	var i = 0;	var counted = 0;	while (i < $gameParty.size()) {      if ($gameParty.members()[i].hasWeapon($dataWeapons[weaponId])) { counted += 1 };	  i += 1;	};    return counted;};
there was no plugin there.


I think the JS term should be filter, not select, but even with that I can't quite get it working that way.


This will work:

Control Variables: [001: Sword Count] = $gameParty.numItems($dataWeapons[8]) + $gameParty.members().filter(function(a) { return a.hasWeapon($dataWeapons[8]) }).length
If you're calling it from an event, why have you put your code into Window_ItemWeight rather than Game_Party? A Game_Party method called countAllWeapons could do a count of weapons in inventory AND weapons equipped.
[...]

Control Variables: [001: Sword Count] = $gameParty.numItems($dataWeapons[8]) + $gameParty.members().filter(function(a) { return a.hasWeapon($dataWeapons[8]) }).length[...]
Yeah, this code works in the event command. Thanks again!

The plugin that I reffer is a weight system, and I'm making it. At first, I needed count weapons to use it, but, when saw the event command don't work how I pensei, imagined that would a bug.

Sorry if I expressed what I wanted wrong, but now, It's solved my problem.
Shaz, thank you very much your help ^^
I was just facing a similar problem when I found this topic with your solution.
(I work on a method that makes it easier to count and replace equipment (for example older saves and newer game versions, I could change the modified items)
But with Yanfly's ItemCore and independent items, there are not counted, so I make a workaround for it, which is working fine for me.
I know this is an old topic, but if someone faces the same problem, it will be useful for him/her.

The common event uses 2 variables (one for the weaponID, and one for the return value)
inside this common event, create a script event command.
Code:
var id = $gameVariables.value(76); // the variable #76 which I used for the weaponId, change if you want
var qty1 = $gameParty.numItems($dataWeapons[id]); // the quantity of the base item
var qty2 = $gameParty.numIndependentItems($dataWeapons[id]); // the quantity of the independent item
var qty3 = $gameParty.members().filter(function(a) { return a.hasWeapon($dataWeapons[id]) }).length; // the quantity of the equipped item
var qty = qty1 + qty2 + qty3; // total quantity
$gameVariables.setValue(77, qty); // the variable #77 which I used for return value with the total quantity, change if you want
console.log('Weapon ID: '+id+' Weapon Name: '+$dataWeapons[id].name); // some debug info to console
console.log('Base: '+qty1+' Independent: '+qty2+' Equipped: '+qty3+' Total: '+qty); // some debug info to console

Outside a common event, where you want to use:
Control Variables: #0076: WeaponID = 8
Common Event: Weapon Count
Text: "You have \V[77] of the specified weapon."

For armors, just change the $dataWeapons to $dataArmors and a.hasWeapon to a.hasArmor 🙂

Original thread: https://forums.rpgmakerweb.com/threads/equipped-weapons-arent-counting.54472/