GetInventoryObject
Revision as of 11:47, 19 February 2008 by imported>Haama (→Notes: Added link to snippet)
A function for Oblivion Script Extender
Syntax:
GetInventoryObject index
Must be called on a reference. Returns the indexth item in the container's inventory.
ExampleEdit
ref itemType set itemType to ( player.GetInventoryObject 0 ) container.additem itemType 1
Finds the first item in the player's inventory, and adds an object of the same type to a container.
NotesEdit
- Objects are listed in the order they were first picked up. If you pick up a sword, a bow, and a shield, GetInventoryObject 0 will return the sword, 1 will return the bow, and 2 the shield.
- Items remember what order they were in, so if you dropped the bow and picked it up again, it will still be returned by GetInventoryObject 1, and the shield will still be 2.
- However, every time you load a save game the order will be reversed. It's a bit more complicated, though. There are 2 sets of items for every container - those added during play (via script or directly) and those included in the base object (placed in the container in the CS; i.e., by default Player has LowerPants05, LowerShirt05, LowerShoes05, and WristIrons).
- Base Object Items - These will always come before the Added items. These will remain in the same order from save to save. However, some CS actions can reverse the order (not clear on which actions do this - referencing an instance of the container reversed the order, but commenting out the referencing lines didn't restore the original order).
- Added items - These always come after Base Object Items. Their order is reversed every save game. For instance, if you add an Apple and then an Orange to a container, scanning it will first return an Apple and then an Orange. However, once you save and reload, a scan will first return an Orange and then the Apple. Another save and reload will reverse the order again to Apple, Orange.
- Most importantly, this means that the original order of items will be hard to impossible to tell after a number of save games. For instance, if you add 2 items their order is 1, 2. If you add a third, the order could be 1, 2, 3 or 2, 1, 3. A fourth item could be 1, 2, 3, 4; 3, 2, 1, 4; 2, 1, 3, 4; or 3, 1, 2, 4, and so on.
- It is possible to pair up items, though. For instance, if you want to use an old clone of an ingredient you can place both in a container. Find the original ingredient and the clone will either be one spot before or after the original. See the Inventory Flipper tutorial to see how to tell which.
- However, every time you load a save game the order will be reversed. It's a bit more complicated, though. There are 2 sets of items for every container - those added during play (via script or directly) and those included in the base object (placed in the container in the CS; i.e., by default Player has LowerPants05, LowerShirt05, LowerShoes05, and WristIrons).
- Like GetNumItems, this works with unique items - if your 4th item was an arrow, and you have ten of them, GetInventoryItemType 3 (it starts with 0, 3 is the fourth value) will return Iron Arrow, and GetInventoryItemType 4 will return whatever is next, not another Iron Arrow.
- Prior to OBSE v0006, this function was known as GetInventoryItemType.
- Using this function every frame will significantly drop FPS (by 3 on my semi-old computer). If you need to run it constantly, try to find an alternative (i.e., linked lists of reference variables to the items and if (SomeNPC.GetItemCount pInvObj)), or only run it every few frames (5 or more). Note that this only applies to using the function every few frames, a 1000 of them in a single frame will take less than a second to run.
- As of v0013 this function is much faster, and should be safe to spam (at least as much as other functions). See this post for some stats.