SetItemStackSize

From NWN Lexicon
Jump to: navigation, search

SetItemStackSize(object, int)

Set the number of items in a given stack.

void SetItemStackSize(
    object oItem,
    int nSize
);

Parameters

oItem

Item to set the stack size of.

nSize

New stack size.

Description

Sets the number of items in a given stack. If a number less than 1 is passed, then the stack size is set to 1 (not destroyed like the SetItemCharges function). If a number greater than the maximum stack size for an item of its type is passed, the number of items in the stack is set to the item's maximum stack size.

Remarks

Other than removing a single item from a stack of, say, potions (or adding one), this function can be used to determine if an item is stackable or not. See code sample below.

Known Bugs

Setting the stack size on an item at ground won't updates to the nearby players.

Version

1.30

Example

//Returns TRUE if oItem is stackable
int GetIsStackableItem(object oItem)
{
//Must have a chest tagged checkchest
 
object oCopy=CopyItem(oItem, GetObjectByTag("checkchest"));
 
//Set the stacksize to two
SetItemStackSize(oCopy, 2);
 
//Check if it really is two - otherwise, not stackable!
int bStack=GetItemStackSize(oCopy)==2;
 
//Destroy the test copy
DestroyObject(oCopy);
 
//Return bStack which is TRUE if item is stackable
return bStack;
}

See Also

functions: 

TakeNumItems


 author: Charles Feduke, editor: Lilac Soul, additional contributor(s): Lilac Soul