OnItemAdded Issues

Post » Sun Aug 31, 2014 6:51 am

So I have a few aliases set up, and then a script on my player alias. My Player alias is a specific reference, PlayerRef, and my other alias, "Package" is a Create Reference At Object alias, and is created inside my Dead Courier, which is a Specific Reference and properly set to my dead courier. I have a script on the player, and I've checked that all of the properties and aliases are set correctly. It uses the OnItemAdded event. I could use OnContainerChanged, in this case, but I'd just like to know if there's anything explicitly wrong with my script (which compiles correctly) that is causing it not to work, or if it's just OnItemAdded being finicky.

My Script:

Spoiler
Scriptname IQ02PlayerAliasScript extends ReferenceAlias  {Governs all the functions and actions related to the player in Disrupted Service.}Message Property PackageAddedMes Auto Message Property OpenConfirmationMes Auto ReferenceAlias Property CourierNote AutoWeapon Property Cutlass Auto Armor Property Buckler Auto ReferenceAlias Property PackageAlias AutoReferenceAlias Property FNVEasterEgg Auto ReferenceAlias Property DeadCourier Auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If akBaseItem == PackageAlias.GetReference() 		Utility.Wait(0.1)		Int iButton = PackageAddedMes.Show()		While iButton			If iButton == 1				CourierNote.GetReference().Activate(Self.GetReference())				If Self.GetReference().GetItemCount(CourierNote.GetReference())									Self.GetReference().AddItem(CourierNote.GetReference(), 1)				EndIf			ElseIf iButton == 2				iButton = OpenConfirmationMes.Show()				While iButton					If iButton == 1						Self.GetReference().RemoveItem(PackageAlias.GetReference(), 1)						GetOwningQuest().SetStage(200)						Self.GetReference().AddItem(Cutlass, 1)						Self.GetReference().AddItem(Buckler, 1)					ElseIf iButton == 2						CourierNote.GetReference().Activate(Self.GetReference())						If Self.GetReference().GetItemCount(CourierNote.GetReference())											Self.GetReference().AddItem(CourierNote.GetReference(), 1)						EndIf					EndIf				EndWhile			EndIf		EndWhile	ElseIf akBaseItem == FNVEasterEgg.GetReference()		Debug.Notification("Would have resurrected courier here.")	EndIfEndEvent	
User avatar
Joey Avelar
 
Posts: 3370
Joined: Sat Aug 11, 2007 11:11 am

Post » Sun Aug 31, 2014 3:03 pm

Needed to use ItemReference instead. Oops.

User avatar
Multi Multi
 
Posts: 3382
Joined: Mon Sep 18, 2006 4:07 pm

Post » Sun Aug 31, 2014 11:02 am

Just for reference, is there anything incredibly inefficient about this script?

Spoiler
Scriptname IQ02PlayerAliasScript extends ReferenceAlias  {Governs all the functions and actions related to the player in Disrupted Service.}Message Property PackageAddedMes Auto Message Property OpenConfirmationMes Auto ReferenceAlias Property CourierNote AutoWeapon Property Cutlass Auto Armor Property Buckler Auto ReferenceAlias Property PackageAlias AutoReferenceAlias Property FNVEasterEgg Auto ReferenceAlias Property DeadCourier Auto Int NoteOnce = 0Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If akItemReference == PackageAlias.GetReference() 		Utility.Wait(0.1)		Int iButton = PackageAddedMes.Show()		While iButton			If iButton == 1				If NoteOnce == 0					CourierNote.GetReference().Activate(Self.GetReference())					NoteOnce = 1				EndIf				If Self.GetReference().GetItemCount(CourierNote.GetReference())									Self.GetReference().AddItem(CourierNote.GetReference(), 1)				EndIf			ElseIf iButton == 2				iButton = OpenConfirmationMes.Show()				While iButton					If iButton == 1						Self.GetReference().RemoveItem(PackageAlias.GetReference(), 1)						GetOwningQuest().SetStage(200)						Self.GetReference().AddItem(Cutlass, 1)						Self.GetReference().AddItem(Buckler, 1)					ElseIf iButton == 2						If NoteOnce == 0							CourierNote.GetReference().Activate(Self.GetReference())							NoteOnce = 1						EndIf						If Self.GetReference().GetItemCount(CourierNote.GetReference())											Self.GetReference().AddItem(CourierNote.GetReference(), 1)						EndIf					EndIf				EndWhile			EndIf		EndWhile	ElseIf akItemReference == FNVEasterEgg.GetReference()		Debug.Notification("Would have resurrected courier here.")	EndIfEndEvent	

