[Tutorial] How to fix the vanishing merchant stock bug

Releases, works in progress, help, reviews, ideas, tutorials
Post Reply
User avatar
Selene310187
Site Admin
Joined: Fri Oct 07, 2022 8:34 pm
Contact:

[Tutorial] How to fix the vanishing merchant stock bug

Post by Selene310187 »

The vanishing merchant stock bug can occur with summonable merchants and merchant followers.

Sometimes these NPCs can loose their connection to their merchant chest. I experienced this during the development of SESM and the Dremora Merchant Tweak (old and deleted mod; I'm working on a rewrite with more features). Regarding the merchants of SESM, they couldn't access the chest containing the stock (leveled items, potions, armors, etc.) anymore after they became followers and the player entering another cell. If you reload a save and summon Dragonborn's Dremora Merchant, the merchant will not have any gold or items in his stock. Resummoning him solves the problem temporarily.

I solved both problems by implementing "invisible" middlemen. The middlemen are NPCs in a remote (interior) cell. They will trade with the player on behalf of the original merchants using the default merchant factions and without any follower factions. They are named after the original merchants so that the player will not notice the workaround ;).

Regarding the Dremora Merchant, I duplicated the NPC, the merchant faction and the merchant chest. Then I put the duplicated NPC (who is the middleman) and the duplicated chest into the remote cell. I replaced the merchant faction of the duplicated NPC with the duplicated merchant faction and let the duplicated faction point to the duplicated merchant chest. I also removed the gold from the chest as I add it to the middleman via script.

I modified the trading dialogue script fragment:
 

Code: Select all

Scriptname DLC2_TIF__0201EEAC Extends TopicInfo Hidden

Function Fragment_0(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor

(GetOwningQuest() as SESM_Dremora_Merchant_Tweak).Barter()
;akSpeaker.ShowBarterMenu()

EndFunction
I commented the ShowBarterMenu() part out and let the script fragment point to the custom Barter() function in the quest script (GetOwingQuest() part)


The original quest script with some additional annotations:
 

Code: Select all

Scriptname SESM_Dremora_Merchant_Tweak extends Quest  

SESMvariablesStorageScript property vars auto  
ObjectReference Property MerchantChest auto
Actor Property Middleman Auto

; used properties from SESMvariablesStorageScript:
; GlobalVariable Property MerchantGold Auto
; MiscObject Property gold Auto
; GlobalVariable Property MerchantRestock Auto


Function Barter()
MerchantChest.removeitem(vars.gold, MerchantChest.getitemcount(vars.gold))
Middleman.removeitem(vars.gold, Middleman.getitemcount(vars.gold))

If (vars.MerchantRestock.GetValueInt() == 2)
MerchantChest.reset()
endif

Middleman.additem(vars.gold, vars.MerchantGold.getvalueint())

Middleman.showbartermenu() 
EndFunction
You can ignore most of the script as only the last line of the custom Barter() function and the second and third properties are important.

The shortened version of the quest script:
 

Code: Select all

Scriptname SESM_Dremora_Merchant_Tweak extends Quest  


ObjectReference Property MerchantChest auto ; the duplicated merchant chest in the remote cell
Actor Property Middleman Auto ; the duplicated NPC in the remote cell

Function Barter()
Middleman.showbartermenu()
EndFunction
I attached he quest script to the quest DLC2Init which contains the dialogue of the Dremora Merchant.


The middleman will never leave the cell with his merchant chest and so he will never loose the connection to the chest and the stock.

Tags:
User avatar
Avrie
Joined: Thu Nov 03, 2022 11:37 pm

Re: How to fix the vanishing merchant stock bug

Post by Avrie »

Interesting work around. I never noticed the bug, but I don't usually summon merchants. I do however use "Seluna and Sharleen Merchant Followers SE" one of the oldrim ports by ff7legend. So far I've never actually used them as followers. They hang in Whiterun and I just use them to empty my excess inventory. I wonder if they suffer from the same bug if I actually use them as followers?

https://www.nexusmods.com/skyrimspecial ... mods/45797 (Just a mod of convenience)
User avatar
Altbert
Moderator
Joined: Tue Nov 01, 2022 10:58 pm
Location: Netherlands
Contact:

Re: How to fix the vanishing merchant stock bug

Post by Altbert »

Never cared for followers, but long ago, at least a few years, I created a personal mod in which I could summon a merchant ghost with the appearance of Belethor, but it didn't feel right. The ghost always wandered off and I had to run after him.

Floating Island of Legends has a summonable Dwemer barrel (no, not BA's home), but it can only be used when near overencumbered (95% or more), based on current carrying capacity. Still have to add another condition: you can only summon the barrel when it's empty!

Since Floating Island is one of my largest mods since ever, I was struggling with compiling a loose file archive. Sure, I can create a BSA in the Creation Kit, but this may often include assets that are not really necessary (vanilla assets or assets from other masters). Also, when creating a BSA, the CK also skips assets I do want in my archive. So I took a new project on my hand in Visual Studio to use the <name>.achlist from the CK, which lists all the assets, and create a folder/file structure outside the Skyrim/Data folder, to use 7-Zip to create a loose file archive.

But I think I made the wrong choice! I use VB instead of C# to create the tools, because I thought it would be a bit more easy. Wrong choice! Working with VB was too long ago. Too late now as half of the tool has already been finished.
Bis vincit, qui se vincit in victoria - He conquers twice who conquers himself in victory (Publius Syrus)
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Skyrim - Mods and Modding”