void TakeNumItemsFromPC(object oPC, string sRef, 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);
}
}
Modify the function accordingly if you prefer using the tag instead of the resref.
Kato