• 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:
(Have not tested this yet - will attempt to do so when I get home tonight)
How about adding/changing things within the text files such as the locilization.txt?
I do not want to take anything away from this wonderful addition so first let me say thank you for putting the time and effort into making this happen.

That said I cant stress enough the importance of the Localization being something we have control over using xpath. Unfortunately I can not use xpath as I wished i could have due to this. So many of my mods include new items and blocks and require descriptions that by having to still do them by hand in the original file, as well as having to instruct people HOW to copy the Localization into their vanilla install negates the use of this for me and some others.

Also the issue will arise where someone like myself and others include vanilla Localizations in their modlets, and each will contain DIFFERENT entries that when the user copies into their files will overwrite the other. I know this may not seem like a priority but descriptions and conformity in naming conventions almost require we be able to include our own Localization in mods.

 
I dont know if I found a bug or not but I was messing around with combinations of modlets and Ravenhearst. It seems that if I add a block with a custom asset into the xml, and then add a modlet that also has a custom block it OVERWRITE the Ravenhearst one.

For example I have a drying rack in Ravenhearst. I added it to 17 using the old method. I then went to drop my farming modlet in that adds wheat. My drying racks disappeared and became a wheat plant.

Mentioning this because for mods like Walkers and Darkness Falls that have complete overhauls this could cause massive issues if players install modlets on top of it and it removes our items. Was this intentional?

If it is I think it should be explicitly stated that this is how it works otherwise somewhere along the line someone is going to install something from the Launcher and then try to add modlets and its going to wreck their games.

 
I dont know if I found a bug or not but I was messing around with combinations of modlets and Ravenhearst. It seems that if I add a block with a custom asset into the xml, and then add a modlet that also has a custom block it OVERWRITE the Ravenhearst one.
For example I have a drying rack in Ravenhearst. I added it to 17 using the old method. I then went to drop my farming modlet in that adds wheat. My drying racks disappeared and became a wheat plant.

Mentioning this because for mods like Walkers and Darkness Falls that have complete overhauls this could cause massive issues if players install modlets on top of it and it removes our items. Was this intentional?

If it is I think it should be explicitly stated that this is how it works otherwise somewhere along the line someone is going to install something from the Launcher and then try to add modlets and its going to wreck their games.
That isn't the expected results. Can you send me the files through discord, and I'll take a look? Are you using <append> or <insertBefore> and <insertAfter> ?

- - - Updated - - -

I do not want to take anything away from this wonderful addition so first let me say thank you for putting the time and effort into making this happen.
That said I cant stress enough the importance of the Localization being something we have control over using xpath. Unfortunately I can not use xpath as I wished i could have due to this. So many of my mods include new items and blocks and require descriptions that by having to still do them by hand in the original file, as well as having to instruct people HOW to copy the Localization into their vanilla install negates the use of this for me and some others.

Also the issue will arise where someone like myself and others include vanilla Localizations in their modlets, and each will contain DIFFERENT entries that when the user copies into their files will overwrite the other. I know this may not seem like a priority but descriptions and conformity in naming conventions almost require we be able to include our own Localization in mods.
The testing version of SDX has removed the ability to merge the xpath, but it kept the ability to apply localization.

If your SDX mod folder is like this:

Code:
JaxTeller718/Config/
JaxTeller718/Scripts/
JaxTeller718/Text/
JaxTeller718/Resources/
It will copy the Config and Resource scripts over into the Game's Mods/JaxTeller718/ as-is, build and apply the scripts, and do the localization merge.

It's definitely not ideal, and I believe there's plans to include native support for localization, but we just aren't there yet.

 
Hi!
Can you send me an example of ModInfo.xml file please ?
Sure

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xml>
<ModInfo>
	<Name value="SphereII_PG13" />
	<Description value="This modlet tries to make the game a bit more PG, by switching out the stripper model with a nurse." />
	<Author value="sphereii" />
	<Version value="1.0.0" />
</ModInfo>
</xml>
 
That said I cant stress enough the importance of the Localization being something we have control over using xpath. Unfortunately I can not use xpath as I wished i could have due to this. So many of my mods include new items and blocks and require descriptions that by having to still do them by hand in the original file, as well as having to instruct people HOW to copy the Localization into their vanilla install negates the use of this for me and some others.

While you may not be able to modify the locilization file. I have had decent success in modifying a description directly and bypassing the localization file (if it cant fidn it in the locilization fiel it prints it as is ingame)

It may not be perfect for all cases, but my limited use of it works well enough until propr localization modding is implemented.

 
I try to build my first mod on A17.

But can i add a picture on toolbelt for change the Xui with xpath ?

 
Last edited by a moderator:
This is AWESOME! Will make the adding of tweaks and personal changes so much easier!

now to learn it haha

Ok how do i add in new Item? I want to create the herbal bandage. Using Chrysanthemum and goldenrod, and NitratePowder. I want to make a first aid bandage that works like vanilla, but half strength.

 
Playing around with it a bit, really like it.

I hope we get more functions, like 'mult', 'add', 'sub'.

For now I will use stacksize selectors:

