xpatch other mod's weapon tags

Started by Elwo, October 03, 2019, 04:11:28 PM

Previous topic - Next topic

Elwo

Hi!
So I wanted to create a custom faction that use equipment from 'ancient rim' mod, but that equipment has tags (<weapontags> for example) that i don't want to use because many more unwanted items use it as well. So i went and made a xpatch file and it goes like this:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
    <Operation Class="PatchOperationAdd">
<xpath>*/Defs/ThingDefs[defName = "AR_Falcata"]/weaponTags</xpath>
<value>
<li>IberianWeaponsMelee</li>
</value>
</Operation>

    <Operation Class="PatchOperationAdd">
<xpath>*/Defs/ThingDefs[defName = "AR_LightCape"]/tags</xpath>
<value>
<li>IberianCapes</li>
</value>
</Operation>

<Operation Class="PatchOperationAdd">
<xpath>*/Defs/ThingDefs[defName = "AR_Himation"]/tags</xpath>
<value>
<li>IberianClothes</li>
</value>
</Operation>
</Patch>


From the little knowledge I have, what I'm trying to do is for the game to search for example for "AR_Falcata" and add a weapontag "IberianWeaponsMelee", so I can use it in my "pawnkinds def" properly.

But what I get is this horror


Can anyone help me make the corrections I need in order to make the xpath work? All I want is to add simple tags to already existing items from another mod.

And yes, the actual path to the def file is Defs/ThingDefs

Hjkma

QuoteAnd yes, the actual path to the def file is Defs/ThingDefs
xpath operations does not use file paths, this is your mistake
xpath should look like this:
<xpath>Defs/ThingDef[defName = "AR_LightCape"]/tags</xpath>

Elwo

#2
Oh, thanks for pointing that out. I've been wrestling with that 3 days now.

I did corrections and now the AR_Falcata works well, so I know that I can add the <weapontag> now, but for some reason it does not work for the AR_LightCape and AR_Himalton.
Is there a diffrent parameter for aparell or something one should type right here?

<xpath>Defs/ThingDef[defName = "AR_LightCape"]/tags</xpath>

Here's the code.

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
   <Operation Class="PatchOperationAdd">
      <xpath>Defs/ThingDef[defName = "AR_Falcata"]/weaponTags</xpath>
         <value>
            <li>IberianWeaponsMelee</li>
         </value>
   </Operation>
     
    <Operation Class="PatchOperationAdd">
         <xpath>Defs/ThingDef[defName = "AR_LightCape"]/tags</xpath>
         <value>
            <li>IberianCapes</li>
         </value>
   </Operation>     
     
   <Operation Class="PatchOperationAdd">
         <xpath>Defs/ThingDef[defName = "AR_Himation"]/tags</xpath>
         <value>
            <li>IberianClothes</li>
         </value>
   </Operation>         
</Patch>

Hjkma

Show xml block of thingDef "AR_LightCape" first.

Elwo

#4
Here it is
<thingDef ParentName="AncientApparelMakeableBase">
<defName>AR_Cape</defName>
<description>It's a cape.</description>
<label>cape</label>
<graphicData>
<texPath>Items/Apparel/CapeOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
<shaderType>CutoutComplex</shaderType>
</graphicData>
<costStuffCount>90</costStuffCount>
<stuffCategories>
<li>Fabric</li>
<li>Leathery</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<statBases>
<WorkToMake>8000</WorkToMake>
<MaxHitPoints>180</MaxHitPoints>
<StuffEffectMultiplierArmor>0.3</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>0.75</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.75</StuffEffectMultiplierInsulation_Heat>
<Mass>2.2</Mass>
<EquipDelay>2.5</EquipDelay>
</statBases>
<equippedStatOffsets>
<SocialImpact>0.1</SocialImpact>
</equippedStatOffsets>
<apparel>
<bodyPartGroups>
<li>Torso</li>
<li>Shoulders</li>
<li>Legs</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/Cape/Cape</wornGraphicPath>
<layers>
<li>Shell</li>
</layers>
<tags>
<li>RomeOfficer</li>
<li>BarbarianNoble</li>
</tags>
<defaultOutfitTags>
<li>Worker</li>
</defaultOutfitTags>
</apparel>
</thingDef>



