Difference between revisions of "OnItemAdded - ObjectReference"

imported>DavidJCobb
m (→‎Notes: differing filters)
imported>DavidJCobb
Line 38: Line 38:
**This trick stops OnItemAdded calls from ''being queued.'' It doesn't prevent the execution of function calls that have already been queued. To wit, using this trick from inside of OnItemAdded won't stop Skyrim from dumping stacks when you Take All from a QASmoke container, because the first OnItemAdded call only executes after the other hundred or so have been queued. Rather, you'd want to stop listening to inventory events from elsewhere (e.g. an OnMenuOpen event checking for inventory menus, if you don't mind relying on SKSE).
**This trick stops OnItemAdded calls from ''being queued.'' It doesn't prevent the execution of function calls that have already been queued. To wit, using this trick from inside of OnItemAdded won't stop Skyrim from dumping stacks when you Take All from a QASmoke container, because the first OnItemAdded call only executes after the other hundred or so have been queued. Rather, you'd want to stop listening to inventory events from elsewhere (e.g. an OnMenuOpen event checking for inventory menus, if you don't mind relying on SKSE).
*Remember that you can point multiple reference aliases at the player. Each can have their own inventory event filters and inventory event handlers, so you can filter OnItemAdded and OnItemRemoved differently.
*Remember that you can point multiple reference aliases at the player. Each can have their own inventory event filters and inventory event handlers, so you can filter OnItemAdded and OnItemRemoved differently.
*If you call RemoveItem from this event handler, it ''does'' fire an OnItemRemoved event. This can lead to a tricky situation if you need to reject certain items, but ''also'' detect if the player manually removes an item (e.g. a full bookshelf rejecting a deposited book, without mistaking its own rejection for a withdrawal).
**You can use the AddInventoryEventFilter and an empty FormList to stop events from being fired immediately before you call RemoveItem; and then resume events with RemoveInventoryEventFilter. There will be a very brief window of time during which another added item may go unnoticed, but generally this is the best method to avoid confusing rejections and withdrawals.


== See Also ==
== See Also ==
Anonymous user