• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

XPath Modding Explanation Thread

This is a large amount of information in these posts. I'll be working on a full, properly formed tutorial as we get access to A17 and we can really make the xpath system shine. I've listed some examples here, and we'll be posting a ton more xpath samples over the coming weeks, as we port the SDX modlets over to use the native hooks.

By all means, begin posting your comments, questions, or requests for clarity.

Since we now know that xpath support will be built-into the vanilla base game, and discussions earlier were getting a bit confusing, I've decided to make a new thread to try to demystify xpath and what it'll mean for mods and modders going forward in A17. The information in this thread has been pieced together from forum and discord discussions. They may not be 100% accurate, but I will update this thread when we know the full implementation.

XPath is a way of adding, changing, or removing XML lines and nodes, without directly editing the XML files. It allows you to apply patches to the XML files without manually editing the vanilla XML files.

SDX has had partial support for this since its initial release, and a lot of the SDX Modlets are already written this way. We will be using some of the SDX's xpath as examples in this thread, but SDX is not required to do this in A17 and onwards.

I believe in using examples to explain concept, so in the next few posts, you'll see a mixture of explanation, along with sample xpath code.

The following Mod structure is expected for A17 and beyond:

Code:
Mods/
   <ModName>/
       Config/
       UIAtlases/ItemIconAtlas/
       ModInfo.xml

   <ModName2>/
       Config/
       ModInfo.xml
You will be able to have multiple mods loaded, and loading will occur as long as the ModInfo.xml exists. This is unchanged from what we've been doing doing with other alphas, with the exception of the Config folder.

This Config folder will support loading XML files, written using xpath, in the following folder structure:

Code:
Config/entityclasses.xml
Config/gamestages.xml
Config/items.xml
The files in the Config folder will not be a full copy of the vanilla file with your changes. Rather, it'll contain the changes you want done to the vanilla files. The files under the Config must match the vanilla file name. You cannot create an entityclasses2.xml file, and expect it to work. Any changes in the entityclasses.xml will have to be done in the same file. However, each mod can have its own entityclasses.xml.

During the game's initialization, it will perform the xpath merge in-memory only; no files will be actually be modified. This would allow us to remove mods we no longer want, without re-validating against steam, or previous copies of the xml. That's a big one. No more half merging of a mod, and not having it work, then trying to pull it back out.

What this means for us is that we'll be able to make a variety of smaller mods, which I've been calling modlets, which can add, remove and change smaller pieces of the game. They can be used together, or they could be added to an overhaul mod, in order to style your game play easier.

These modlets would also exists outside of the Data/Config folder, so if you have made direct XML changes in your Alpha 17.1 Data/Config files, and Steam updated the game to 17.2, you would have lost your changes, or would have to re-merge them in. We've all been there before. But if they existed as modlets, under the Mods folder, they would be safe. And as long as your xpath is still valid to the new XML, it should load up with no additional work on your part.

If we could use xyth's JunkItems modlet, which adds random, scrappable junk items to loot containers, and add them to Valmod Overhaul. Likewise, if Valmod Overhaul did not have the No Ammo modlet (which gives you the ability to unload a gun and get its bullets back without disassembling it), you could drop the NoAmmo modlet into your Mods folder. Headshots only? Want to increase stack sizes? Same deal.

With a properly constructed modlet, we'll be able to piece together new play styles for people to enjoy and share. A modder working on a large overhaul won't have to duplicate work. If they wanted to include the No Ammo mod, they wouldn't have to code it themselves, letting them focus on the bits that make their mod really unique.

Let's get started on your journey...

 
Last edited by a moderator:
This will do the same thing. I am not sure which is the best or if it just don't matter as long as it gets the job done. :)

Code:
<set xpath="/blocks/block[@name='terrDesertGround']/drop[@event='Harvest'][@name='resourceCrushedSand']/@count">20</set>
 
I made a mod to cook canned food to remove the food poisoning risk and give you basic hot food. Worked great until I made them learnable. I want them to unlock at the first level. I found the code I need to work with but I can't figure out how to add my foods to it.

