Adding a chest to a merchant via script

Post » Thu Nov 21, 2013 5:51 am

I'm trying to add some items to another mod's merchant, without necessarily requiring the other mod to be installed. The NPC is already a functional general goods merchant, complete with services faction and container, I just need to add one more leveled item list to his stock that will respawn whenever he restocks.

So, I created a new chest in my own mod (in the WEMerchantChests cell, next to the road peddler chest) which contains only the leveled list I need to add. Then I created a new services faction (cloned from Belethor's) which points to my new chest reference.

Then at run-time, when the player enters the cell with the other mod's merchant, I use GetFormFromFile to retrieve the actor reference (can't do it sooner because he's not persistent, so it won't load until the player is in the cell), and then SetFactionRank to put him in my added services faction at rank 0. This happens before I open dialogue with him, and I checked in the log that the script has gotten valid pointers for both the actor and the faction.

But of course it doesn't work, or I wouldn't be here. Am I missing something obvious? Is there some other way to add to another mod's respawning merchant stock without having to actually override anything from that mod in my own .esp file?

User avatar
barbara belmonte
 
Posts: 3528
Joined: Fri Apr 06, 2007 6:12 pm

Post » Thu Nov 21, 2013 3:13 am

If this list adds things that are in the stock game, then just change the leveled list in your mod.

If this is to add an item that is unique to this other mod that is not installed, then no. Magic does not work in the real world. You would need the other mod installed or at least merged with the mod you are working on.

User avatar
Izzy Coleman
 
Posts: 3336
Joined: Tue Jun 20, 2006 3:34 am

Post » Thu Nov 21, 2013 2:43 pm

I don't understand how this applies. The leveled item list is added by my mod, the merchant is added by the other mod, and I want him to have my list in his merchant chest. But I don't want to override his chest in order to add it, because that makes the other mod required for mine to run. My mod should work on its own, it just add something extra to this other mod, if it's installed as well.

I am detecting the presence of the other mod via a script in my mod, and that part works just fine (it prints the Actor reference that it found for the other mod's merchant, and it has the correct name and form ID). The part that isn't working is getting this merchant to sell from an additional chest (added by me).

User avatar
Steven Hardman
 
Posts: 3323
Joined: Sun Jun 10, 2007 5:12 pm

Post » Thu Nov 21, 2013 12:17 pm

1- Check you are getting the correct reference by using http://www.creationkit.com/GetName_-_Form on the from you think belongs to the merchant.
2- Make sure your leveled list is working fine by testing it on vanilla merchants.
3- What function are you suing to add the leveled list?
User avatar
Russell Davies
 
Posts: 3429
Joined: Wed Nov 07, 2007 5:01 am

Post » Thu Nov 21, 2013 10:08 am

When I enter the cell with the actor, I fetch all the pointers and print them:

[11/20/2013 - 11:12:37AM] myobjref = [ObjectReference < (9001D821)>]  (my new container reference)[11/20/2013 - 11:12:37AM] myactorbase = [ActorBase < (0D01427A)>]  (the merchant's base actor form)[11/20/2013 - 11:12:37AM] myactor = [Actor < (0D0419AF)>]  (the merchant actor reference in the cell)[11/20/2013 - 11:12:37AM] myfaction = [Faction < (9001DD84)>]  (my new services faction)

With those pointers, I do:

myobjref.MoveTo(myactor, 0, 0, 256)myobjref.SetActorOwner(myactorbase)myobjref.SetFactionOwner(myfaction)myactor.AddToFaction(myfaction)myactor.SetFactionRank(myfaction, 0)

As I understand it only the last line should be necessary, but I've been adding things to try to get it working.

When I approach the merchant, I can see my new chest floating above his head, and I can peek inside and see the items I added to it via my leveled list (some gold ingots just for testing). But the merchant does not sell those items, even though he's been added to the new faction which points to the chest, and he's the owner of the chest, and the items have the right keywords (or rather don't have the wrong ones -- both his original services faction and my new one use VendorItemsMisc with "Not Sell/Buy" checked).
User avatar
Toby Green
 
Posts: 3365
Joined: Sun May 27, 2007 5:27 pm

Post » Thu Nov 21, 2013 1:40 am


I think the problem might be, that a merchant can't have two vendor chests. Don't quote me on this though cause I started modding Skyrim a week ago.
Try adding your leveled list to the merchant's current container and see what happens. AddItem or one of the AddForm should work.

Another possibility is that the merchant needs to reset it's containers. Wait 48 hours outside of the cell before talking to him again.
User avatar
Matt Fletcher
 
Posts: 3355
Joined: Mon Sep 24, 2007 3:48 am

Post » Thu Nov 21, 2013 1:26 am

The problem with adding the list to the original chest is that it will only be there once, and as soon as his stock resets, it'll be gone and I'd have to add it again. I could do that if there was a way to know when a merchant restocks, but I don't think there's anything like an "OnRespawn" event, so I'd risk accidentally adding the stuff more than once during the same respawn cycle.

Incidentally, I solve this problem for all other merchants in the game by adding to the VendorGold* leveled item lists using AddForm() as you suggest, and that works very well. The reason I'm doing this merchant chest business at all is that this one mod decided not to use any VendorGold* lists for their merchants, so I'm looking for a workaround.

I did also try waiting a few days for the restock cycle, but it didn't help.

User avatar
emma sweeney
 
Posts: 3396
Joined: Fri Sep 22, 2006 7:02 pm

Post » Thu Nov 21, 2013 9:26 am

Is the chest a form that is unique to the mod? I'm asking because there is at least one option that requires that you can get the ObjectReference of that specific chest at runtime.

User avatar
Kristina Campbell
 
Posts: 3512
Joined: Sun Oct 15, 2006 7:08 am


Return to V - Skyrim