• 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:
Howdy!
I've been working on a "no crafting" mod, and this thread has been gold! for information. I've learned a lot about xpath, etc.

I have unfortunately run into something.. Ive been able to get everything working the way i want it, but one part is giving me some issue.

The short story is this:

Code:
<config>

<remove xpath="/items/item[@name='modArmorPlatingBasicSchematic']" />

<append xpath="/items">
<item name="modArmorPlatingBasicSchematic">
<property name="Extends" value="schematicNoQualityMaster"/>
<property name="CreativeMode" value="Player"/>
<property name="CustomIcon" value="modArmorPlatingBasic"/>
<property name="Unlocks" value="modArmorPlatingBasic"/>
<effect_group tiered="false">
	<triggered_effect trigger="onSelfPrimaryActionEnd" action="ModifyCVar" 
cvar="modArmorPlatingBasic" operation="set" value="0"/>
	<triggered_effect trigger="onSelfPrimaryActionEnd" action="GiveExp" exp="50"/>
</effect_group>
</item>
</append>

</config>
this works, but everything i have tried to try to write it shorter.. to take up less space, and not have to

include everything... how am i trying to say this...

For some reason, just the way the game is, and does what it does right now, i can remove

all recipes from "recipes.xml", BUT, when i do, the trader sells all the item mods at 0 cost..

while all other items they sell DO have cost..

my workaround was to leave the recipes in there (that works fine), then to change

this line from value=1 --> value=0

Code:
<triggered_effect trigger="onSelfPrimaryActionEnd" action="ModifyCVar" 
cvar="modArmorPlatingBasic" operation="set" value="0"/>
that allows the trader to sell the item mods for #cost, but when you read the schematic,

you get the xp, but not the ability to craft it.

This is the intended goal, but i am looking for a shorter way to write this, rather than

write it the way i did above for every mod*schematic...

btw.. if i have to, i will. but i am sure there is a better way..

also, before i try with xpath, i DO try the changes in the actual xml file,

to make sure what i am trying is even valid..

i have tried starts-with, ends-with, set, etc...

each time it looks me right in the eye, and says F you,

for example:

Code:
<set xpath="/items/item[starts-with(@name, 'mod')]/triggered_effect[@operation='set']/@value">0</set>
this fails, for some reason..

Thanks!
I think the reason the above fails is that triggered_effect does not exist off an item node. They are always inside an <effect_group>

Either add a // or add in /effect_group

Code:
<set xpath="/items/item[starts-with(@name, 'mod')]//triggered_effect[@operation='set']/@value">0</set>
<set xpath="/items/item[starts-with(@name, 'mod')]/effect_group/triggered_effect[@operation='set']/@value">0</set>
 
I think the reason the above fails is that triggered_effect does not exist off an item node. They are always inside an <effect_group>
Either add a // or add in /effect_group

Code:
<set xpath="/items/item[starts-with(@name, 'mod')]//triggered_effect[@operation='set']/@value">0</set>
<set xpath="/items/item[starts-with(@name, 'mod')]/effect_group/triggered_effect[@operation='set']/@value">0</set>
Well, i'll be... yep.. that did the trick..

I tried both, and they did work.. I know that I did try adding in the /effect_group/ on at least one try, but most likely had some other

punctuation wrong or misplaced...

Many Thanks!

+1

I will probably post this modlet after i play it for a little bit to make sure nothing in normal gameplay got buggered..

 
Hi All,

Maybe someone could point me in the right direction, I am trying to modify value on a perk. It is from darkness falls mod, but this should not matter. I run into similar problem modifying random brackets on vanila game. Anyway here is xml code:

Code:
<perk name="perkASMiningTools" parent="skillMiningTools" max_level="100" base_skill_point_cost="0" name_key="perkASMiningToolsName" desc_key="perkASMiningToolsDesc" icon="ui_game_symbol_mining">
	<effect_group>
		<requirement name="HoldingItemHasTags" tags="perkMotherLode"/>
			<passive_effect name="BlockDamage" operation="perc_add" value="0.01,1" level="1,100"/>
			<passive_effect name="HarvestCount" operation="perc_add" value="0.01,1" level="1,100" />
			<effect_description level="1,100" desc_key="perkASMiningDesc"/>				
	</effect_group>
What I am aiming for is setting different value for HarvestCount. Here is my xpath:

Code:
<set xpath="perks/perk[@name="perkASMiningTools"]/effect_group/passive_effect[@name="HarvestCount"]/@value">0.01,0.5</set>
Word perks comes from file structure perks/perk etc. On game load I always get an error. Only way to go around this is to xpathremove whole effect_group and append new one. I would like some more flexible solution :) .

Thanks

 
Hi All,
Maybe someone could point me in the right direction, I am trying to modify value on a perk. It is from darkness falls mod, but this should not matter. I run into similar problem modifying random brackets on vanila game. Anyway here is xml code:

Code:
<perk name="perkASMiningTools" parent="skillMiningTools" max_level="100" base_skill_point_cost="0" name_key="perkASMiningToolsName" desc_key="perkASMiningToolsDesc" icon="ui_game_symbol_mining">
	<effect_group>
		<requirement name="HoldingItemHasTags" tags="perkMotherLode"/>
			<passive_effect name="BlockDamage" operation="perc_add" value="0.01,1" level="1,100"/>
			<passive_effect name="HarvestCount" operation="perc_add" value="0.01,1" level="1,100" />
			<effect_description level="1,100" desc_key="perkASMiningDesc"/>				
	</effect_group>
What I am aiming for is setting different value for HarvestCount. Here is my xpath:

Code:
<set xpath="perks/perk[@name="perkASMiningTools"]/effect_group/passive_effect[@name="HarvestCount"]/@value">0.01,0.5</set>
Word perks comes from file structure perks/perk etc. On game load I always get an error. Only way to go around this is to xpathremove whole effect_group and append new one. I would like some more flexible solution :) .

Thanks
The start of your xpath is probably not as correct as it should be. should it be something like /progression/perks/ ? or just add //perks/perk...

 
Thanks @Sphereii,

That did the trick.... I was so worried about the rest of the syntax I missed such simple thing.

Purpose of // is to start at that line as I understand, so I can avoid typing to long strings in such instances?

 
Now I'm back with even more weird problems -.-

I'm trying to add a item that can be used to repair the different oven/stoves found to a working one based from Valmod.

The repairitem is added in and can be found in lootlists, but when I try to update an oven it just shows the 'missing item' error (correct one though) even when I have the item on me.

This is what I have appended in blocks.xml under <append xpath="/blocks">

Code:
<block name="workstationOven">
	<property name="DescriptionKey" value="workstationOvenDesc"/>
	<property name="Class" value="Campfire" />
	<property name="CustomIcon" value="cntWallOven" />
	<property name="Place" value="TowardsPlacerInverted" />
	<property name="Stacknumber" value="1" />
	<property name="Material" value="Mwood_weak" />
	<property name="Texture" value="346,345,341,345,262,345" />
	<property name="LootList" value="130" />
	<drop event="Destroy" name="resourceScrapIron" count="5,10" />
	<drop event="Fall" name="woodDebris" count="1" prob="1.0"  stick_chance=".75" />
	<property name="HeatMapStrength" value="1"/>
	<property name="HeatMapTime" value="1200"/>
	<property name="HeatMapFrequency" value="25"/>
	<property name="Group" value="Food/Cooking,Decor" />
	<property name="ActiveRadiusEffects" value="+heatSource(3)"/>
	<property class="Workstation">
		<property name="Modules" value="tools,output,input"/>
		<property name="CraftingAreaRecipes" value="campfire" />
	</property>
</block>
</append>	

<append xpath="blocks/block[@name='cntWallOven']">
	<property class="UpgradeBlock">
	<property name="ToBlock" value="workstationOven"/>
	<property name="Item" value="ElectricalRepairKit"/>
	<property name="ItemCount" value="1"/>
	<property name="UpgradeHitCount" value="5"/>
</property>
<property name="CustomUpgradeSound" value="place_block_metal" />
</append>

<append xpath="blocks/block[@name='cntStoveOldVer1Closed']">
	<property class="UpgradeBlock">
	<property name="ToBlock" value="workstationOven"/>
	<property name="Item" value="ElectricalRepairKit"/>
	<property name="ItemCount" value="1"/>
	<property name="UpgradeHitCount" value="5"/>
</property>
<property name="CustomUpgradeSound" value="place_block_metal" />
</append>
And this is the item appended in items.xml

Code:
<append xpath="/items">
<item name="ElectricalRepairKit">
<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="MresourceScrapIron" />
<property name="Weight" value="1" />
<property name="Stacknumber" value="25" /> <!-- STK resource -->
<property name="EconomicValue" value="10" />
<property name="EconomicBundleSize" value="10" />
<property name="Group" value="Resources" />
<property name="RepairTime" value=".5" />
<property name="RepairAmount" value="20" />
<property name="CraftingIngredientTime" value=".2" />
<property name="CustomIcon" value="resourceRepairKit" />
</item>
</append>
I tried to change the item to just need resourceScrapIron, and then it worked flawlessly and used one scrapiron, but not with the ElectricalRepairKit. All the items are loaded and looks correct in the configdump xmls

 
Now I'm back with even more weird problems -.-I'm trying to add a item that can be used to repair the different oven/stoves found to a working one based from Valmod.

The repairitem is added in and can be found in lootlists, but when I try to update an oven it just shows the 'missing item' error (correct one though) even when I have the item on me.

