GetNumStackedItems(object, int)

From NWN Lexicon
Revision as of 10:45, 21 June 2022 by Jasperre (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

int GetNumStackedItems(
    object oItem


The item to determine the stack count of.


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.


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.




// 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;
        nArrows += GetNumStackedItems(oItem);

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

See Also


GetItemStackSize SetItemStackSize

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