Walking Through Inventory Items

From the Oblivion ConstructionSet Wiki
Revision as of 11:29, 19 February 2008 by imported>Haama (Created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

There are 2 ways to walk the inventory:

  1. From the end to the beginning - Easier to use with RemoveItem, but slower
  2. From beginning to end - faster

From the End to the Beginning

short InvPos
ref pInvObj
ref pCont
...
set pCont to YourDesiredContainer
set InvPos to pCont.GetNumItems
Label
if InvPos
  set InvPos to (InvPos - 1)
  set pInvObj to (pCont.GetInventoryObject InvPos)
  ;Do whatever you want to do
  ;You can run tests such as
    ;if (IsQuestItem pInvObj)
    ;if (pInvObj == Apple)
  Goto
endif

From the Beginning to the End

short InvPos
ref pInvObj
ref pCont
...
set pCont to YourDesiredContainer
set InvPos to 0
Label
set pInvObj to (pCont.GetInventoryObject InvPos)
if pInvObj
  set InvPos to (InvPos + 1)
  ;Do whatever you want to do
  ;You can run tests such as
    ;if (IsQuestItem pInvObj)
    ;if (pInvObj == Apple)
  Goto
endif

Notes

  • GetInventoryObject returns the base object FormID. It can't be used when a reference should be used. The information returned about it (i.e., using GetSoulLevel) will be about the base object and not necessarily each object in the player's inventory. That is, if the player has 2 petty soul gems, one filled and the other empty and you use GetSoulLevel it will return the same for both (empty).
  • Can be used for both containers and actors.