Jump to content

Adding new category to Traders - possible?


Camiracundus

Recommended Posts

Hi everyone. I was wondering if anyone knows if it's possible/how to add new categories to the traders? 
I work on a mod that has a ton of fruits, vegetables, resources etc, that I'd like to make buyable from the Traders; and while I could easily add them into the existing categories (which I have done with seeds), I'd prefer to make an all-new category so I don't end up making it nearly impossible to find the existing crop items (potatoes, pumpkins, blueberries etc) because there's a much higher likelihood of some of mine showing up instead (10:1 ratio, likely).

 

I imagine it would need to be done through the traders.xml and the windows + uidisplay xmls, but I'm not sure on much more than that.    

Link to comment
Share on other sites

The bulk of the code is within traders.xml, with a small edit to ui_display.xml and a quick check through items.xml

First of all you'll need to create a new item group for your new resources in traders.xml

 

For example

	<insertAfter xpath="/traders/trader_item_groups/trader_item_group[@name='foodSupplies']">
		<trader_item_group name="new_group">
			<item name="your_resource"/>
		</trader_item_group>
	</insertAfter>


Then you will have to add this new group to specific traders, starting at line 1269 in traders.xml

	<insertBefore xpath="/traders/trader_info[@id='1']/trader_items/item[@group='modAllT1SecretStash']">
		<item group="new_group" count="4,8"/>
	</insertBefore>


This will place your new category one place before the secret stash at trader with id 1 (Joel).

Next, in ui_display.xml

	<insertAfter xpath="/ui_display_info/trader_category_display/trader_category[@name='TCArmor']">
		<trader_category name="new_group" icon="ui_game_symbol_chemistry" display_name="new group" />
	</insertAfter>


This adds your new group to traders so that an icon and category is displayed.
Without this, your items will still appear in the trader, but won't have their own category.

The last thing you need to do is go through items.xml and make sure the group for the specific items matches your group name, ie "new_group" in the above example.

<property name="Group" value="new_group"/>

I'm not sure that this is entirely necessary but I like to keep things grouped

Not tested but should work.

The only thing that may throw out errors is the same name somewhere else in your code

 

Forgot to mention, you will need to add a new line of code for each trader, trader ID's are 6 (Bob), 2 (Jen), 7 (Hugh) and 8 (Rekt). Otherwise the above code will only show in trader 1 (Joel).

Edited by poly (see edit history)
Link to comment
Share on other sites

18 hours ago, poly said:

The bulk of the code is within traders.xml, with a small edit to ui_display.xml and a quick check through items.xml

First of all you'll need to create a new item group for your new resources in traders.xml

 

For example

	<insertAfter xpath="/traders/trader_item_groups/trader_item_group[@name='foodSupplies']">
		<trader_item_group name="new_group">
			<item name="your_resource"/>
		</trader_item_group>
	</insertAfter>


Then you will have to add this new group to specific traders, starting at line 1269 in traders.xml

	<insertBefore xpath="/traders/trader_info[@id='1']/trader_items/item[@group='modAllT1SecretStash']">
		<item group="new_group" count="4,8"/>
	</insertBefore>


This will place your new category one place before the secret stash at trader with id 1 (Joel).

Next, in ui_display.xml

	<insertAfter xpath="/ui_display_info/trader_category_display/trader_category[@name='TCArmor']">
		<trader_category name="new_group" icon="ui_game_symbol_chemistry" display_name="new group" />
	</insertAfter>


This adds your new group to traders so that an icon and category is displayed.
Without this, your items will still appear in the trader, but won't have their own category.

The last thing you need to do is go through items.xml and make sure the group for the specific items matches your group name, ie "new_group" in the above example.

<property name="Group" value="new_group"/>

I'm not sure that this is entirely necessary but I like to keep things grouped

Not tested but should work.

The only thing that may throw out errors is the same name somewhere else in your code

 

Forgot to mention, you will need to add a new line of code for each trader, trader ID's are 6 (Bob), 2 (Jen), 7 (Hugh) and 8 (Rekt). Otherwise the above code will only show in trader 1 (Joel).


Hey! Thanks for your input; it doesn't work, though :( There's no errors or warnings loading in, but there's still no new category at the traders 😕 Do you have any other suggestions?

Link to comment
Share on other sites

5 hours ago, Camiracundus said:


Hey! Thanks for your input; it doesn't work, though :( There's no errors or warnings loading in, but there's still no new category at the traders 😕 Do you have any other suggestions?


The category will only appear if the trader has the stock - for the above example, go to trader Joel, as the trader with id 1 is trader Joel

Then in DM restock inventory until it appears

