Need help with patching xml files

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Bifidus
Posts: 15
Joined: Sat, 1. Dec 18, 22:38
x4

Need help with patching xml files

Post by Bifidus »

Hi
I have a question about patching xml files, I made a little mod with the goal of adding different npcs to stations and for that I needed to change the md/npc_instantiation.xml file. But while replacing the whole file with changes included works fine, it's not really future proof (or other-mods proof for that matter) in any way so I've been looking into patching it properly and this is what I ended up with :

Code: Select all

<?xml version="1.0" encoding="utf-8"?> 
<diff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<replace sel="/mdscript/cues/cue/cues/library[@name='InstantiateNPCs']/actions/do_if/do_if[@value='this.$Object.exists']/do_elseif/
do_if[@value='this.$Object.workforce.amount and this.$Object.workforce.capacity']/do_all/do_all/do_if/do_if[@value='this.$SelectedRace']/do_any">
<set_value name="this.$Role" exact="entityrole.service" weight="50"/>
<set_value name="this.$Role" exact="entityrole.marine" weight="10"/>
<set_value name="this.$Role" exact="entityrole.pilot" weight="20"/>
<set_value name="this.$Role" exact="entityrole.manager" weight="10"/>
</do_any>
</replace>

</diff>
While I'm pretty sure the path is right (I want to replace everything included in the last do_any) I have a very limited knowledge of coding in general so I've been reading X rebirth related guides for help and it doesn't work :( . I've tried swaping around some things (at first I specified every values for the do_if/do_all etc statements before I realised I could simplify them ?)
If anyone could help on what's wrong it'd be greatly appreciated :)
Chair5768
Posts: 36
Joined: Sun, 15. Jan 06, 06:43
x3

Re: Need help with patching xml files

Post by Chair5768 »

Are you getting any debug errors? What are they?

adding, -debug all -logfile debug_rebirth.log

to your x4 shortcut will create a log file in your documents/egosoft/x4/### every time you run the game; if you haven't done so already. It's really helpful for stuff like this.


You're also missing the opening tag for <do_any>
SirNukes
Posts: 549
Joined: Sat, 31. Mar 07, 23:44
x4

Re: Need help with patching xml files

Post by SirNukes »

You can also use '//' in the xpath to recursively search children, which can shorten your search path and make it more robust if nesting is every added or removed. On the short side would be something like sel="//do_if[@value='this.$SelectedRace']/do_any".
Bifidus
Posts: 15
Joined: Sat, 1. Dec 18, 22:38
x4

Re: Need help with patching xml files

Post by Bifidus »

Thanks both of you, really helpful :)
It's now patched properly and it will definitely help in the future

Return to “X4: Foundations - Scripts and Modding”