• 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:
Quick question:

I am trying to tweak the Experience Gain multiplier for Nerd Glasses.  I can't seem to get the xpath to work.  I've tried these to no avail:

<set xpath="/items/item[@name='apparelNerdGlasses']/passive_effect[@name='PlayerExpGain']/@value">0.25</set>

<set xpath="/items/item[@name='apparelNerdGlasses']/passive_effect[@name='PlayerExpGain']/operation[@name='perc_add']/@value">0.25</set>

Any suggestions/solutions?  Any help would be appreciated!

DaemonGeek

 
Last edited by a moderator:
DaemonGeek said:
Quick question:

I am trying to tweak the Experience Gain multiplier for Nerd Glasses.  I can't seem to get the xpath to work.  I've tried these to no avail:

<set xpath="/items/item[@name='apparelNerdGlasses']/passive_effect[@name='PlayerExpGain']/@value">0.25</set>

<set xpath="/items/item[@name='apparelNerdGlasses']/passive_effect[@name='PlayerExpGain']/operation[@name='perc_add']/@value">0.25</set>

Any suggestions/solutions?  Any help would be appreciated!

DaemonGeek
I think you are missing the <effect_group> node, which contains the passive_effect

<set xpath="/items/item[@name='apparelNerdGlasses']/effect_group/passive_effect[@name='PlayerExpGain']/@value">0.25</set>

 
I think you are missing the <effect_group> node, which contains the passive_effect

<set xpath="/items/item[@name='apparelNerdGlasses']/effect_group/passive_effect[@name='PlayerExpGain']/@value">0.25</set>
That did the trick, thanks!

I thought I had tried every permutation but I think I included the operation="perc_add" in the attempt using effect_group. 

 
ok  - people who know more than I do - which is 99% of you

I have been fighting with trying to vary zombie xp without editing every  single zombie - tried this

<set xpath="/entity_classes/entity_class[contains(@name, 'zombie')]/property[contains(@name, 'ExperienceGain')]/@value">*.25</set>  

set all  occurrences of experiencegain on a zombie entity to  25% of what it was .

which "logically" should work as far as I understand BUT it doesnt  

please put me out of my misery before i smack my head through a wall  :)

 
ok  - people who know more than I do - which is 99% of you

I have been fighting with trying to vary zombie xp without editing every  single zombie - tried this

<set xpath="/entity_classes/entity_class[contains(@name, 'zombie')]/property[contains(@name, 'ExperienceGain')]/@value">*.25</set>  

set all  occurrences of experiencegain on a zombie entity to  25% of what it was .

which "logically" should work as far as I understand BUT it doesnt  

please put me out of my misery before i smack my head through a wall  :)
XPath can only find nodes and values and allow changes to them; But it cannot read in the original value enough to do any kind of math on them, so your current path won't result in what you want done.

 
XPath can only find nodes and values and allow changes to them; But it cannot read in the original value enough to do any kind of math on them, so your current path won't result in what you want done.


Thank you  and  - ill go back to  doing it entity by entity  - and redo each time they change entity names  :)  ah well

Rather interestingly -  my idea actually breaks the entire game  -  no zombies no animals and the traders is always locked and bounces you 

Im assuming then it sets all to *25  rather than multiplying it and  as zombieboe no longer exists all entities are removed 

 
Last edited by a moderator:
Thank you  and  - ill go back to  doing it entity by entity  - and redo each time they change entity names  :)  ah well

Rather interestingly -  my idea actually breaks the entire game  -  no zombies no animals and the traders is always locked and bounces you 

Im assuming then it sets all to *25  rather than multiplying it and  as zombieboe no longer exists all entities are removed 
The game is expecting a number, and you are giving it a string. It probably fails, on loading the rest of the entityclasses.xml.

Probably a pretty boring playthrough with just the player :)

 
Potentially a stupid question here . . .

Does /append tell the program where to look for a new localization file?

 
Reckis said:
Potentially a stupid question here . . .

Does /append tell the program where to look for a new localization file?
As far as I know, you can use xpath only inside xml files, which means it cannot be used to alter Localization.txt, if that's what you're wondering.

...

Sphereii, is there any way to use xpath to edit a single value from a list of values inside value attribute?

Example:

Change this:

<property name="TEST" value="1,2,3"/>

to this:

<property name="TEST" value="1,2,10"/>

 
Last edited by a moderator:
As far as I know, you can use xpath only inside xml files, which means it cannot be used to alter Localization.txt, if that's what you're wondering.
I disagree, I have seen other mod authors change the localization (i.e, changing the description of a perk or item) Unless I am way off base here . . . which I have to admit is entirely possible.

 
I disagree, I have seen other mod authors change the localization (i.e, changing the description of a perk or item) Unless I am way off base here . . . which I have to admit is entirely possible.
I think localization changes via modlet will overwrite vanilla entries if they exist and will append if they dont.

 
I disagree, I have seen other mod authors change the localization (i.e, changing the description of a perk or item) Unless I am way off base here . . . which I have to admit is entirely possible.
In Alpha 17, this was possible with my 7 Days to Die Mod Localization Loader script, not only you could add your own localizations to the base game localization files, but you could also change the existing ones, it would happen automatically depending on how you wrote your localization that was supposed to change the vanilla one, but devs were working on their own solution for Alpha 18 and perhaps improved it in Alpha 19. If and how is this particular type of modification possible in base game, I have no idea.

 
Last edited by a moderator:
In Alpha 17, this was possible with my 7 Days to Die Mod Localization Loader script, not only you could add your own localizations to the base game localization files, but you could also change the existing ones, it would happen automatically depending on how you wrote your localization that was supposed to change the vanilla one, but devs were working on their own solution for Alpha 18 and perhaps improved it in Alpha 19. If and how is this particular type of modification possible in base game, I have no idea.
Yes, localization file modifications can be pushed via modlet now and is supposed to even get pushed to clients on servers (A19) but haven't tested it out myself yet.

 
Yes, localization file modifications can be pushed via modlet now and is supposed to even get pushed to clients on servers (A19) but haven't tested it out myself yet.
I haven't played with it that much yet either. In fact, it is only now that I created some actual mods that I learned how to create the actual localization file. Back when I wrote that script, I made it so that it was blindly following the general format most people used for their localizations to make it work. I'm surprised it actually worked well lol

 
Trying to change when we get the warnings/debuffs on food, but can't get it to work,

