• 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:
Good evening,

I am just trying my hand at modding by tweaking some things, the video tutorials in the other threads have been helpful but pretty straightforward so far. However I'm kind of stumped with how to do the following:

I wanted to give an inherent nerd outfit buff specifically to any person who is using a skill magazine for a perk they've leveled up.

for example: when a person with N points in Salvage operations reads the Scrapping4Fun magazine, they get a [N * 10] % chance of getting double points, similar to how the nerd outfit gives that buff.

I obviously don't want to add a million different buffs, so instead I looked at the class magazines in the items.xml:

<item name="salvageToolsSkillMagazine">
<property name="Tags" value="salvageToolsCSM,csm"/>
<property name="Extends" value="masterSkillMagazine"/>
<property name="CustomIcon" value="bookScrapping4Fun"/>
<property name="DescriptionKey" value="salvageToolsSkillMagazineDesc"/>
<property name="Unlocks" value="craftingSalvageTools"/>

<effect_group tiered="false">
<triggered_effect trigger="onSelfPrimaryActionEnd" action="AddProgressionLevel" progression_name="craftingSalvageTools" level="1"/> <!-- level="-1" sets a perk to max level -->
<triggered_effect trigger="onSelfPrimaryActionEnd" action="GiveExp" exp="50"/>
<triggered_effect trigger="onSelfPrimaryActionEnd" action="AddProgressionLevel" progression_name="craftingSalvageTools" level="1">
<requirement name="HasBuff" buff="buffNerdOutfit"/>
<requirement name="RandomRoll" seed_type="Random" min_max="0,100" operation="LTE" value="@$nerdOutfitSkillPointChance"/>
</triggered_effect>
</effect_group>


This is essentially saying, "when players clicks read, give them 1 point. Then, give them another point IF:

 (requirement HasBuff) - They have a nerd outfit on

 (requirement RandomRoll) - they succeed a roll based on the quality of the outfit.

Can I add something very similar for what I want? I was thinking just appending to each of the skill magazines, right before the end of the </effect_group> end tag, but this is what I'm currently stuck at:

<triggered_effect trigger="onSelfPrimaryActionEnd" action="AddProgressionLevel" progression_name="craftingSalvageTools" level="1">
<requirement name="ProgressionLevel" progression_name="perkSalvageOperations" operation="GTE" value="1"/>
<requirement name="RandomRoll" seed_type="Random" min_max="0,5" operation="LTE" value="@$perkSalvageOperations"/>
</triggered_effect>


Does this ... look right at all? whats the best way I can essentially do the nerd outfit criteria, but instead make the requirements:

(requirement) - user has at least 1 pt in corresponding perk skill

(requirement) - succeed a roll based on level of the skill they have invested.

 
Good day friends, I have such a question - I want to completely rewrite the file biomes.xml how can I realize it? I understand that the command set - changes the current value of the string to your value, apend - adds and in principle through the command set can rewrite all the values for each biome, but I want to do remove biomes.xml and write a completely new biomes.xml

 
Good day friends, I have such a question - I want to completely rewrite the file biomes.xml how can I realize it? I understand that the command set - changes the current value of the string to your value, apend - adds and in principle through the command set can rewrite all the values for each biome, but I want to do remove biomes.xml and write a completely new biomes.xml
Use "<remove xpath=""">

You can remove anything, from a single line to the complete contents of a file, depending where you point the xpath at.

Explained on the first page

 
Last edited by a moderator:
Good day friends, I have such a question - I want to completely rewrite the file biomes.xml how can I realize it? I understand that the command set - changes the current value of the string to your value, apend - adds and in principle through the command set can rewrite all the values for each biome, but I want to do remove biomes.xml and write a completely new biomes.xml


Set can be used to change the entire value, Khaine did it in the past for Darkness Falls.  I believe it is something like:

<set xpath="/biomes">



your code here



</set>




Couple of things to bring up about doing it this way.

  • Using Set to change everything means that any mods you have that make the changes prior to your mod loading up will be erased
  • Mass changing everything means that updates by TFP in the future won't be captured until you update them yourself (even values that you don't modify for your likening).



Personally, I would never recommend changing the file this way because of the two reasons above.  I always use remove and set / append / insertAfter / insertBefore in a targeted manner.  That way if something else changes that I am not changing for my purpose. the game will implement those changes without me going back into my code to update those changes.  In addition, it makes it easier to me to make smaller changes down the road when something is not working out the way I want to and easier to located (I use comments in my mods when they start getting lengthy to find the areas I am specifically looking for), and more than likely my mods won't conflict with other mods if someone wants to use mine.

Another benefit about using a targeted approach is that I can comment out specific parts of my code to revert back to vanilla settings if I am on the fence on a change and wanting to try it again in vanilla.  Again, the targeted approach makes it easier to do this.

 
A small modding question.
Are the biome's difficulty bonus display hardcoded? I changed the values on biomes.xml to make it so biome gamestage progression happens in increments of 1 and biome lootstage progression goes in .75, problem is, the game still shows half a skull in the burnt biome. 

I tried doing a wide search on the xmls for words like "biome" "bonus" "difficulty" "display" "skull" but nothing so far in the xui side of things. 
Am I overlooking something here?

 
Back
Top