• 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:
It was to an actual Block :)
Do you have the full error?

- - - Updated - - -

id=numbers or not in use anymore, or are they?
cant see them anywhere

if yes, where do i find the ids?

if no, the id is now the item/block name?
Loot containers, as far as I know, still use hard coded numbers, rather than names. Hopefully that'll see a similar update as the blocks.xml and items.xml in the future. You would have to manually look through the loot.xml to find a 'free' sequential number.

- - - Updated - - -

Edit: I just checked the game code and saw that "AnimatotSet" functions don't accept CVars. :upset:
Hi

I am trying to pass an Int variable to the AnimationController but for some reason I get an error.

If I do:

Code:
   <triggered_effect trigger="onSelfPrimaryActionStart" action="ModifyCVar" target="self" cvar="TestCVar" operation="set" value="1"/>
   <triggered_effect trigger="onSelfPrimaryActionStart" action="AnimatorSetInt" target="self" property="TempProp" value="@TestCVar"/>
I get:

Code:
ERR XML loader: Loading and parsing 'items.xml' failed
FormatException: Input string was not in the correct format.
and if I do:

Code:
   <triggered_effect trigger="onSelfPrimaryActionStart" action="ModifyCVar" target="self" cvar="TestCVar" operation="set" value="1"/>
   <triggered_effect trigger="onSelfPrimaryActionStart" action="AnimatorSetFloat" target="self" property="TempProp" value="@TestCVar"/>
I get:

Code:
ERR XML loader: Loading and parsing 'items.xml' failed
FormatException: Unknown char: @ (input: '@TempCVar')
Basically these are the 2 lines that are causing it (actually the last line is causing it). For sake of testing I just created a new CVar and tried to pass it to the AnimationController.

If I pass a value like "3" it works fine. In this post from last year is noted that you can use a CVar for value with '@' in front of the name of the CVar and you can use it with Animator actions.

What am I doing wrong?
That's unfortunate it doesn't use cvars. That could have been used in a few interesting ways.

 
hi there, i followed your guide and attempted to add in a stainless steel mod but make it so that instead of it being craftable that it would be obtainable from the trader, i created a traders.xml file, added in the following code: <trader_item_group name="generalResources"> <!-- bundle size -->

<item name="steelPolish" count="50,1000"/> <!-- 50 -->

i know i went somewhere wrong, i had to open and close the code so to speak? so i put <append=xpath> or something, i tried different variations, i am very noob at this stuff sorry, i was just wondering if someone can help me figure this out, thanks.

Link to the mod and my issue here: https://7daystodie.com/forums/showthread.php?130484-MODLET-A18-Stainless-Steel-Again/page2

 
I don't think I read anything about setting the position of elements.

I'd like to move the UI elements out towards the edges more.

Only the things you see when no windows are open, like health, stamina, compass, toolbelt etc. All the static elements.

I've downloaded an addon that's a windows.xml to kinda dissect, if you will, but I can't make heads or tails of 'pos" attribute. I don't know where these values would be on screen.

 
Is it something wrong with my game or <property name="Sound_reload"> does not work? I tried to change the reload sound of my imported gun and nothing happened (it plays default pistol reload sound). Then I tested with simple mod:

items.xml

Code:
<config>
   <set xpath="/items/item[@name='gunPistol']/property[@class='Action0']/property[@name='Sound_reload']/@value">44magnum_reload</set>
</config>
and again the pistol_reload (not 44magnum_reload) sound plays.

 
Last edited by a moderator:
This may sound silly, but is xpath limited to changes to xml files within only the config folder? I am trying to write a modlet for changes to an xml file contained within the Worlds directory instead.

For example, adding the following prefab location line to a World Map prefabs.xml file.

Code:
   <decoration type="model" name="LazManPrison" position="5755,28,3164" rotation="0" />
 
This may sound silly, but is xpath limited to changes to xml files within only the config folder? I am trying to write a modlet for changes to an xml file contained within the Worlds directory instead.
For example, adding the following prefab location line to a World Map prefabs.xml file.

Code:
   <decoration type="model" name="LazManPrison" position="5755,28,3164" rotation="0" />
