Aller au contenu

Photo

ga_take_item


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
PJ156

PJ156
  • Members
  • 2 985 messages

I used ga_take_item on a custom item created for the module. Instead of taking the items one by one it is took the stack.

 

I built the script in Lilac Souls and the same thing happen. I am thinking perhaps the issue is with the item not the script. Has anyone had or sorted this issue in the past.

 

Thanks,

 

PJ

 

 



#2
Dann-J

Dann-J
  • Members
  • 3 161 messages

Scripts like ga_take_item or ga_destroy_item are notoriously bugged where stacked items are concerned. They tend to treat the entire stack as one item.

 

I've been using a corrected version of ga_destroy_item for years, which I think I saw posted on the old forums. It has an additional loop that deals with stacks. I use it in conjunction with CopyItem(), recreating the item in the new inventory and destroying it in the old.

// ga_destroy_item2
/*
This takes an item from a player
sItemTag = This is the string name of the item's tag
nQuantity = The number of items to destroy. -1 is all of the Player's items of that tag.
*/

#include "nw_i0_plot"

void DestroyItems(object oTarget,string sItem,int nNumItems)
{
int nCount = 0;
object oItem = GetFirstItemInInventory(oTarget);

while (GetIsObjectValid(oItem) == TRUE && nCount < nNumItems)
{
if (GetTag(oItem) == sItem)
{
int nRemainingToDestroy = nNumItems - nCount;
int nStackSize = GetItemStackSize(oItem);

if(nStackSize <= nRemainingToDestroy)
{
DestroyObject(oItem,0.1f);
nCount += nStackSize;
}
else
{
int nNewStackSize = nStackSize - nRemainingToDestroy;
SetItemStackSize(oItem, nNewStackSize);
break;
}
}
oItem = GetNextItemInInventory(oTarget);
}
return;
}

void main(string sItemTag,int nQuantity)
{

int nTotalItem;
object oPC = GetPCSpeaker();
object oItem; // Items in inventory

if ( nQuantity < 0 ) // Destroy all instances of the item
{
nTotalItem = GetNumItems( oPC,sItemTag );
DestroyItems( oPC,sItemTag,nTotalItem );
}
else
{
DestroyItems( oPC,sItemTag,nQuantity );
}

}


#3
PJ156

PJ156
  • Members
  • 2 985 messages

Thanks for the quick response DannJ.

 

I would be grateful to use this  but would a solution also be to set the item not to stack in the inventory?

 

PJ

 

[EDIT - I have just seen that you can't do that on the item properties so script it is. Thanks Dann_J] 



#4
Dann-J

Dann-J
  • Members
  • 3 161 messages

If it's a custom quest-related item then you can choose a base item type that doesn't stack.



#5
PJ156

PJ156
  • Members
  • 2 985 messages

Thanks Dann, that's what I did in the end.

 

PJ