I think this where I need to do it:

<perk name="perkMasterChef" parent="skillCraftsmanship" name_key="perkMasterChefName" desc_key="perkMasterChefDesc" icon="ui_game_symbol_spatula">


<level_requirements level="1"><requirement name="ProgressionLevel" progression_name="attIntellect" operation="GTE" value="1" desc_key="reqIntellectLevel01"/></level_requirements>



<level_requirements level="2"><requirement name="ProgressionLevel" progression_name="attIntellect" operation="GTE" value="3" desc_key="reqIntellectLevel03"/></level_requirements>



<level_requirements level="3"><requirement name="ProgressionLevel" progression_name="attIntellect" operation="GTE" value="5" desc_key="reqIntellectLevel05"/></level_requirements>



<level_requirements level="4"><requirement name="ProgressionLevel" progression_name="attIntellect" operation="GTE" value="7" desc_key="reqIntellectLevel07"/></level_requirements>



<level_requirements level="5"><requirement name="ProgressionLevel" progression_name="attIntellect" operation="GTE" value="10" desc_key="reqIntellectLevel10"/></level_requirements>


 


<effect_group>



<passive_effect name="RecipeTagUnlocked" operation="base_set" level="1,5" value="1" tags="foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea"/>


<passive_effect name="RecipeTagUnlocked" operation="base_set" level="2,5" value="1" tags="foodSteakAndPotato,foodBlueberryPie,foodMeatStew,foodVegetableStew"/>



<passive_effect name="RecipeTagUnlocked" operation="base_set" level="3,5" value="1" tags="foodShamChowder,foodHoboStew,foodFishTacos"/>



<passive_effect name="RecipeTagUnlocked" operation="base_set" level="4,5" value="1" tags="drinkYuccaJuiceSmoothie,foodChiliDog"/>



<passive_effect name="RecipeTagUnlocked" operation="base_set" level="5,5" value="1" tags="drinkJarGrandpasMoonshine,drinkJarGrandpasAwesomeSauce,drinkJarGrandpasLearningElixir"/>



<effect_description level="1" desc_key="perkMasterChefRank1Desc"/>



<effect_description level="2" desc_key="perkMasterChefRank2Desc"/>



<effect_description level="3" desc_key="perkMasterChefRank3Desc"/>



<effect_description level="4" desc_key="perkMasterChefRank4Desc"/>



<effect_description level="5" desc_key="perkMasterChefRank5Desc"/>



</effect_group>



</perk>


Can you help me with this?

I also want to up the chance of food poisoning on the canned food. This is what I came up with, but it doesn't work. It still shows Food Poisoning at 5%.

<FoodPoisoningMod>


<setattribute xpath="/items/item[@name =foodCanBeef]/property[@name=FoodPoisoningRisk]" name="display_value">.25</setattribute>



</FoodPoisoningMod>


Thank you for your time. :smile-new:

 
Last edited by a moderator:
I am sure there are easier ways to do this but this way worked for me. NOTE: I only added "foodCanBeef", to add more be sure to add a comma between names.

Code:
<progression>
   <set xpath="/progression/perks/perk[@name='perkMasterChef']/effect_group/passive_effect[@tags='foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea']/@tags">foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea,foodCanBeef</set>
</progression>
Check the video tutorial for maybe some help on the second part of your question

 
I am sure there are easier ways to do this but this way worked for me. NOTE: I only added "foodCanBeef", to add more be sure to add a comma between names.

Code:
<progression>
   <set xpath="/progression/perks/perk[@name='perkMasterChef']/effect_group/passive_effect[@tags='foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea']/@tags">foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea,foodCanBeef</set>
</progression>
Check the video tutorial for maybe some help on the second part of your question
Thank you so much for your reply. I copied it exactly as you have it. It failed to load, the message says there was no xpath attribute. I don't get it. I see one there lol.

 
To make sure we are on the same page. You made a "Mods" folder with a ModInfo.xml in it then in the "Config" folder you have a progression.xml with the above in the progression.xml