<set xpath="/buffs/buff[@name='buffStatusCheck01']/triggered_effect'[@buff='buffStatusHungry01']/requirement[@name='StatComparePercCurrentToMax']/@value">.3</set>

gives an error about invalid token

Having too much of an headache today to figure out whats wrong >.<

 
Trying to change when we get the warnings/debuffs on food, but can't get it to work,

<set xpath="/buffs/buff[@name='buffStatusCheck01']/triggered_effect'[@buff='buffStatusHungry01']/requirement[@name='StatComparePercCurrentToMax']/@value">.3</set>

gives an error about invalid token

Having too much of an headache today to figure out whats wrong >.<
You have a extra apostrophe after triggered_effect. 

 
You have a extra apostrophe after triggered_effect. 
Geez. I think I need new glasses too.

Unfortunatly it did not apply but I managed a few moments of 'doh' and corrected the logic for the code and get it to work! \o/

<set xpath="/buffs/buff[@name='buffStatusCheck01']/effect_group/triggered_effect[@trigger='onSelfBuffUpdate' and @buff='buffStatusHungry01']/requirement[@name='StatComparePercCurrentToMax']/@value">.3</set>


Did the trick!

 
Hello everyone.  I'm new to modding, and xml coding altogether really.  I've been getting help from someone in direct messages and they provided me with a line of code that, in theory, will change shotgun ammo block damage versus wood blocks so that shotguns won't decimate entire buildings.  The line of code I was given is:
 

<set xpath="/items[@name='ammoShotgunShell']/effect_group[@name='ammoShotgunShell']/passive_effect[@name='BlockDamage'][@value='20']/@value">5.4</set>


I tried it and it did not work.  No errors or warnings, so I'm guessing it loaded without issue.  I figured the value was still too high, since shotgun ammo damage is per pellet so I lowered it to .05.  Still kills 2+ wooden blocks per trigger pull.  Prior to trying the above line of code I had modded it myself using this code:

<append item name="ammoShotgunShell">
<property name="Tags" value="ammo,shotgun"/>
<property name="DisplayType" value="ammoShotgun"/>
<property name="HoldType" value="45"/>
<property name="Meshfile" value="#Other/Items?Misc/sackPrefab.prefab"/>
<property name="DropMeshfile" value="#Other/Items?Misc/sack_droppedPrefab.prefab"/>
<property name="Material" value="Mlead_scrap"/>
<property name="Stacknumber" value="150"/> <!-- STK ammo low -->
<property name="EconomicValue" value="11"/>
<property name="Group" value="Ammo/Weapons"/>
<effect_group name="ammoShotgunShell" tiered="false">
<passive_effect name="EntityDamage" operation="base_set" value="11.2" tags="perkBoomstick"/>
<passive_effect name="BlockDamage" operation="base_set" value="5.4" tags="perkBoomstick"/>
<passive_effect name="BlockDamage" operation="base_add" value=".05" tags="wood"/> <!-- This is the damage value I need to change -->
<passive_effect name="RoundRayCount" operation="base_set" value="10" tags="perkBoomstick"/>
<passive_effect name="TargetArmor" operation="perc_add" value=".4" tags="perkBoomstick"/><display_value name="dTargetArmor" value=".4"/>
<passive_effect name="MaxRange" operation="base_set" value="10" tags="perkBoomstick"/>
<passive_effect name="DamageFalloffRange" operation="base_set" value="5" tags="perkBoomstick"/>
<passive_effect name="EntityPenetrationCount" operation="base_set" value="2" tags="perkBoomstick"/>
<passive_effect name="BlockPenetrationFactor" operation="base_set" value="51" tags="perkBoomstick"/>
<passive_effect name="SpreadDegreesVertical" operation="base_set" value="4.5" tags="perkBoomstick"/>
<passive_effect name="SpreadDegreesHorizontal" operation="base_set" value="4.5" tags="perkBoomstick"/>
<passive_effect name="SpreadMultiplierAiming" operation="perc_add" value="-.13" tags="perkBoomstick"/>
<passive_effect name="SpreadMultiplierCrouching" operation="perc_add" value="-.05" tags="perkBoomstick"/>
<passive_effect name="SpreadMultiplierWalking" operation="perc_add" value=".15" tags="perkBoomstick"/>
<passive_effect name="SpreadMultiplierRunning" operation="perc_add" value=".3" tags="perkBoomstick"/>
<passive_effect name="DamageModifier" operation="perc_add" value="-.8" tags="earth"/>
</effect_group>
</append>


The above code worked perfectly, but after reading this thread I now know that the above code didn't actually overwrite the vanilla code, it just added a second instance of the ammoShotgunShell to the items.xml file.  

Does anyone know how to make the line of code that I was given work?  I would love to use that since it is simple, easy, and clean.  Please note that both versions of modifying the ammo were tested with Boomstick at max, with a Tier 6 Auto Shotgun with full attachments, and 7/7 shotgun messiah books.  I have asked the person who gave me the code for assistance as well, but I feel like I am asking him for too much help, so I figured I would ask you guys too.  

Thank you in advance.

 
Back
Top