GetNumStackedItems(object, int)

From NWN Lexicon
Jump to navigationJump to search

Determines the number of stacked items contained within an inventory object.

int GetNumStackedItems(
    object oItem
);

Parameters

oItem
The item to determine the stack count of.


Description

Returns the number of items in a stack attached to oItem. Only items that are the same may be stacked; i.e. two gems of the same name can be stacked, but a sword and an arrow cannot.


Remarks

Returns -1 if an invalid object is provided for oItem, or if oItem isn't an item (like a creature or a placeable).

You can check an items stack size maximum with Get2DAString and checking baseitems.2da column "Stacking".

This function is pretty much identical (except the return value when a non-item is checked) to GetItemStackSize, which was added later to likely be the logical counterpart to SetItemStackSize.


Version

1.22

Example

// Checks for the amount of arrows on a PC in a conversation
void main()
{
    object oPC = GetPCSpeaker();
    object oItem = GetItemInSlot(INVENTORY_SLOT_ARROWS, oPC);

    int nArrows = 0;
    if(GetIsObjectValid(oItem))
    {
        nArrows += GetNumStackedItems(oItem);
    }

    // Loop inventory for arrows
    oItem = GetFirstItemInInventory(oPC);
    while(GetIsObjectValid(oItem))
    {
        if(GetBaseItemType(oItem) == BASE_ITEM_ARROW)
        {
            nArrows += GetNumStackedItems(oItem);
        }
        oItem = GetNextItemInInventory(oPC);
    }
    SpeakString("You have " + IntToString(nArrows) + " in your inventory.");
}

See Also

functions:

GetItemStackSize SetItemStackSize



author: Sarev0k, editors: Tom Cassiotis, Fireboar, Kookoo, Mistress