Editing
GetItemCount - ObjectReference
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[[Category:Scripting]] [[Category:Papyrus]] '''Member of:''' [[ObjectReference Script]] Returns how many of the specified item is in this reference's inventory. == Syntax == <syntaxhighlight lang="papyrus"> int Function GetItemCount(Form akItem) native </syntaxhighlight> == Parameters == *akItem: The item to look for in this reference's inventory. **If a reference, will look for just that particular reference. **If a base object (like armor or a weapon), it will count the how many instances of that base object are in the container **If a form list, it will count how many of each item in the form list is in the container and sum it all up **If a keyword, it will count how many items with that keyword are in the container == Return Value == How many of said item is in this reference's inventory. == Examples == <syntaxhighlight lang="papyrus"> if (Game.GetPlayer().GetItemCount(WeapTypeSwordKeyword) == 0) Debug.Trace("Player has no swords") endIf </syntaxhighlight> <br/> <syntaxhighlight lang="papyrus"> if (Game.GetPlayer().GetItemCount(SuperSecretPotionReference) == 0) Debug.Trace("Player doesn't have the super-secret potion") endIf </syntaxhighlight> == Notes == * If the argument akItem is a keyword and the object reference is an actor this function will fail to operate properly. A solution is to transfer the contents of the actor's inventory to a container and call the function on that container ( [http://forums.bethsoft.com/topic/1441239-cant-getitemcount-on-the-pc-via-formlist-of-keywords/page__pid__22196680#entry22196680/ Source (EN)] - [http://forum.wiwiland.net/index.php?/topic/54019-getitemcount-fonctionne-sur-les-conteneurs-mais-pas-les-acteurs/#entry721717 Source (FR)]). * In all cases, if the object reference contains CK-Defined Leveled lists of items then this function will fail to operate properly ([http://forums.bethsoft.com/topic/1444477-about-addressing-the-follower-bow-issue/ Source]) * If the argument akItem is a keyword and the object reference contains CK-defined items (Object References) then this function will fail to operate properly ([http://forums.bethsoft.com/topic/1441239-cant-getitemcount-on-the-pc-via-formlist-of-keywords/page__view__findpost__p__22215007 Source]) : it fails to include the CK-defined inventory when GetItemCount tries to calculate its count. *Calling this function on an objectreference from the outside of its cell will return 1 in the case of the passed in form being in a leveled list. Needs more testing.. but works fine if the player is in the same cell. == See Also == *[[ObjectReference Script]] *[[AddItem - ObjectReference]] *[[RemoveItem - ObjectReference]] *[[GetNumItems - ObjectReference]]
Summary:
Please note that all contributions to the CreationKit Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
CreationKit:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Landing page
Tutorials
Game Systems
Editor Reference
Scripting Reference
Recent changes
Help
Tools
What links here
Related changes
Special pages
Page information
Page values