How do I Add a new item to Merchant Inventory for sale?

Discuss modding questions and implementation details.
Post Reply
Asesino
Posts: 66
Joined: Fri Aug 16, 2019 3:14 am

How do I Add a new item to Merchant Inventory for sale?

Post by Asesino »

Hi all,
I created a mod that adds a telescope to your inventory. The telescope works fine; if I press "USE" in inventory, i can zoom in and out on the HUD after I close my inventory.

I would like to place this item in a shop owner's inventory for sale; but i can't figure out where i intercept the store shelf items list. Any help would be greatly appreciated.

On a side note, it would be more user friendly if I can automatically close inventory when i select use on the telescope; if you know a simple way to close down the window, that would be wonderful :)

Thanks all
A

User avatar
Doctor3d
Posts: 12
Joined: Tue Nov 19, 2019 1:51 am

Re: How do I Add a new item to Merchant Inventory for sale?

Post by Doctor3d »

I was kinda wondering this too. I was looking into adding new items to the loot tables (Not replace) and it doesn't seem like there's an easy method to add entirely new things. It doesn't appear like there's any code currently there to add new items. And, it looks like it would be a helluva lotta work to even do it.

From what I can tell, if you tried to do something like re-build the data table at launch by combining whatever new item lists you had from say an XML and let it import and rebuild the table on startup - the id's from the classic would be different and it wouldn't work.

That's kind of a bummer - I wanted to add a lot of money sinks into the game to buy and new loot items inspired by later ES games - like legendary weapons, silverware, relics, possibly furniture you could decorate with, etc

Asesino
Posts: 66
Joined: Fri Aug 16, 2019 3:14 am

Re: How do I Add a new item to Merchant Inventory for sale?

Post by Asesino »

hi all,
I was able to figure out a way to place the telescope onto the alchemist shop Shelves, but I do not know if it is the right way to do it.
What I did was create a CheckAlchemist method and used it to subscribe to OnTransitionInterior.
The code for CheckAlchemist checks that I am first in an Alchemist shop, and then looks for any Gameobjects that contain DaggerfallLoot Script. For each of those objects, I check that the container type is ShopShelves. If so, I add a new Component Script.
This is the source:

Code: Select all

        public void CheckAlchemist(EventArgs e)
        {
            if (GameManager.Instance.PlayerEnterExit.IsPlayerInsideOpenShop && GameManager.Instance.PlayerEnterExit.BuildingType == DaggerfallConnect.DFLocation.BuildingTypes.Alchemist)
            {
                DaggerfallLoot[] gos = FindObjectsOfType<DaggerfallLoot>() as DaggerfallLoot[];

                foreach (DaggerfallLoot gObj in gos)
                {
                         if (gObj.ContainerType == LootContainerTypes.ShopShelves)
                            gObj.gameObject.AddComponent<AddTelescope>();
                }
            }
        }
In the AddTelescope Script, I subscribe to OnWindowChange. In the method, I ensure that the topWindow is TradeWindow; if so, I check that the telescope is not already added, otherwise, I add it and update the window.

Here is the code for that part.

Code: Select all

        private void Start()
        {
            daggerfallLoot = this.GetComponent<DaggerfallLoot>();
            DaggerfallUI.UIManager.OnWindowChange += AddStock;
        }

 
        private void AddStock(object sender, EventArgs e)
        {
            var manager = (UserInterfaceManager)sender;
            var topWindow = manager.TopWindow;
            if (topWindow.ToString().Contains("Trade"))
            {
                if (!daggerfallLoot.Items.Contains(telescope))
                {
                    telescope = new Telescope(CreateItem())
                    {
                        currentCondition = 100,
                        maxCondition = 100
                    };
                    daggerfallLoot.Items.AddItem(telescope, ItemCollection.AddPosition.Front);
                    topWindow.Update();
                }
            }
        }
It all seems to be working. The parts that I don't currently like are the findObjectsOfType since that is a costly call, eventhough I am only calling it on start. The other thing I don't currently like is that I am checking the trade window's name to ensure it contains the word Trade. If anyone uses UIWindowFactory and changes the name to something else, it will break.

Is there a way to check the window against its UIWindowType enum? That way, I know that I have the tradewindow regardless of its actual name.

Any feedback would be greatly appreciated.
thanks all,
a

Post Reply