Talk:OnContainerChanged - ObjectReference

From the CreationKit Wiki
Jump to navigation Jump to search

Bugs with Stacked Items[edit source]

I have a long discussion on potential bugs related to using this function on stacked items. See the discussion thread here: http://forums.bethsoft.com/topic/1349382-event-in-script-attached-to-misc-item-only-firing-once/

Does anyone have any suggestions as to how to summarize that for the wiki page? - Chesko

I haven't been able to reproduce your results. Here are my observations with an item that had an OnContainerChanged event attached:
  • A preplaced item that is rapidly picked up and dropped ten times in a row will fire twenty OnContainerChanged events, as expected.
  • Adding 12345 copies of an item via the console fires one OnContainerChanged event, as if you picked up a single stack (ObjectReference).
  • Dropping 12345 copies of an item, in a single operation, produces two in-world ObjectReferences (one of them is a stack of 12344, while the other is a single item), both of which fire an OnContainerChanged event for being dropped.
  • Picking up two preplaced copies of the item, one rapidly after another, produces two OnContainerChanged events.
  • Dropping two copies of the item, in two separate operations, one rapidly after another, produces two OnContainerChanged events.
The script I attached to the test item is as follows:
Scriptname AtronachCrossingTESTOnContainerChg extends ObjectReference Hidden

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
   Debug.Trace(Self + " contained changed from " + akOldContainer + " to " + akNewContainer)
EndEvent
DavidJCobb (talk) 2015-04-02T18:39:30 (EDT)

Script for Quest Stage Advancing Using OnContainerChanged[edit source]

Here is a sample script using the OnContainerChanged block type:

; Quest stage advances when the player finds the quest item:
Scriptname AAFoundTheQuestItem extends ObjectReference  

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
        if (akNewContainer == Game.GetPlayer())
                AAQuest.SetStage (15)
        endif
EndEvent

Quest Property AAQuest  Auto

--David Brasher 19:17, 27 April 2012 (EDT)

This example is already in Complete Example Scripts. --Fg109 19:44, 27 April 2012 (EDT)

Script for Quest Stage Advancing Using OnActivate[edit source]

Here is a script that can use an Event OnActivate block instead of an Event OnContainerChanged block:

; Quest stage advances when the player finds the quest item:
Scriptname AAFoundTheObject extends ObjectReference  

Event OnActivate (ObjectReference akActionRef)
        AAQuest.SetStage (15) 
EndEvent  

Quest Property AAQuest Auto

Note that the quest stage advances when the player activates the item, not when the player takes it and adds it to inventory. The player could forget to take an item like a book and could leave it in the dungeon. Then the player would walk all the way back to the quest-giver and realize that he or she didn't have the item and needed to go back to the dungeon and get it.

--David Brasher 18:47, 27 April 2012 (EDT)