Code:
<configs>

 <set xpath="/items/item[contains(@name,'resource')]/property[
               @name='Stacknumber'
               and @value > 900
             ]/@value">20000</set>

 <set xpath="/items/item[contains(@name,'resource')]/property[
               @name='Stacknumber'
               and @value <= 900
               and @value > 400
             ]/@value">2000</set>

 <set xpath="/items/item[contains(@name,'resource')]/property[
               @name='Stacknumber'
               and @value <= 400
               and @value > 100
             ]/@value">1000</set>

 <set xpath="/items/item[contains(@name,'resource')]/property[
               @name='Stacknumber'
               and @value < 100
             ]/@value">250</set>

</configs>
 
For your generic XML issues I recommend using e.g. Notepad++ with the XML plugin. It will tell you when the general XML structure is borked (like if you forget to close an XML element, mismatching open and close names etc).
Can you link to the plugin?

 
Can you link to the plugin?
If you use the 32-bit version of NotePad++, go to Plugins -> Plugin Manager. Do any update it asks for. Then search in the available list for XML Tools.

I'm not sure if the 64-bit version of Notepad++ has the Plugin Manager working yet; it may need manual downloads and file placements.

 
Attempting to Add in Valmars Fuel log, requires adding in a new recipe and Item. Heres what i did....

2 files in config folder

recipes has

Code:
<configs>
    <append xpath="/recipes">

               <recipe name="fuelLog" count="1">
                  <ingredient name="resourceWood" count="20"/>
                  <ingredient name="resourceTallow" count="1" />
               </recipe>

	</append>
</configs>
And Items has

Code:
<configs>
    <append xpath="/items">

           	<item name="fuelLog">

                   <property name="Meshfile" value="Items/Misc/sackPrefab"/>
                   <property name="DropMeshfile" value="Items/Misc/sack_droppedPrefab"/>
   	               <property name="Material" value="Mwood"/>
                   <property name="HoldType" value="45"/>
				   <property name="DescriptionKey" value="fuelLogDesc"/>
	               <property name="Stacknumber" value="50" />
				   	<property name="Weight" value="5"/>
   	               <property name="SellableToTrader" value="true"/>
	               <property name="EconomicValue" value="34"/>
	               <property name="FuelValue" value="580" />
                   <property name="Group" value="Resources,Basics"/>
                   <property name="CraftingSkillGroup" value="craftSkillScience"/>
				   <property name="CraftingIngredientTime" value="0.25"/>


             </item>

	</append>
</configs>
Hows it look?

Holy crap it worked lol I had to edit the main localization file right? no way yet to use xpath to edit those yet?

 
Last edited by a moderator:
Running into a slight headache. Anyone know WHY im getting that extra </item> tag at the end of this code?

Code:
<lootcontainer id="36" count="0,2" size="4,3" sound_open="UseActions/open_suitcase" sound_close="UseActions/close_suitcase" loot_quality_template="baseTemplate">
   <item name="drinkJarBoiledWater" count="1" prob="0.15"><!--Attribute "count" replaced by: "JaxTeller718_LessWaterInLoot"--></item>
   <item group="cannedfood" prob="0.5" />
   <item group="junk" />
   <item name="meleeToolFlashlight02" prob="0.1" />
   <item group="medicine" prob="0.1" />
   <item group="weaponsBasicGuns+ammo" prob="0.03" />
   <item group="weaponsMelee" prob="0.03" />
   <item group="ammo" />
</lootcontainer>
here is the xpath im using for that

Code:
<set xpath="/lootcontainers/lootcontainer[@id='36']/item[@name='drinkJarBoiledWater']/@count">1</set>
 
How do i add an item to a lootgroup?

I want to add the fuellog to loot group Tools, i came up with this

Code:
<config>

<set xpath="/lootgroups/lootgroup[@name='tools']/item[@name='fuellog']/@count">1</set>

</config>
 
Last edited by a moderator:
Running into a slight headache. Anyone know WHY im getting that extra </item> tag at the end of this code?

Code:
<lootcontainer id="36" count="0,2" size="4,3" sound_open="UseActions/open_suitcase" sound_close="UseActions/close_suitcase" loot_quality_template="baseTemplate">
   <item name="drinkJarBoiledWater" count="1" prob="0.15"><!--Attribute "count" replaced by: "JaxTeller718_LessWaterInLoot"--></item>
   <item group="cannedfood" prob="0.5" />
   <item group="junk" />
   <item name="meleeToolFlashlight02" prob="0.1" />
   <item group="medicine" prob="0.1" />
   <item group="weaponsBasicGuns+ammo" prob="0.03" />
   <item group="weaponsMelee" prob="0.03" />
   <item group="ammo" />
</lootcontainer>
here is the xpath im using for that

Code:
<set xpath="/lootcontainers/lootcontainer[@id='36']/item[@name='drinkJarBoiledWater']/@count">1</set>
Compare it to these two examples:

Code:
<set xpath="/lootcontainers/lootcontainer[@id='62']/@size">7,6</set>

<set xpath="/items/item/property[@class='Action0']/property[@name='Magazine_items'][@value='9mmBullet']/@value">9mmBullet,NoAmmo</set>
I'm guessing the /item, either needs to be removed or named @item, but I don't really know this stuff yet.

 
Last edited by a moderator:
Back
Top