RemoveItemByComponent - ObjectReference

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search

Member of: ObjectReference Script

Removes an arbitrary number of arbitrary items such that at least the specified number of the specified component is removed from this reference's inventory, possibly silently.

Syntax[edit | edit source]

Function RemoveItemByComponent(Form akComponentToRemove, int aiCount = 1, bool abSilent = false, ObjectReference akOtherContainer = None) native

Parameters[edit | edit source]

  • akComponentToRemove: The component or form list of components the items to be removed must contain.
  • aiCount: How many components to remove. (Not items)
    • 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[edit | edit source]

None.

Examples[edit | edit source]

; Remove 5 (or more) leather
Chest.RemoveItemByComponent(c_Leather, 5)

Notes[edit | edit source]

  • The function searches the object's inventory in the order it is stored in memory looking for objects with the specified component or one of the components in the form list. When one is found, that item is removed from inventory and the number to be removed is deducted by the component count of the removed item. The process continues until the number to be removed reaches zero.
  • This function is dependent on the order in which the items are stored and therefore gives the caller no control over which or how many items are actually removed.
  • To remove [n] items with the given component, rather than [n] components, use RemoveItem instead.
  • Items are removed, they are not scrapped, and the "change" is not returned to the container. If you want scrapping behavior, use RemoveComponents instead.

Examples:

  • If the container has two objects that each have two copper, and you call this function with copper, and a count of two, then one item will be removed.
  • If the container has two objects that each have two copper, and you call this function with copper, and a count of three, then both items will be removed.
  • If the container has two objects that provide one copper and one glass, and you call this function with a form list containing copper and glass, with a count of two, then one item will be removed.

See Also[edit | edit source]