I think only the Data/Config files are read for xpath insertion. I'm assuming this is to add something to Navezgane?

 
I think only the Data/Config files are read for xpath insertion. I'm assuming this is to add something to Navezgane?
A custom world. No big deal though. Will just ask creator to include the xml edits and/or provide copy/paste instructions with the files. Thanks sphereii!

 
A custom world. No big deal though. Will just ask creator to include the xml edits and/or provide copy/paste instructions with the files. Thanks sphereii!
No problem. Good luck!

 
A custom world. No big deal though. Will just ask creator to include the xml edits and/or provide copy/paste instructions with the files. Thanks sphereii!
Add a mods/modname/worlds/yourworldname folder and put the fully edited prefabs.xml in there.

No Xpath, but it should "install" the worlds folder when run.

 
Add a mods/modname/worlds/yourworldname folder and put the fully edited prefabs.xml in there.
No Xpath, but it should "install" the worlds folder when run.
I think he was trying to add the prison to someone else' generated world. Kind of like a mod to an existing worl.

 
Yeh, he's adding it to Sam Neils world (see prefab section). If Sam packages it correctly (they're both learning how I think?), it'll be a non issue for him.

 
I not speak english. Sorry my english.

Not work:

<removeattribute xpath="/Sounds/SoundDataNode[@name=Auger_Fire_Start]/Noise/heat_map_strength" />

Work:

<removeattribute xpath="/Sounds/SoundDataNode[@name=Auger_Fire_Start]/Noise/@heat_map_strength" />

A18

Thanks for the description. Greatly help.

 
Last edited by a moderator:
hello, I'm looking for some help if u dont mind :c

Because I changed max stacks of items I also need to change the bundles to something more appropriate. So I did, but their names specify how many units they used to contain.

I need to change the name of the bundle items.

1 - preferred method through a property, couldn't find one working so far.

2 - localization file, I dislike that they would need to download it but whatever, thing is I put the localization file with the exact same name and structure in the indicated folder, loaded the game, the changes aren't reflected there yet no error is shown.

would you know a property to change its name or take a look at my localization file? its inside the config folder of the mod.

thanks!

View attachment 30417

Localization.txt

 

Attachments

Last edited by a moderator:
Yeh, he's adding it to Sam Neils world (see prefab section). If Sam packages it correctly (they're both learning how I think?), it'll be a non issue for him.
Yeah, I think sam incorporated into his v14 so my installation instructions probably no longer needed...😂

 
Hi guys. I feel really, really dumb. I've tried and tried to grasp XPath and been through the tutorials and looked at other mods and I just cannot get the syntax of it right. Sometimes it works for me, but mostly it doesn't seem to.

Can someone help me understand how to alter the birdnest block as an example and maybe I can finally get a firm understanding of how some of this is supposed to be properly done? I picked this block because I do want to change it and also I think it's a good example of covering several different cases such as altering, removing and appending lines.

Here's what I could really use help with:

1) Does the name of the XML file in a modlet matter? For example Can I use birdnest.xml to implement changes (provided I use proper syntax and nesting) or does it need to be blocks.xml ?

2) Does nesting in the XML file need to contain <config> or <configs>? Is there a necessary syntax for that (it doesn't seem so judging from other modlets I looked at trying to understand). Can I just use <JRavens> or <blahblahblah> so long as it has the requisite closing piece </JRavens>, </blahblahblah> etc.

3) Let's say I want to change a blocks material. In this example changing the birdnest from Wood to Grass (because well I think it's a little silly that birdnests have 100 health, clunk when you walk over them and explode into wood chips when destroyed). I tried this with no success:

Code:
<set xpath="/blocks/block[@name='cntBirdnest']/property[@name='Material']/@value">Mtallgrass</set>
4) Since I don't want bird nests to be harvested (just destroyed) I want to alter the harvest and destroy lines

(i.e. I want to player to get a some fibers and maybe some additional feathers when a nest is destroyed)

So I want to remove these lines:

Code:
	<drop event="Harvest" name="resourceCloth" count="1" prob="0.3" tag="allHarvest"/>