EDIT:
Now that I look at it, shouldn't it be something like:
<xpath>Defs/ThingDef[defName = "AR_LightCape"]/apparel/tags/</xpath>
instead of just
<xpath>Defs/ThingDef[defName = "AR_LightCape"]/tags</xpath>
???

MORE EDIT:

So I've made it, but I'm not quite satisfied.
<xpath>Defs/ThingDef[@ParentName="AncientApparelMakeableBase"]/apparel/tags</xpath>
The code above works, but it adds that tag to every single child def of that parent. Is there a way to further specify just the one item from many?

Hjkma

#5
If I understood correctly, then xpath should look like this:
<xpath>Defs/ThingDef[defName="AR_Cape"]/apparel/tags</xpath>

you can patch a lot of defName like this:
<xpath>Defs/ThingDef[defName="AR_Cape" or defName="AR_LightCape"]/apparel/tags</xpath>

Elwo

For my logic, your code should work absolutely fine. But it does not somehow. I think it's the problem with locating the correct def, because it works fine on the parent but not the child def. I need to find a way to select it correctly.

Hjkma

#7
Post the entire def file and the patch file. And the error message in the debug log. Then it will be clear what the problem is.

Elwo

Ok so here's the def file from the other mod:

<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<ThingDef Name="AncientApparelMakeableBase" ParentName="ApparelBase" Abstract="True">
<recipeMaker>
<workSpeedStat>TailoringSpeed</workSpeedStat>
<workSkill>Crafting</workSkill>
<effectWorking>Tailor</effectWorking>
<soundWorking>Recipe_Tailor</soundWorking>
<recipeUsers>
<li>AR_TailoringBench</li>
</recipeUsers>
<unfinishedThingDef>UnfinishedApparel</unfinishedThingDef>
</recipeMaker>
</ThingDef>

<ThingDef Name="AncientArmorMakeableBase" ParentName="ApparelBase" Abstract="True">
<statBases>
<MaxHitPoints>300</MaxHitPoints>
<Flammability>1.0</Flammability>
<DeteriorationRate>2</DeteriorationRate>
<Beauty>-4</Beauty>
<SellPriceFactor>0.70</SellPriceFactor>
</statBases>
<recipeMaker>
<unfinishedThingDef>UnfinishedApparel</unfinishedThingDef>
<workSpeedStat>SmithingSpeed</workSpeedStat>
<workSkill>Crafting</workSkill>
<effectWorking>Smith</effectWorking>
<soundWorking>Recipe_Smith</soundWorking>
<recipeUsers>
<li>ElectricSmithy</li>
<li>FueledSmithy</li>
</recipeUsers>
<defaultIngredientFilter>
<categories>
<li>Root</li>
</categories>
<disallowedThingDefs>
<li>Gold</li>
<li>Silver</li>
<li>Plasteel</li>
<li>Jade</li>
<li>Uranium</li>
</disallowedThingDefs>
</defaultIngredientFilter>
</recipeMaker>
</ThingDef>

<!-- Civil -->

<ThingDef ParentName="AncientApparelMakeableBase">
<defName>AR_Tunic</defName>
<description>A common shirt in the civilized parts of the world.</description>
<label>tunic</label>
<graphicData>
<texPath>Items/Apparel/TunikaOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<costStuffCount>60</costStuffCount>
<stuffCategories>
<li>Fabric</li>
<li>Leathery</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<statBases>
<WorkToMake>2000</WorkToMake>
<StuffEffectMultiplierArmor>0.2</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>0.16</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.26</StuffEffectMultiplierInsulation_Heat>
<EquipDelay>1.5</EquipDelay>
<Mass>0.6</Mass>
</statBases>
<apparel>
<bodyPartGroups>
<li>Torso</li>
<li>Shoulders</li>
<li>Legs</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/Tunika/Tunika</wornGraphicPath>
<layers>
<li>OnSkin</li>
</layers>
<tags>
<li>Hellenic</li>
<li>RomeCivil</li>
<li>Persian</li>
</tags>
<defaultOutfitTags>
<li>Worker</li>
</defaultOutfitTags>
</apparel>
<colorGenerator Class="ColorGenerator_StandardApparel" />
</ThingDef>