Link to comment
Share on other sites

Hi again,

I went into devmode and refreshed his inventory, and the items showed up - but under the Food/Cooking category instead of their own category (which didn't show up, either). So something somewhere is not quite right; I've posted the coding below so you can look over it. 

 

traders.xml

<insertAfter xpath="/traders/trader_item_groups/trader_item_group[@name='foodSupplies']">
        <trader_item_group name="ZTTest">
            <item name="Apple" count="1,10"/>
        </trader_item_group>    
    </insertAfter>
    
    <insertBefore xpath="/traders/trader_info[@id='1']/trader_items/item[@group='modAllT1SecretStash']">
        <item group="ZTTest" count="4,8"/>
    </insertBefore>

 

Ui_display

<insertAfter xpath="/ui_display_info/trader_category_display/trader_category[@name='TCArmor']">
        <trader_category name="ZTTest" icon="ui_game_symbol_spatula" display_name="ZTTest" />
    </insertAfter>

 

items.xml

    <append xpath="/items">
     <property name="Group" value="ZTTest"/> 
    </append>    

 

So the Apple does show up in-game but not in its own category, which is preferable; if I add all of the crops into the normal food/cooking category, there's a pretty big chance they'll drown out the vanilla games items in there.. unless there's a better quick fix of simply increasing the number of items in the Food/Cooking category that the traders can display? That's also an option, but a new category would be best, to help users distinguish what's from the mod and what's not.

Link to comment
Share on other sites

The only thing I can see from your code which might be causing the category issue is the items.xml part..

Make sure the append is to the specific item block.

 

For example
 

<append xpath="/items">
	<item name="Apple">
    	<property name="Group" value="ZTTest"/> 
	</item>
</append>


And not:
 

  <append xpath="/items">
     <property name="Group" value="ZTTest"/> 
    </append>   


The above will place a random property outside of an item block

Link to comment
Share on other sites

16 minutes ago, poly said:

The only thing I can see from your code which might be causing the category issue is the items.xml part..

Make sure the append is to the specific item block.

 

For example
 

<append xpath="/items">
	<item name="Apple">
    	<property name="Group" value="ZTTest"/> 
	</item>
</append>


And not:
 

  <append xpath="/items">
     <property name="Group" value="ZTTest"/> 
    </append>   


The above will place a random property outside of an item block


I see what you mean. Now my concern is, that most of the these food items already have the 

 

<property name="Group" value="Food/Cooking"/>

 

Can I add the ZTTest group to that as well, or do I need to remove it? And if I need to remove it, my worry is that it'll prevent the items from showing up properly elsewhere. Do you have any insight on this?

I appreciate your help!

Link to comment
Share on other sites

4 minutes ago, poly said:

Just change it to:
 

<property name="Group" value="Food/Cooking,ZTTest"/>


It should appear in both group (when in stock)

The problem would then be that the items show up under both the Food/Cooking and ZTTest  categories at the trader when they're only supposed to show up in one; can I remove the Food/Cooking tag from them without them also dissapearing from cooking (campfire)?

Link to comment
Share on other sites

22 minutes ago, Camiracundus said:

The problem would then be that the items show up under both the Food/Cooking and ZTTest  categories at the trader when they're only supposed to show up in one; can I remove the Food/Cooking tag from them without them also dissapearing from cooking (campfire)?


What appears in the campfire is decided in recipes.xml

You can add the following value to Group:

 

<property name="Group" value="Food/Cooking,CFFood/Cooking"/>


CFFood/Cooking = Campfire display

In ui_display you can find this parameter:

 

		<crafting_category_list display_type="campfire">
			<!-- <crafting_category name="" icon="ui_game_symbol_campfire" display_name="lblAll" />
			<crafting_category name="Drink/Cooking" icon="ui_game_symbol_water" display_name="lblCategoryChemicals" /> -->
			<crafting_category name="CFFood/Cooking" icon="ui_game_symbol_fork" display_name="lblCategoryFood" />
			<crafting_category name="CFDrink/Cooking" icon="ui_game_symbol_thirst" display_name="lblCategoryDrink" />
			<crafting_category name="CFChemicals" icon="ui_game_symbol_chemistry" display_name="lblCategoryChemicals" />
		</crafting_category_list>

 

Link to comment
Share on other sites

Still no luck; the Apple no longer shows up under the Food/Cooking Trader category, but the new ZTTest category is always missing. I've thought about what the reason could be, and can't think of one; the syntax/coding is correct as it's not throwing out any errors, but it just won't implement it properly.

I may need to simple add it all into the Food/Cooking category and then increase the min/max stock count and refresh count instead; that, I can do. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...