Replacing items in merchant containers through script

Post » Tue Jun 19, 2012 11:35 am

I think I need to revise a script because although it is running, it is not doing what I want it to. The goal is to check merchant containers (which are being stored in FormList set A) for items in FormList set B, and if found, replace those items with equivalents in FormList set C.

Scriptname aaTKMerchantOverwatchScript extends QuestFormList property aaTKSLMerchants autoFormList property aaTKMKMerchants autoFormList property aaTKWHMerchants autoFormList property aaTKRFMerchants autoFormList property aaTKWRMerchants autoFormList property aaTKSLBase autoFormList property aaTKMKBase autoFormlist property aaTKWHBase autoFormList property aaTKRFBase autoFormList property aaTKWRBase autoFormList property aaTKSLImports autoFormList property aaTKMKImports autoFormlist property aaTKWHImports autoFormList property aaTKRFImports autoFormList property aaTKWRImports autoEvent OnUpdate()CheckContainers(aaTKSLMerchants, aaTKSLBase, aaTKSLImports)CheckContainers(aaTKMKMerchants, aaTKMKBase, aaTKMKImports)CheckContainers(aaTKWHMerchants, aaTKWHBase, aaTKWHImports)CheckContainers(aaTKRFMerchants, aaTKRFBase, aaTKRFImports)CheckContainers(aaTKWRMerchants, aaTKWRBase, aaTKWRImports)Debug.Notification("Updating merchant item prices")RegisterForSingleUpdate(10)EndEventFunction MerchStartCheck()    RegisterForSingleUpdate(1)    EndFunctionFunction CheckContainers(FormList MerchContainer, FormList Base, FormList Imports)    int i = 0    int x = 0        While i < MerchContainer.getSize()            ObjectReference Target = MerchContainer.getAt(i) as ObjectReference                If Target != none && Target.IsEnabled()                    While x < Base.GetSize()                        ObjectReference ItemTarget = Base.getAt(x) as ObjectReference                ObjectReference ImportTarget = Imports.getAt(x) as ObjectReference                            If Target.GetItemCount(ItemTarget) != 0                                Int ItemCount = Target.GetItemCount(ItemTarget)                                    Target.RemoveItem(ItemTarget, ItemCount)                    Target.AddItem(ImportTarget, ItemCount)                                EndIf                        x += 1                    EndWhile                    EndIf                i += 1            EndWhile    EndFunction

The Event triggers properly, but the container contents are always the same after it does (the items I'm asking to be replaced are not being replaced), so I'm wondering if I missed anything as to how to adjust the contents of merchant containers properly.
User avatar
sara OMAR
 
Posts: 3451
Joined: Wed Jul 05, 2006 11:18 pm

Post » Tue Jun 19, 2012 1:21 pm

I'm trying to revise the script to figure out why the function is not firing correctly, but until I know exactly why, I'm working blind.

(This script doesn't compile because the Target Variable is only good for the loop it is called in.)

Spoiler
Scriptname aaTKMerchantOverwatchScript extends QuestFormList property aaTKSLMerchants autoFormList property aaTKMKMerchants autoFormList property aaTKWHMerchants autoFormList property aaTKRFMerchants autoFormList property aaTKWRMerchants autoFormList property aaTKSLBase autoFormList property aaTKSLImports autoFormList property aaTKMKBase autoFormList property aaTKMKImports autoFormlist property aaTKWHBase autoFormlist property aaTKWHImports autoFormList property aaTKRFBase autoFormList property aaTKRFImports autoFormList property aaTKWRBase autoFormList property aaTKWRImports autoEvent OnUpdate()CheckContainers(aaTKSLMerchants, aaTKSLBase, aaTKSLImports)CheckContainers(aaTKMKMerchants, aaTKMKBase, aaTKMKImports)CheckContainers(aaTKWHMerchants, aaTKWHBase, aaTKWHImports)CheckContainers(aaTKRFMerchants, aaTKRFBase, aaTKRFImports)CheckContainers(aaTKWRMerchants, aaTKWRBase, aaTKWRImports)RegisterForSingleUpdate(10)EndEventFunction MerchStartCheck()	RegisterForSingleUpdate(1)	EndFunctionFunction CheckContainers(FormList MerchContainer, FormList Base, FormList Imports)	int i = 0		While i < MerchContainer.getSize()			ObjectReference Target = MerchContainer.getAt(i) as ObjectReference				i += 1			EndWhile	int x = 0			While x < Base.GetSize()			If Target != none && Target.IsEnabled()				ObjectReference ItemTarget = Base.getAt(x) as ObjectReference		ObjectReference ImportTarget = Imports.getAt(x) as ObjectReference						If Target.GetItemCount(ItemTarget) != 0							Int ItemCount = Target.GetItemCount(ItemTarget)								Target.RemoveItem(ItemTarget, ItemCount)				Target.AddItem(ImportTarget, ItemCount)								Debug.Notification("Updating Merchant Prices")							EndIf					x += 1				EndIf			EndWhile	EndFunction
User avatar
Sharra Llenos
 
Posts: 3399
Joined: Wed Jan 17, 2007 1:09 pm

Post » Tue Jun 19, 2012 10:10 am

I was trying to do something like this to avoid editing leveled lists, adding new items directly to merchant containers via script. It worked, but the merchant's inventory wouldn't update until I'd bartered with them at least once. What I'm doing now as a stopgap solution is adding them directly to the merchant's personal inventory via script, though I don't think that would help you much. I wonder if there's some way to make a merchant reevaluate their inventory, similar to how you can make an actor reevaluate their run speed by damaging a leg or changing their carryweight.
User avatar
marie breen
 
Posts: 3388
Joined: Thu Aug 03, 2006 4:50 am


Return to V - Skyrim