Papyrus: OnItemAdded event isn't triggered by Take All

Post » Mon Sep 07, 2015 2:27 am

I have an odd issue where the OnItemAdded event isn't triggered when using Take All to remove ANY number of items from a container.

How can I make this work?

Here's the script:

ScriptName dubhKingOfThievesMiscStatFix Extends ReferenceAliasActor Property Player AutoFaction Property PlayerFaction AutoActorBase PlayerBaseEvent OnInit()	PlayerBase = Player.GetActorBase()EndEventEvent OnPlayerLoadGame()	PlayerBase = Player.GetActorBase()EndEventEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	Bool bIsContainerMenuOpen = UI.IsMenuOpen("ContainerMenu")	If bIsContainerMenuOpen		If akSourceContainer			Log("I picked up " + aiItemCount + "x " + akBaseItem + " from " + akSourceContainer)			If !IsContainerOwnedByPlayer(akSourceContainer)				Game.IncrementStat("Items Stolen", aiItemCount)				Log("Increased 'Items Stolen' stat by " + aiItemCount)			EndIf		EndIf	EndIfEndEventBool Function IsContainerOwnedByPlayer(ObjectReference aContainer)	ActorBase actorOwner	Faction factionOwner	If aContainer		actorOwner = aContainer.GetActorOwner()		If !actorOwner			actorOwner = aContainer.GetParentCell().GetActorOwner()			If !actorOwner				factionOwner = aContainer.GetFactionOwner()				If !factionOwner					factionOwner = aContainer.GetParentCell().GetFactionOwner()				EndIf			EndIf		EndIf		If actorOwner			Return actorOwner == PlayerBase		ElseIf factionOwner			Return factionOwner == PlayerFaction		Else			Return True		EndIf	Else		Return True	EndIfEndFunctionFunction Log(String msgTrace)	Debug.Trace("King of Thieves: dubhKingOfThievesMiscStatFix> " + msgTrace)EndFunction
User avatar
Melanie Steinberg
 
Posts: 3365
Joined: Fri Apr 20, 2007 11:25 pm

Post » Sun Sep 06, 2015 9:37 pm

Have you tried adding a trace outside of the outermost if-statement to check if OnItemAdded is called at all? Maybe the container menu closes before OnItemAdded can be called, thus leading to bIsContainerMenuOpen being false?

Spoiler
Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	Log("OnItemAdded")	Bool bIsContainerMenuOpen = UI.IsMenuOpen("ContainerMenu")	If bIsContainerMenuOpen		If akSourceContainer			Log("I picked up " + aiItemCount + "x " + akBaseItem + " from " + akSourceContainer)			If !IsContainerOwnedByPlayer(akSourceContainer)				Game.IncrementStat("Items Stolen", aiItemCount)				Log("Increased 'Items Stolen' stat by " + aiItemCount)			EndIf		EndIf	EndIfEndEvent 
User avatar
Rachel Cafferty
 
Posts: 3442
Joined: Thu Jun 22, 2006 1:48 am

Post » Sun Sep 06, 2015 11:13 pm

That looks like what's happening. Is there a fix?

User avatar
Veronica Flores
 
Posts: 3308
Joined: Mon Sep 11, 2006 5:26 pm

Post » Sun Sep 06, 2015 10:58 pm

Does it break anything if you remove the bIsContainerMenuOpen check?

User avatar
Emma Copeland
 
Posts: 3383
Joined: Sat Jul 01, 2006 12:37 am


Return to V - Skyrim