This is a function -- if you put it in a library you can call it in any script you want to count the items in a creature's inventory.
// Counts the number of items with sTag that oCreature possesses
// Will NOT count items equipped
int CountItem(object oCreature, string sTag)
{
// Tracker variable
int nCount;
// Loop through inventory
object oItem = GetFirstItemInInventory(oCreature);
while (GetIsObjectValid(oItem))
{
// Do the tags match?
if (GetTag(oItem) == sTag)
{
// Increase the tracker by the stack size
nCount += GetItemStackSize(oItem);
}
oItem = GetNextItemInInventory(oCreature);
}
// Return the tracker
return nCount;
}
So you'd run it by doing something like...
int x;
x = CountItem(oPC, "potion3");
x would then equal the number of items with the tag "potion3" -- and it doesn't matter if it's 10 separate potions or 10 stacked potions, it'll always equal 10.