This is what I have appended in blocks.xml under <append xpath="/blocks">

Code:
<block name="workstationOven">
	<property name="DescriptionKey" value="workstationOvenDesc"/>
	<property name="Class" value="Campfire" />
	<property name="CustomIcon" value="cntWallOven" />
	<property name="Place" value="TowardsPlacerInverted" />
	<property name="Stacknumber" value="1" />
	<property name="Material" value="Mwood_weak" />
	<property name="Texture" value="346,345,341,345,262,345" />
	<property name="LootList" value="130" />
	<drop event="Destroy" name="resourceScrapIron" count="5,10" />
	<drop event="Fall" name="woodDebris" count="1" prob="1.0"  stick_chance=".75" />
	<property name="HeatMapStrength" value="1"/>
	<property name="HeatMapTime" value="1200"/>
	<property name="HeatMapFrequency" value="25"/>
	<property name="Group" value="Food/Cooking,Decor" />
	<property name="ActiveRadiusEffects" value="+heatSource(3)"/>
	<property class="Workstation">
		<property name="Modules" value="tools,output,input"/>
		<property name="CraftingAreaRecipes" value="campfire" />
	</property>
</block>
</append>	

<append xpath="blocks/block[@name='cntWallOven']">
	<property class="UpgradeBlock">
	<property name="ToBlock" value="workstationOven"/>
	<property name="Item" value="ElectricalRepairKit"/>
	<property name="ItemCount" value="1"/>
	<property name="UpgradeHitCount" value="5"/>
</property>
<property name="CustomUpgradeSound" value="place_block_metal" />
</append>

<append xpath="blocks/block[@name='cntStoveOldVer1Closed']">
	<property class="UpgradeBlock">
	<property name="ToBlock" value="workstationOven"/>
	<property name="Item" value="ElectricalRepairKit"/>
	<property name="ItemCount" value="1"/>
	<property name="UpgradeHitCount" value="5"/>
</property>
<property name="CustomUpgradeSound" value="place_block_metal" />
</append>
And this is the item appended in items.xml

Code:
<append xpath="/items">
<item name="ElectricalRepairKit">
<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="MresourceScrapIron" />
<property name="Weight" value="1" />
<property name="Stacknumber" value="25" /> <!-- STK resource -->
<property name="EconomicValue" value="10" />
<property name="EconomicBundleSize" value="10" />
<property name="Group" value="Resources" />
<property name="RepairTime" value=".5" />
<property name="RepairAmount" value="20" />
<property name="CraftingIngredientTime" value=".2" />
<property name="CustomIcon" value="resourceRepairKit" />
</item>
</append>
I tried to change the item to just need resourceScrapIron, and then it worked flawlessly and used one scrapiron, but not with the ElectricalRepairKit. All the items are loaded and looks correct in the configdump xmls
I'm not much of an expert on this, but how are you applying the upgrade? via a hammer? Did you also update the hammer's Allowed_upgrade_items to include your new item?

 
I'm not much of an expert on this, but how are you applying the upgrade? via a hammer? Did you also update the hammer's Allowed_upgrade_items to include your new item?
I tried with nailgun and stoneaxe, but I was unaware of that allowed_upgrade_item. That's probably it! Gonna apply that example code from page one to change all of those when I get back home :D

