Difference between revisions of "RemoveItem - ObjectReference"
Jump to navigation
Jump to search
RemoveItem - ObjectReference (edit)
Revision as of 07:54, 22 September 2013
, 07:54, 22 September 2013added a script for removing items using a form list
imported>Perdev |
imported>B1gBadDaddy (added a script for removing items using a form list) |
||
Line 35: | Line 35: | ||
==Notes== | ==Notes== | ||
*The function accepts a form object, however you can't make a property to a form object, you need to create a property to another type of object that extends form. Most often a MiscObject, or Weapon, etc. | *The function accepts a form object, however you can't make a property to a form object, you need to create a property to another type of object that extends form. Most often a MiscObject, or Weapon, etc. | ||
*If you pass in a form list, it will remove aiCount of each item in the form list from the container. If there isn't aiCount of a particular item in the container, it will remove all of them. | *If you pass in a form list, it will remove aiCount of each item in the form list from the container. If there isn't aiCount of a particular item in the container, it will remove all of them. If you wish to remove X amount of objects from a container, by checking against a form list, use the following script (the script uses PlayerREF as the ObjectReference to remove items from): | ||
<source lang="papyrus"> | |||
Function SomeFunction() | |||
int ListSize = myFormList.GetSize() | |||
int CurrentItems = 0 | |||
int ItemsLeft = 10; remove 10 items, change this to whatever number you want to remove | |||
while CurrentItems <= ListSize && ItemsLeft > 0 | |||
Form CurrentItem1 = myFormList.GetAt(CurrentItems) | |||
int ItemCount = PlayerREF.GetItemCount(CurrentItem1) | |||
PlayerREF.RemoveItem(CurrentItem1, ItemsLeft) | |||
ItemsLeft -= ItemCount | |||
CurrentItems += 1 | |||
endwhile | |||
endFunction | |||
</source> | |||
*The function seems to have a preference for equipped items. Or if not equipped items then the first instance of the item that's in inventory (which is the same thing, since when you equip something, it's the first instance of the object in the inventory). | *The function seems to have a preference for equipped items. Or if not equipped items then the first instance of the item that's in inventory (which is the same thing, since when you equip something, it's the first instance of the object in the inventory). | ||
*The akItemToAdd argument of [[AddItem - ObjectReference]] can be a LeveledItem. A LeveledItem as akItemToRemove, however, won't work and the members of the LeveledItem must be passed individually as akItemToRemove. | *The akItemToAdd argument of [[AddItem - ObjectReference]] can be a LeveledItem. A LeveledItem as akItemToRemove, however, won't work and the members of the LeveledItem must be passed individually as akItemToRemove. |