Ahh true, you remind me that TakeNumItems() does not handle stacks correctly. Here is a function which should do it, provided you pass the correct parameters.
void TakeItemFromCreature(object oPC, string sTag, int nNum)
{
object oItem = GetFirstItemInInventory(oPC);
int nDestroyed, nStack, nDel;
while(oItem != OBJECT_INVALID && nDestroyed < nNum)
{
if(GetTag(oItem) == sTag)
{
nStack = GetItemStackSize(oItem);
nDel = nNum - nDestroyed;
if(nStack <= nDel)
{
DestroyObject(oItem);
nDestroyed += nStack;
}
else
{
SetItemStackSize(oItem, nStack - nDel);
nDestroyed += nDel;
}
}
oItem = GetNextItemInInventory(oPC);
}
}
It's from my old arsenal and thus could probably be optimized but it works well nonetheless
'>
Kato
Modifié par Kato_Yang, 16 juin 2012 - 03:56 .