Count item script?

Hi there, i want to count item X (x is the item's ID stored in variable 1) to see how many of items X does player possess
and store the result into variable 2 (via Script call)
(can you show me the scripts for both situation that includes / not includes equipped items)
Thanks, please help T.T
image is via event commands.

the script equivalent is $gameParty.numItems(item, includeEquip);

argument details:
item = $dataItems[itemId] i.e. the database item object itself.
includeEquip = boolean value specified as true or false.
including equipped items:
Code:
$gameVariables.setValue (2, $gameParty._items[$gameVariables.value(1)]);

not including equipped items
Code:
var x = 0;
for (var i = 0; i<$gameParty.members().length; i++) {
if ($gameParty.members()[i].isEquipped ($gameVariables.value (1))) x++;
}
gameVariables.setValue (2, $gameParty._items[$gameVariables.value(1)] - x);
Wow thank so much @dbchest and @Poryg , I couldn't believe got replied that fast @.@
Both scripts you teach me works perfect.
Dbchest method "$gameParty.numItems(item, includeEquip);" is easier for a dummy like me though (while Poryg method #1 is shorter)
Thanks again
Learn and you won't be a dummy over time 😛 It's free and not that time consuming 🙂
@Poryg that is one of the good ones.
Of course it is, it is the one I used 🙂 It just lacks content, but well... You get what you pay for and this site is free.

Original thread: https://forums.rpgmakerweb.com/threads/count-item-script.87828/