<ThingDef ParentName="AncientApparelMakeableBase">
<defName>AR_BeltedSkirt</defName>
<description>Common clothing in the civilized parts of the world.</description>
<label>belted skirt</label>
<graphicData>
<texPath>Items/Apparel/BeltedSkirtOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<costStuffCount>35</costStuffCount>
<stuffCategories>
<li>Fabric</li>
<li>Leathery</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<statBases>
<WorkToMake>1600</WorkToMake>
<StuffEffectMultiplierArmor>0.2</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>0.06</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.32</StuffEffectMultiplierInsulation_Heat>
<EquipDelay>1.5</EquipDelay>
<Mass>0.3</Mass>
</statBases>
<apparel>
<bodyPartGroups>
<li>Legs</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/BeltedSkirt/Skirt</wornGraphicPath>
<layers>
<li>OnSkin</li>
</layers>
<tags>
<li>Hellenic</li>
<li>RomeCivil</li>
<li>Spartan</li>
</tags>
<defaultOutfitTags>
<li>Worker</li>
</defaultOutfitTags>
</apparel>
<colorGenerator Class="ColorGenerator_StandardApparel" />
</ThingDef>

<thingDef ParentName="AncientApparelMakeableBase">
<defName>AR_FurCape</defName>
<label>fur cape</label>
<description>Sometimes it is necessary to dress like a barbarian, especially in barbarian terrain.</description>
<graphicData>
<texPath>Items/Apparel/FurCapeOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<techLevel>Neolithic</techLevel>
<costStuffCount>120</costStuffCount>
<stuffCategories>
<li>Leathery</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<statBases>
<MaxHitPoints>180</MaxHitPoints>
<WorkToMake>8000</WorkToMake>
<Mass>3.8</Mass>
<StuffEffectMultiplierArmor>0.2</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>2.00</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.00</StuffEffectMultiplierInsulation_Heat>
<EquipDelay>2.5</EquipDelay>
</statBases>
<equippedStatOffsets>
<MoveSpeed>-0.05</MoveSpeed>
</equippedStatOffsets>
<apparel>
<bodyPartGroups>
<li>Torso</li>
<li>Shoulders</li>
<li>Arms</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/FurCape/FurCape</wornGraphicPath>
<layers>
<li>Shell</li>
</layers>
<tags>

</tags>
<defaultOutfitTags>
<li>Worker</li>
<li>Soldier</li>
</defaultOutfitTags>
</apparel>
</thingDef>

<thingDef ParentName="AncientApparelMakeableBase">
<defName>AR_Cape</defName>
<description>It's a cape.</description>
<label>cape</label>
<graphicData>
<texPath>Items/Apparel/CapeOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
<shaderType>CutoutComplex</shaderType>
</graphicData>
<costStuffCount>90</costStuffCount>
<stuffCategories>
<li>Fabric</li>
<li>Leathery</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<statBases>
<WorkToMake>8000</WorkToMake>
<MaxHitPoints>180</MaxHitPoints>
<StuffEffectMultiplierArmor>0.3</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>0.75</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.75</StuffEffectMultiplierInsulation_Heat>
<Mass>2.2</Mass>
<EquipDelay>2.5</EquipDelay>
</statBases>
<equippedStatOffsets>
<SocialImpact>0.1</SocialImpact>
</equippedStatOffsets>
<apparel>
<bodyPartGroups>
<li>Torso</li>
<li>Shoulders</li>
<li>Legs</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/Cape/Cape</wornGraphicPath>
<layers>
<li>Shell</li>
</layers>
<tags>
<li>RomeOfficer</li>
<li>BarbarianNoble</li>
</tags>
<defaultOutfitTags>
<li>Worker</li>
</defaultOutfitTags>
</apparel>
</thingDef>

<!-- Armor -->

<thingDef ParentName="AncientArmorMakeableBase">
<defName>AR_Kardiophylax</defName>
<description>An pre-roman armor type. Basically just a plate covering the torsos front</description>
<label>Kardiophylax</label>
<graphicData>
<texPath>Items/Apparel/KardiophylaxOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<costStuffCount>80</costStuffCount>
<stuffCategories>
<li>Metallic</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<equippedStatOffsets>
<MoveSpeed>-0.025</MoveSpeed>
</equippedStatOffsets>
<statBases>
<WorkToMake>10000</WorkToMake>
<Mass>5</Mass>
<StuffEffectMultiplierArmor>0.5</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>0.15</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.15</StuffEffectMultiplierInsulation_Heat>
<EquipDelay>5</EquipDelay>
</statBases>
<apparel>
<bodyPartGroups>
<li>Torso</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/Kardiophylax/Kardiophylax</wornGraphicPath>
<layers>
<li>Middle</li>
</layers>
<tags>
<li>RomeSoldier</li>
<li>Military</li>
</tags>
<defaultOutfitTags>
<li>Soldier</li>
</defaultOutfitTags>
</apparel>
<colorGenerator Class="ColorGenerator_StandardApparel" />
</thingDef>

