Simply replace sRef by sTag and pass the tag(and change GetResRef for GetTag) if you prefer to scan by tag instead of resref.
int GetNumItemsOnPC(string sRef, object oPC)
{
int nNth;
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
{
if(GetResRef(oItem) == sRef) nNth += GetItemStackSize(oItem);
oItem = GetNextItemInInventory(oPC);
}
return nNth;
}
void DelNumItemsFromPC(string sRef, object oPC, int nNmb)
{
int nDeleted, nItemStack;
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem) && nDeleted < nNmb)
{
if(GetResRef(oItem) == sRef)
{
nItemStack = GetItemStackSize(oItem);
if(nItemStack <= (nNmb-nDeleted))
{
nDeleted += nItemStack;
DestroyObject(oItem);
}
else
{
SetItemStackSize(oItem, nItemStack-(nNmb-nDeleted));
nDeleted += (nNmb-nDeleted);
}
}
oItem = GetNextItemInInventory(oPC);
}
}
Kato