On the other part if your question the other page is wrong, I got this to load with errors but it does seem to load and it does display a 25% chance,

This needs to be in items.xml

Code:
<configs>
<set xpath="/items/item[@name='foodCanBeef']/effect_group[@tiered='false']/triggered_effect[@trigger='onSelfPrimaryActionEnd'][@buff='buffIllFoodPoisoning0']/requirement[@name='RandomRoll']/@value">25</set>


<set xpath="/items/item[@name='foodCanBeef']/effect_group/display_value[@name='FoodPoisoningRisk']/@value">0.25</set>
</configs>
 
To make sure we are on the same page. You made a "Mods" folder with a ModInfo.xml in it then in the "Config" folder you have a progression.xml with the above in the progression.xml
On the other part if your question the other page is wrong, I got this to load with errors but it does seem to load and it does display a 25% chance,

This needs to be in items.xml

Code:
<configs>
<set xpath="/items/item[@name='foodCanBeef']/effect_group[@tiered='false']/triggered_effect[@trigger='onSelfPrimaryActionEnd'][@buff='buffIllFoodPoisoning0']/requirement[@name='RandomRoll']/@value">25</set>


<set xpath="/items/item[@name='foodCanBeef']/effect_group/display_value[@name='FoodPoisoningRisk']/@value">0.25</set>
</configs>
I copied and pasted your code for progression into my progression.xml which is in my Config folder which is in my mod folder that has a ModInfo.xml. Failed to load due to no xpath element.

Here is the exact code in that xml

<CanFoodLearnable>


<progression>



<set xpath="/progression/perks/perk[@name=perkMasterChef]/effect_group/passive_effect[@tags=foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea]/@tags">foodBaconAndEggs,foodBoiledMeat,foodGrilledMeat,foodBakedPotato,foodCornBread,foodCornOnTheCob,drinkJarRedTea,drinkJarCoffee,drinkJarGoldenRodTea,foodCanBeef</set>



</progression>



</CanFoodLearnable>


I also copied pasted your code for the food poisoning into my items.xml

It has the same problem no xpath element.

I tested them separately so I know I'm not getting them mixed up.

I went back and took screenshots of the error messages.

https://www.mediafire.com/view/we8a23kgyw389bt/FoodPosioning_Error.png/file

https://www.mediafire.com/view/akdjhdy2crawaqn/CanFoodLearnable_error.png/file

 
Last edited by a moderator:
I see lots of spaces where there should not be, that could be because of lack of code tags.

Still trying to learn xpath myself, it could be the modinfo.xml that is giving you problems.

Copy of the modinfo I used to test

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xml>
   <ModInfo>
       <Name value="Food Posioning" />
       <Description value="Add more posioning" />
       <Author value="Duke" />
       <Version value="A17.2b20" />
       <Website value="https://7daystodie.com/forums/forumdisplay.php?61-Game-Mods" />
   </ModInfo>
</xml>
You might try to hit F1 for the console and enter "exportcurrentconfigs" without the quotes, the console will tell you where the complete configs are placed so you can see just what is being loaded.

An example of where you should find the exported cofigs

C:\Users\Duke\AppData\Roaming\7DaysToDie\Saves\Hezubu Mountains\Perfect World2\Configs

Here is a start to what you want I think.

DOWNLOAD

 
Last edited by a moderator:
I see lots of spaces where there should not be, that could be because of lack of code tags.
Still trying to learn xpath myself, it could be the modinfo.xml that is giving you problems.

Copy of the modinfo I used to test

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xml>
   <ModInfo>
       <Name value="Food Posioning" />
       <Description value="Add more posioning" />
       <Author value="Duke" />
       <Version value="A17.2b20" />
       <Website value="https://7daystodie.com/forums/forumdisplay.php?61-Game-Mods" />
   </ModInfo>
