Morrowind Mod:GetItemCount
< Mod / Morrowind: Morrowind Mod: Alphabetical Functions / Categorical FunctionsGetItemCount
GetItemCount, ObjectID Where: ObjectID = ID of object to get the count for Type: Object Returns: short or long (if more than 32267 of the item present) 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. If the calling object has more than 32267 of the given item and you are using a short variable, this will cause a 'wrap-around' error - numbers above 32267 start reading from -32267 (e.g. 35000 will read as -29534). To avoid this, use a long variable instead if there are likely to be so many. This is only likely when counting player gold.
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