Many many thanks for helping with my numerous mishaps. I just can't seem to get the hang of xpath's logic :(

 
Hi, how do I enter here with xpath:

"<effect_group name="gunJunkTurret">

<passive_effect name="MaxRange" operation="base_set" value="15"/>

<passive_effect name="DamageFalloffRange" operation="base_set" value="10"/>

<passive_effect name="DamageFalloffRange" operation="perc_add" value="-.2,.2"/> <!-- random effective rng -->

<passive_effect name="BlockRange" operation="base_set" value="3"/>

<passive_effect name="EntityDamage" operation="base_set" value="11.8"/>

<passive_effect name="EntityDamage" operation="perc_add" value="-.15,.15"/> <!-- random EntityDmg -->

<passive_effect name="EntityDamage" operation="perc_add" value=".1,.5" tier="2,6"/> <!-- tier bonus -->

<passive_effect name="DegradationMax" operation="perc_add" value="-.2,.2" tags="perkTurrets"/> <!-- random DegMax -->

<passive_effect name="WeaponHandling" operation="perc_add" value="-.08,.08"/> <!-- random WeaponHandling -->

<passive_effect name="RoundsPerMinute" operation="perc_add" value="-.1,.1"/> <!-- random APM -->

<passive_effect name="MagazineSize" operation="perc_add" value="-.122,.122"/> <!-- random MagazineSize -->

<passive_effect name="WeaponHandling" operation="perc_add" value="-.08,.08"/> <!-- random WeaponHandling -->

<passive_effect name="BlockDamage" operation="base_set" value="1"/>

<passive_effect name="RoundsPerMinute" operation="base_set" value="105.6"/>

<passive_effect name="BurstRoundCount" operation="base_set" value="1"/>

<!-- was

<passive_effect name="MagazineSize" operation="base_set" value="50"/>

<passive_effect name="MagazineSize" operation="base_add" value="2,10" tier="2,6"/>

-->

<passive_effect name="MagazineSize" operation="base_set" value="62"/>

<passive_effect name="MagazineSize" operation="base_add" value="6,30" tier="2,6"/>

<passive_effect name="ReloadSpeedMultiplier" operation="base_set" value="1"/>

<passive_effect name="SpreadDegreesVertical" operation="base_set" value="5"/>

<passive_effect name="SpreadDegreesHorizontal" operation="base_set" value="5"/>

<passive_effect name="SpreadMultiplierAiming" operation="perc_add" value="-.13"/>

<passive_effect name="SpreadMultiplierCrouching" operation="perc_add" value="-.05"/>

<passive_effect name="SpreadMultiplierWalking" operation="perc_add" value=".15"/>

<passive_effect name="SpreadMultiplierRunning" operation="perc_add" value=".3"/>

<passive_effect name="KickDegreesVerticalMin" operation="base_set" value="3"/>

<passive_effect name="KickDegreesVerticalMax" operation="base_set" value="3"/>

<passive_effect name="KickDegreesHorizontalMin" operation="base_set" value="-2"/>

<passive_effect name="KickDegreesHorizontalMax" operation="base_set" value="2"/>

<passive_effect name="IncrementalSpreadMultiplier" operation="base_set" value="0"/>

<passive_effect name="WeaponHandling" operation="base_set" value="1"/>

<passive_effect name="JunkTurretActiveRange" operation="base_set" value="30"/>

<passive_effect name="DegradationMax" operation="base_set" value="250,600" tier="1,6" tags="perkTurrets"/>

<passive_effect name="DegradationPerUse" operation="base_set" value="0.35" tags="perkTurrets"/>

<passive_effect name="ModSlots" operation="base_set" value="1,1,2,2,3,4" tier="1,2,3,4,5,6"/>

<passive_effect name="ModPowerBonus" operation="perc_add" value=".10" tags="EntityDamage"/>

<passive_effect name="ModPowerBonus" operation="base_add" value="300" tags="EconomicValue"/>

</effect_group>

"

 
How can i remove dynamite completly from the game?So you cant craft or loot it.

Thanks in advance ;)

Orakel
My quick anser is to set damage to 0 if the griefing is what worries you, that's easy. But if you want to achieve what you said, redo the nodes of loot groups where it appears, and for the crafting, you can alter the recipe, either set the ammount result to 0, or add an unobtainable resource to it.

 
i cant get this to work, any ideas?

<configs>

<!--CDSStartingLoot-->

<set xpath="/entity_classes/entity_class[@name=playerMale]/property[@name=ItemsOnEnterGame.GameModeSurvival]/@value">hitMe1</set>

<set xpath="/entity_classes/entity_class[@name=playerMale]/property[@name=ItemsOnEnterGame.GameModeSurvivalSP]/@value">hitMe1</set>

<set xpath="/entity_classes/entity_class[@name=playerMale]/property[@name=ItemsOnEnterGame.GameModeSurvivalMP]/@value">hitMe1</set>

</configs>
 
The good news is that its valid xpath. What exactly isn't working? What's your mod-let folder structure?
the same as everybody else. The mod is suppose to change starting look. Even removing all other files and just leaving the mod info, an the folder with the entities file. and then placing a vanilla item into the code, it still doesnt change out the starting loot.

its just a starting loot change mod. I would reference somebody elses, but i couldnt find any in the forums that were current with xpath.

folder structure = mods>modlet folder>mod info + mod folder>files

 
so am i doing setpath wrong? is that why the game is pretty much ignoring the change in entity starting loot?

i seem to remember having this issue last year and having to use something else. I really wish i had my old file to reference.

 
i think i figured out my mistake. I saved the files as file all and not .xml. I'll test this theory out in the morning.

 
i think i figured out my mistake. I saved the files as file all and not .xml. I'll test this theory out in the morning.
This makes sense, and sorry for the delay. That was why I was asking about the structure of the files.

 
This makes sense, and sorry for the delay. That was why I was asking about the structure of the files.
i wish i was right. I reviewed the fl and all are saved as .xml. and still not working. I can see where boot says it is reading them. but when you log into the game it still gives the vanilla starting loot. I have even tried deleting the blocks and loot files and replacing the item with a vanilla one, and it still ignores the swapped loot.

I am having the same problem with several other peoples mods, where the vanilla files are simply not being overwritten at bootup, even though the boot files says that it read the modlet.

 
Back
Top