Editing
RemoveItem - 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]] Removes X of the specified item from this reference's inventory, possibly silently. == Syntax == <syntaxhighlight lang="papyrus"> Function RemoveItem(Form akItemToRemove, int aiCount = 1, bool abSilent = false, ObjectReference akOtherContainer = None) native </syntaxhighlight> == Parameters == *akItemToRemove: The item (or other form) to remove from this reference's inventory. Different form types yield different behaviors: **'''Item base form:''' ''aiCount'' of the item will be removed. **'''FormList:''' ''aiCount'' of each base form in the FormList will be removed. However, if the FormList is empty, a Papyrus error will occur. **'''ObjectReference:''' The reference will be removed from the inventory and then deleted. *aiCount: How many references to remove. **'''Default:''' 1 *abSilent: If true, no message will be printed to the screen **'''Default:''' false *akOtherContainer: If not None, the removed item(s) will be moved into this ref's inventory **'''Default:''' None == Return Value == None. == Examples == <syntaxhighlight lang="papyrus"> ; Take away an apple Chest.RemoveItem(Apple) </syntaxhighlight> <br> <syntaxhighlight lang="papyrus"> ; Remove 50 gold from the player Game.GetPlayer().RemoveItem(GoldBase, 50) </syntaxhighlight> ==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. *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): <syntaxhighlight lang="papyrus"> Function SomeFunction() ;In this example, let's say you have 2 misc objects in your formlist. ;This script will remove 10 count of any quantity of those items. ;So it could be 5 of one, 5 of the other, or 9 of one and 1 of the other. 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 </syntaxhighlight> *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. *This function does not work on items pre-placed inside containers until that container is opened and its contents are finally loaded by the game. **Solution for scenarios that need to remove such items: ***Use [[RemoveAllItems - ObjectReference]] to transfer the entire container's contents to a separate container ***Use the [[OnItemAdded - ObjectReference]] event on the second container to obtain the incoming items ***Finally use [[RemoveItem - ObjectReference]] to send all but the unwanted item(s) back to the first container *The function does not work on object references that have only existed inside containers, for example an item the player has crafted. Even if you use the Self reference. == See Also == *[[ObjectReference Script]] *[[AddItem - ObjectReference]] *[[GetItemCount - ObjectReference]] *[[RemoveAllItems - 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