<thingDef ParentName="AncientArmorMakeableBase">
<defName>AR_Spaulder</defName>
<description>Armor designed only to protect the shoulder</description>
<label>Spaulder</label>
<graphicData>
<texPath>Items/Apparel/SpaulderOnMap</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<costStuffCount>30</costStuffCount>
<stuffCategories>
<li>Metallic</li>
</stuffCategories>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<statBases>
<WorkToMake>10000</WorkToMake>
<Mass>5</Mass>
<StuffEffectMultiplierArmor>0.73</StuffEffectMultiplierArmor>
<StuffEffectMultiplierInsulation_Cold>1.0</StuffEffectMultiplierInsulation_Cold>
<StuffEffectMultiplierInsulation_Heat>0.5</StuffEffectMultiplierInsulation_Heat>
<EquipDelay>5</EquipDelay>
</statBases>
<apparel>
<bodyPartGroups>
<li>Shoulders</li>
</bodyPartGroups>
<wornGraphicPath>Items/Apparel/Spaulder/Spaulder</wornGraphicPath>
<layers>
<li>Middle</li>
</layers>
<tags>
</tags>
<defaultOutfitTags>
<li>Soldier</li>
</defaultOutfitTags>
</apparel>
<colorGenerator Class="ColorGenerator_StandardApparel" />
</thingDef>

</Defs>


And here is my patch file


<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
<xpath>Defs/ThingDef[defName="AR_Cape"]/apparel/tags</xpath>
<value>
<li>IberianCapes</li>
</value>
</Operation>

<Operation Class="PatchOperationAdd">
<xpath>Defs/ThingDef[defName="AR_Tunic"]/apparel/tags</xpath>
<value>
<li>IberianClothes</li>
</value>
</Operation>
</Patch>


And now here comes the fearful error message:


[Iberian Faction - Addon] Patch operation Verse.PatchOperationAdd(Defs/ThingDef[defName="AR_Cape"]/apparel/tags) failed
file: C:\RimWorld_Modder\Mods\Iberian Faction - Addon\Patches\Patches_AncientRim_SPQRim.xml
Verse.Log:Error(String, Boolean)
Verse.PatchOperation:Complete(String)
Verse.LoadedModManager:ClearCachedPatches()
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()



As you can see, Something changed. Somehow (because I don't really know why) the AR_Tunic started working today. Like, zero issues. But even though the cape is a similar item, it won't work for it. I even tried to brute foce it by copying whole AR_Tunic xpath and just changing it to AR_Cape - no luck there.

By the way, thank you for spending your time trying to figure this out with me, I already owe you ;)

Hjkma

#9
Well, I think the error is in the mod itself, in the file the ThingDef tag is written with a small letter, that is:
<thingDef ParentName="AncientApparelMakeableBase">
<defName>AR_FurCape</defName>
...
</thingDef>

It should be like this:
<ThingDef ParentName="AncientApparelMakeableBase">
<defName>AR_FurCape</defName>
...
</ThingDef>


I'm not sure if this leads to errors in the game, just everyone uses a tag with a capital letter, but if everything is ok with the mod, then just write xpath with a small letter:
<xpath>Defs/thingDef[defName="AR_Cape"]/apparel/tags</xpath>

Elwo

You Sir have just made your way into the credits (that is, if I'll ever finish this minimod, but at least now it's possible thanks to you), that's all I can do to express my gratitude. Thank you!

Hjkma

Glad I helped! Good luck with the mod.

Jking911

Broder empecé nuevo en el rim si sabes de algún tutoriaL EN PDF QUE ESTE BUENO PORF DEJA EL LINK QUE ME HACE FALTA SOY CUBANO Y AKÍ LA CONEXION ES ARCAICA