<drop event="Harvest" name="resourceFeather" count="3" prob="0.35" tag="allHarvest"/>
<drop event="Harvest" name="resourceFeather" count="2" prob="0.6" tag="allHarvest"/>
What's the proper syntax to remove those drop events?

5) Then say I want to alter this line to drop say half as many max fibers:

Code:
	<drop event="Destroy" name="resourceYuccaFibers" count="2,8"/>
So would this be a correct way to change that line??

Code:
<set xpath="/blocks/block[@name='cntBirdnest']/drop[@name='resourceYuccaFibers']/@count">2,4</set>
6) Finally lets say I want to append (add) in some lines to give a chance to drop some feathers (bird feathers often get stuck in nests and are even used when building them... actually lets go ahead and add back in a tiny chance for cloth or even paper to have been used as material for the nest...).

Would this code be proper?

Code:
<append xpath="/blocks/block[@name='cntBirdnest']" > 
<drop event="Destroy" name="resourceFeather" count="0,6" prob="0.8"/>
<drop event="Destroy" name="resourceCloth" count="0,1" prob="0.01"/>
<drop event="Destroy" name="resourcePaper" count="0,1" prob="0.01"/>
</append>
Thanks for any help and / or pointers. I am really struggling with this for some reason. I've never been good with code / regex style strings and such... my brain just doesn't work that way. I much prefer plain text, but I understand the need for xpath and so I would like to understand how to compose it correctly so I cna make my own modlets / mods. Thank you :)

 
Hi guys. I feel really, really dumb. I've tried and tried to grasp XPath and been through the tutorials and looked at other mods and I just cannot get the syntax of it right. Sometimes it works for me, but mostly it doesn't seem to.
Can someone help me understand how to alter the birdnest block as an example and maybe I can finally get a firm understanding of how some of this is supposed to be properly done? I picked this block because I do want to change it and also I think it's a good example of covering several different cases such as altering, removing and appending lines.

Here's what I could really use help with:

1) Does the name of the XML file in a modlet matter? For example Can I use birdnest.xml to implement changes (provided I use proper syntax and nesting) or does it need to be blocks.xml ?
The files in the Mods/MyMod/Config folder must match the XML it's patching. You wouldn't be able to do birdnest.xml; you'd have to do blocks.xml, if the changes were in the blocks file. If you also need a recipe, you'd have to do a recipes.xml as well.

2) Does nesting in the XML file need to contain <config> or <configs>? Is there a necessary syntax for that (it doesn't seem so judging from other modlets I looked at trying to understand). Can I just use <JRavens> or <blahblahblah> so long as it has the requisite closing piece </JRavens>, </blahblahblah> etc.
The top node doesn't matter what its called, as long as you open and close it. The top node is required because its part of the XML standard, but the game itself doesn't use the value in it.

3) Let's say I want to change a blocks material. In this example changing the birdnest from Wood to Grass (because well I think it's a little silly that birdnests have 100 health, clunk when you walk over them and explode into wood chips when destroyed). I tried this with no success:

Code:
<set xpath="/blocks/block[@name='cntBirdnest']/property[@name='Material']/@value">Mtallgrass</set>
In order for the game to pick this up, it'd have to be Config/blocks.xml

4) Since I don't want bird nests to be harvested (just destroyed) I want to alter the harvest and destroy lines

(i.e. I want to player to get a some fibers and maybe some additional feathers when a nest is destroyed)

So I want to remove these lines:

Code:
	<drop event="Harvest" name="resourceCloth" count="1" prob="0.3" tag="allHarvest"/>
<drop event="Harvest" name="resourceFeather" count="3" prob="0.35" tag="allHarvest"/>
<drop event="Harvest" name="resourceFeather" count="2" prob="0.6" tag="allHarvest"/>
What's the proper syntax to remove those drop events?
You would use the remove node.

Code:
<remove xpath="/blocks/block[@name='cntBirdnest']/drop[@name='resourceCloth']" />
<remove xpath="/blocks/block[@name='cntBirdnest']/drop[@name='resourceFeather']" />
<remove xpath="/blocks/block[@name='cntBirdnest']/drop[@name='resourceFeather']" />
This may also work, however I don't think it worked in A17:

Code:
<remove xpath="/blocks/block[@name='cntBirdnest']/drop" />
5) Then say I want to alter this line to drop say half as many max fibers:

Code:
<drop event="Destroy" name="resourceYuccaFibers" count="2,8"/>
So would this be a correct way to change that line??

Code:
<set xpath="/blocks/block[@name='cntBirdnest']/drop[@name='resourceYuccaFibers']/@count">2,4</set>
Yes, that line looks okay. Again, the changes would have to be done in a file calld blocks.xml

6) Finally lets say I want to append (add) in some lines to give a chance to drop some feathers (bird feathers often get stuck in nests and are even used when building them... actually lets go ahead and add back in a tiny chance for cloth or even paper to have been used as material for the nest...).

Would this code be proper?

Code:
<append xpath="/blocks/block[@name='cntBirdnest']" > 
<drop event="Destroy" name="resourceFeather" count="0,6" prob="0.8"/>
<drop event="Destroy" name="resourceCloth" count="0,1" prob="0.01"/>
<drop event="Destroy" name="resourcePaper" count="0,1" prob="0.01"/>
</append>
Yes, that'd be the correct xpath. I cannot confirm if the lines will do what you want them to do, since I don't have the files in front of me though.

Thanks for any help and / or pointers. I am really struggling with this for some reason. I've never been good with code / regex style strings and such... my brain just doesn't work that way. I much prefer plain text, but I understand the need for xpath and so I would like to understand how to compose it correctly so I cna make my own modlets / mods. Thank you :)
I hope this has helped a bit. Good luck, and ask more questions if you need help.

 
I hope this has helped a bit. Good luck, and ask more questions if you need help.
It did! Thank you very much sphereii.

I think I see now that a lot of my experiments were hit and miss because I wasn't always naming the files properly (bonehead assumption on my part).

I appreciate the help :)

 
Localization Support ( A18 and Beyond )

As of A18, Localization support from the Mods folder is available in vanilla.

In the Config folder, create a Localization.txt and a Localization - Quest.txt. This file must match case and spelling of the vanilla entries.

The localization files files have a heading, like the vanilla version, as a comma delimited line. For mod localization support, you only need to specify the heading that you are adding. For example, if your mod only contains localization for English, you do not need to specify the other language in the heading line.

If your new localization key matches a vanilla value, or a value from a previously loaded mod, then that value will be updated, with the last mod loaded having the final effect.

The format of the file is this:

HEADER

ENTRY

Example:

Code:
Key,Source,Context,Changes,English
myKey,UI,Item stat,New,This is my English Key
Note: If you are only including non-English translation, such as French, and leave the English blank or out, then a user loading the Spanish version will get the localization key. This is because English is the fall back translation. If you specify an English, then the spanish player will see the English localization.
Actually don't need to put all heading columns. Key and "Language" are enough to work.

Example:

English

Code:
Key,English
airConditioner,Air Conditioner
Spanish

Code:
Key,Spanish
airConditioner,Aire acondicionado
It works perfectlly with my Portuguese localization.

 
Actually don't need to put all heading columns. Key and "Language" are enough to work.
Example:

English

Code:
Key,English
airConditioner,Air Conditioner
Spanish

Code:
Key,Spanish
airConditioner,Aire acondicionado
It works perfectlly with my Portuguese localization.
Thank you for the update. That is replacing the existing vanilla localization. I wonder what would happen if you just included Key and language on a completely new item?

If someone loads your mod, and you only specify Portugesse or Spanish, and they do not have that set, they'll get the raw block or item name from the blocks.xml and items.xml. English is the fall back language to display, if an alternative language isn't specified.

 
Thank you for the update. That is replacing the existing vanilla localization. I wonder what would happen if you just included Key and language on a completely new item?
If someone loads your mod, and you only specify Portugesse or Spanish, and they do not have that set, they'll get the raw block or item name from the blocks.xml and items.xml. English is the fall back language to display, if an alternative language isn't specified.
It works to new items/blocks too.

Example of my vehicle respawning modlet with spanish language:

A18.1_2019-11-14_12-07-33.jpg

Code:
Key,Spanish
RespawnCarro,SAMUELPV's Car Respawning
 
Back
Top