Morrowind Mod:GetItemCount

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search


GetItemCount

                GetItemCount, ObjectID

       Where:   ObjectID = ID of object to get the count for

        Type:   Object

     Returns:   short?

     Example:   if ( player->GetItemCount, "gold_001" == 11171 )
                if ( GetItemCount, "blessed_shield" > 0 )
                short ObjectCount
                set ObjectCount to ( Player->GetItemCount, "wraithguard" )

     Scripts:   blueScript
                DagothTaunt_1

Returns the number of the objectID contained in the calling object. May not work correctly if the calling object has more than 32267 of the given item (unconfirmed) [Consider using a long variable instead of short - RogiVagel].

There is a bug with this function when used on containers (possibly related to the AddItem/RemoveItem bug). If the player chooses the Take All button on the container then subsequent GetItemCount calls on the container will return the number of items in the container before the player took everything.

One way to get around this bug is to set the chest as persistent and use a temporary persistent ingredient in the chest. The persistent ingredient is hidden in the sense that it is added initially to the chest from a script, removed when the player opens the container, and added back again when the container is closed. See the below script for an example:

begin HidePersistent
        short doOnce

        if ( onActivate == 1 )
                RemoveItem, "PersistentIngredient", 1
                set doOnce to 1
        endif


        if ( doOnce == 1 )
                If ( onActivate == 1 )
                        ; do nothing
                elseif ( Activate == 1 )
                        ; do nothing
                elseif ( MenuMode == 1 )
                        ; do nothing
                else
                        AddItem, "PersistentIngredient", 1
                        Set doOnce to 0
                        return
                endif
        endif
end