</xml>
You might try to hit F1 for the console and enter "exportcurrentconfigs" without the quotes, the console will tell you where the complete configs are placed so you can see just what is being loaded.

An example of where you should find the exported cofigs

C:\Users\Duke\AppData\Roaming\7DaysToDie\Saves\Hezubu Mountains\Perfect World2\Configs

Here is a start to what you want I think.

DOWNLOAD
I don't know what the issue is. I unzipped that file and put it in the game the same place as I put my mods. The launcher doesn't even recognize it as a modlet. It recognizes all of mine just fine.

 
Do you already have a "Food Posioning" named file in any modinfo? The game will only read one, try renaming it.
It was the only mod in there. I tried putting a modinfo.xml from one of my mods that I know works in place of yours and it still didn't work. Again in was the only mod in the mods folder.

 
I just noticed there's no description of modinfo.xml. Since the first message goes to the trouble of describing the path (not xpath) structure, perhaps it should also mention what goes there.

 
I am trying to add a large denomination casino token to store large piles of tokens.

It adds the new token and associated recipes to stack and unstack your tokens.

I can get the new item to add correctly to items.xml, but I cannot figure out how to make it add a name and description in the Localization.txt.

(edit: I know can do it manually, but I am trying to get it all self contained.)

Is that even possible with an xpath modlet?

 
Last edited by a moderator:
Question, there are two recipes for gas but I only want to change one of them, so that the oilBarrel recipe makes 1200 gas instead of 600. How do I target the correct one to make my alterations?

Vanilla code:

Code:
<recipe name="ammoGasCan" count="100" craft_area="chemistryStation" tags="learnable">
<ingredient name="resourceOilShale" count="12"/>
</recipe>

<recipe name="ammoGasCan" count="600" craft_exp_gain="0" craft_time="5" always_unlocked="true">
<ingredient name="oilBarrel" count="1"/>
</recipe>
 
Last edited by a moderator:
A17.2 Vanilla gas is 600 not 1000 so depending on which version and what changes have been made one of these should work.

Code:
<set xpath="/recipes/recipe[@name='ammoGasCan'][@count='600']/@count">1200</set>
Code:
<set xpath="/recipes/recipe[@name='ammoGasCan'][@count='1000']/@count">1200</set>
 
A17.2 Vanilla gas is 600 not 1000 so depending on which version and what changes have been made one of these should work.
Yes thank you, but accidentally typed in the wrong amount.

Am I correct that this pair or recipes would do and undo correctly?

Code:
<set xpath="/recipes/recipe[@name='ammoGasCan'][@count='600']/@count">1200</set>
Code:
<set xpath="/recipes/recipe[@name='oilBarrel']/ingredient[@name='ammoGasCan']/@count">1200</set>
I might have done something wrong, It still seems to be using 600 units of gas both ways in the recipe.

 
Last edited by a moderator:
Those should work with no problem. F1 for the console and type in "exportcurrentconfigs" without the quotes the check and see just what its loading or not loading.

assuming a default install here is the path the exported configs will be.

your map name\your world gen name

C:\Users\YOURNAME\AppData\Roaming\7DaysToDie\Saves\Hezubu Mountains\PerfectWorld\Configs

 
Those should work with no problem. F1 for the console and type in "exportcurrentconfigs" without the quotes the check and see just what its loading or not loading.
assuming a default install here is the path the exported configs will be.

your map name\your world gen name

C:\Users\YOURNAME\AppData\Roaming\7DaysToDie\Saves\Hezubu Mountains\PerfectWorld\Configs
The recipes were unchanged in the exported configs.

Edit: Found the problem-- I left the "s" off the end of recipes in the mod xml

 
Last edited by a moderator:
I am having an issue with xpath and Blocks is there a way to add in a property to an existing block or do i need to remove the block some how and append in a replacement one with the changes?

is this used to remove the block, if so could someone explain how.

<remove xpath="">
i Thank you for any help you may provide.

 
Back
Top