Difference between revisions of "OnItemRemoved - ObjectReference"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>DavidJCobb
(→‎Notes: OnItemRemoved + no inventory event filter + RemoveAllItems = recipe for disaster. You don't want to ruin the Thalmor embassy mission, now, do you? :()
imported>DavidJCobb
Line 33: Line 33:
*If you only care about certain kinds of objects, you should also use [[AddInventoryEventFilter - ObjectReference|AddInventoryEventFilter]] to filter out any events for things you aren't interested in.
*If you only care about certain kinds of objects, you should also use [[AddInventoryEventFilter - ObjectReference|AddInventoryEventFilter]] to filter out any events for things you aren't interested in.
**Refer to the notes for [[OnItemAdded - ObjectReference#Notes|OnItemAdded]] to get an idea of how important this is.
**Refer to the notes for [[OnItemAdded - ObjectReference#Notes|OnItemAdded]] to get an idea of how important this is.
**If something calls [[RemoveAllItems - ObjectReference|RemoveAllItems]] and you don't use an inventory event filter, then for every type of item removed from the object's inventory, one call to your OnItemRemoved event handler will be queued. If the player is holding a very wide variety of items (like alchemy ingredients and books in addition to the player's usual gear), then Skyrim will queue up more calls than it can even hold, and end up dumping stacks instantly. One in-game example of this? The Thalmor embassy quest in the main questline, in which a character takes possession of all items in the player's inventory when the actual mission starts.
**If something calls [[RemoveAllItems - ObjectReference|RemoveAllItems]] and you don't use an inventory event filter, then for every type of item removed from the object's inventory, one call to your OnItemRemoved event handler will be queued. If the player is holding a very wide variety of items (like alchemy ingredients and books in addition to the player's usual gear), then Skyrim may queue up more calls than it can even keep track of, causing an instant stack dump.
***The "Diplomatic Immunity" quest is a good testcase for this; getting thrown in jail may also work.
*If the item is consumed by any means (crafting, charging, poisoning, eat/drink) the dest parameter is None and most likely, but not always, the reference is None too.
*If the item is consumed by any means (crafting, charging, poisoning, eat/drink) the dest parameter is None and most likely, but not always, the reference is None too.
* If player uses a poison to apply it to a weapon the event is fired twice: before and after the confirmation dialogue. If canceled in the confirmation dialogue then is not fired twice.
* If player uses a poison to apply it to a weapon the event is fired twice: before and after the confirmation dialogue. If canceled in the confirmation dialogue then is not fired twice.

Revision as of 21:10, 28 February 2015

Member of: ObjectReference Script

Event received when an item is removed from this object's container.

Syntax

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

Parameters

  • akBaseItem: The base object for the item that was removed from this container.
  • aiItemCount: The number of items removed from this container.
  • akItemReference: The specific reference removed from the container, if any. Will be None if a non-persistant object is moved to a different container; a persistant or not item used in crafting, (most likely) when consumed. If a non-persistant item is dropped from inventory into the world the generated reference is received.
  • akDestContainer: The container that the object(s) went to. If None, then the object was dropped into the world, used in crafting or consumed.

Examples

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  if !akDestContainer
    Debug.Trace("I dropped " + aiItemCount + "x " + akBaseItem + " into the world")
  elseif akDestContainer == Game.GetPlayer()
    Debug.Trace("I gave the player " + aiItemCount + "x " + akBaseItem)
  else
    Debug.Trace("I gave " + aiItemCount + "x " + akBaseItem + " to another container")
  endIf
endEvent

Notes

  • If you only care about certain kinds of objects, you should also use AddInventoryEventFilter to filter out any events for things you aren't interested in.
    • Refer to the notes for OnItemAdded to get an idea of how important this is.
    • If something calls RemoveAllItems and you don't use an inventory event filter, then for every type of item removed from the object's inventory, one call to your OnItemRemoved event handler will be queued. If the player is holding a very wide variety of items (like alchemy ingredients and books in addition to the player's usual gear), then Skyrim may queue up more calls than it can even keep track of, causing an instant stack dump.
      • The "Diplomatic Immunity" quest is a good testcase for this; getting thrown in jail may also work.
  • If the item is consumed by any means (crafting, charging, poisoning, eat/drink) the dest parameter is None and most likely, but not always, the reference is None too.
  • If player uses a poison to apply it to a weapon the event is fired twice: before and after the confirmation dialogue. If canceled in the confirmation dialogue then is not fired twice.

See Also