EDIT: Yeah, there's a lot wrong with it. I'll paste the fixed version that won't constantly spam the adding of items and removing and every single function...

User avatar
Christine Pane
 
Posts: 3306
Joined: Mon Apr 23, 2007 2:14 am

Post » Sun Aug 31, 2014 5:22 am

Okay, here's the actual fixed scripts. The same question above applies: Anyway to increase efficiency?

Spoiler
Scriptname IQ02PlayerAliasScript extends ReferenceAlias  {Governs all the functions and actions related to the player in Disrupted Service.}Message Property PackageAddedMes Auto Message Property OpenConfirmationMes Auto ReferenceAlias Property CourierNote AutoWeapon Property Cutlass Auto Armor Property Buckler Auto ReferenceAlias Property PackageAlias AutoReferenceAlias Property FNVEasterEgg Auto ReferenceAlias Property DeadCourier Auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If akItemReference == PackageAlias.GetReference() 		Utility.Wait(0.1)		Int iButton = PackageAddedMes.Show()		While iButton			If iButton == 1				If Self.GetReference().GetItemCount(CourierNote.GetReference())									Self.GetReference().AddItem(CourierNote.GetReference(), 1)				EndIf				CourierNote.GetReference().Activate(Self.GetReference())				iButton = 0			ElseIf iButton == 2				iButton = OpenConfirmationMes.Show()				While iButton					If iButton == 1						Self.GetReference().RemoveItem(PackageAlias.GetReference(), 1)						GetOwningQuest().SetStage(200)						Self.GetReference().AddItem(Cutlass, 1)						Self.GetReference().AddItem(Buckler, 1)						iButton = 0					ElseIf iButton == 2						If Self.GetReference().GetItemCount(CourierNote.GetReference()) == 0											Self.GetReference().AddItem(CourierNote.GetReference(), 1)						EndIf						CourierNote.GetReference().Activate(Self.GetReference())						iButton = 0					EndIf				EndWhile			EndIf		EndWhile	ElseIf akItemReference == FNVEasterEgg.GetReference()		Debug.Notification("Would have resurrected courier here.")	EndIfEndEvent	
User avatar
Nicole Kraus
 
Posts: 3432
Joined: Sat Apr 14, 2007 11:34 pm

Post » Sun Aug 31, 2014 5:22 pm

The function AddInventoryEventFilter can be used so that the OnItemAdded will only trigger for those items. http://www.creationkit.com/AddInventoryEventFilter_-_ObjectReference

I see quite a few things like this...

Self.GetReference().DoSomething()Self.GetReference().DoSomethingElse()Self.GetReference().DoSomeOtherThing()

It's easier just to do...

ObjectReference kRef = Self.GetReference()kRef.DoSomething()kRef.DoSomethingElse()kRef.DoSomeOtherThing()

Also, what are the while loops for?

User avatar
Amy Gibson
 
Posts: 3540
Joined: Wed Oct 04, 2006 2:11 pm

Post » Sun Aug 31, 2014 7:41 pm

I'll fix those.

And I'm not great at messageboxes, but when I asked for some help on them, egocarib recommended that method. See http://www.gamesas.com/topic/1506246-messagebox-problems/?hl=%2Bmessagebox#entry23742714.

User avatar
Eibe Novy
 
Posts: 3510
Joined: Fri Apr 27, 2007 1:32 am


Return to V - Skyrim