Help question - Factions and Guns

Started by silentlord, October 09, 2017, 05:53:20 PM

Previous topic - Next topic

silentlord

Hello.

Dunno if this is the right section to ask, but it is to do with mods.
i wanted to know if it is possible to stop a custom faction using guns? i am playing a heavily modded game thats all geared to tribal or medieval. all the vanilla factions no longer use guns. however i have come across afew very nice custom factions on steam and i added one. however whenever they spawn as either raiders or caravans, they all have machineguns or chargelances. as you can imagine if its a raid then i quickly get pawned.

other than just removing the faction mods, which i don't really wanna do, is there a way to stop them spawn/using guns? i just want them to use melee or crossbows and longbows etc...

Albion

#1
Hey, it's not trivial but actually not that hard to do.
First: are you using the steam workshop or did you download the mods themselves and copied them into the rimworld mod folder?
If you have them from the workshop you'll have to copy all the mods from the workshop (default location: C:\Program Files (x86)\Steam\steamapps\workshop\content\294100 ) to the Rimworld mod folder (default location: C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods ). After doing so you'll need to activate the hardcopies in the main menu and deactivate the steam workshop versions.
The reason for doing this is that you'll have to mod your mods and if a new version of those mods is released they would override your changes.

Now what you need to do is ask yourself if you want to remove all guns from the game or just have the enemies not spawn with any anymore.

Option 1: Go into every mod and delete all .xml files that contain guns.If the mods are done properly you'll find the right ones by name. If it doesn't exist it can't be spawned (and might throw errors). For the vanilla game you'll find the corresponding file under: ...\Mods\Core\Defs\ThingDefs_Misc\Weapons_Guns.xml
It's dirty and I wouldn't recommend it but it should work.

(Better) Option 2: Change the way the Pawns of that faction are spawned. The following examples are for the Core of the game. Your mods will have different naming conventiens.
The way raids are generated is for the game to check the factionDef under ...\Mods\Core\Defs\FactionDefs if you open for example the Factions_Misc.xml file you'll see the definitions for the outlader, tribe and pirate faction of the vanilla game. If you scroll down you'll see under <pawnGroupMakers> what kind of pawns are actually spawnable by this faction.
Now that you know what pawns are spawnable you need to edit the pawns that get spawned. You'll find those under ...\Mods\Core\Defs\PawnKindDefs_Humanlikes
Here you can find the different .xml files defining the different pawns spawnable by the factions (again: naming of folders and files might differ depending on mod). If you scroll down you'll find for most, if not all different PawnKindDefs that they have a entry similar to this one:

<weaponTags>
     <li>Gun</li>
</weaponTags>

This weaponTag defines the different weapons this pawn can randomly have equipped when spawned. Changing this will change the weapons they spawn with. Checkout the different weaponTags of the different weapons by looking at their xml files (as mentioned above are found for the vanilla game under ...\Mods\Core\Defs\ThingDefs_Misc ). What you are probably looking for is mosly the tag <li>Melee</li> for melee weapons and the tag <li>Neolithic</li> for tribal weapons like bows.
Weapons introduced by your mods might have different tags, so check those out.
Soooo.... long story short: Overwrite the current weaponTags found in the PawnKindDefs with the weaponTags you want those pawns to use... from not on they will spawn with those.

Bonus points:
If you want to feel like an awesome modder and want to make a patch for those faction so you can still receive updates you can do the following:
Instead of copying your mods and changing the different weaponTags by hand you can create a patch.
To do this create a new folder in the ....Rimworld\Mods folder and name it silentlordsAwesomePatch (or whatever). Then create a "About" folder, maybe containing a About.xml file (check other mods how they did it and edit it to your needs).
More importantly: create a "Patch" folder and inside create a new .xml named something like "Patch_changeWeaponTags_AwesomePatch.xml".
The content of that file should look something like this:
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/PawnKindDef[defName = "WhateverTheDefNameIs"]/weaponTags</xpath>
<value>
<weaponTags>
<li>Neolithic</li>
</weaponTags>
</value>

</Operation>
</Patch>

The code example above replaces the weaponTags of the PawnKindDef with the defName of WhateverTheDefNameIs with the weaponTags you might want.
What you'll need to do is just copy everything from (and including) <Operation...> to </Operation> multiple times, each time replacing the defName of the PawnKindDef you want to patch.
For a better guide on patching please refer to this guide (link).... or bride someone to do it  ;) ;D

Edit: What I forgot to mention is that if you do the Patch you can keep the mods you currently have installed where ever they are and won't have to worry about updates since your patch is seperate and therefore resistant to any updates of the mod you're patching.
However what you definitly need to do is the following: In the mod menu of the Rimworld main menu you have the list of all the mods you're running. You HAVE to move down your own mod to the bottom of that list because it HAS to be the last one loaded so it can acutally patch the mods you're trying to patch. If it's loaded earlier there will be an error because it tries to patch something that simply isn't there yet because it wasn't loaded yet.

Enjoy your modding and I'll be happy to answer any further questions.

silentlord

Hi Albion

Wow thanks alot, lots to do now. the majority of the mods/factions are Steamworkshop.
I had a feeling the weapontags was linked, i looked through the custom faction and compared to.. for example the Medieval factions. i was thinking of removing tags and lowering budgets, but wasn't sure if this was correct or just cause errors.... and i hate hunting for errors.

I very much like the patching idea, its longer term and better i reckon, than just hacking apart the xmls and then possible a day or hours later a patch via steam wipes it all out.

i think its time to do some reading of patching and hours no doubt of typing really small text on a really big screen.... *sigh* lol

Thank you very much for the help and pointing me in a direction... my poor tribal cats will no longer be mowed down from across the map by filthy guns and those unholy chargelances.

Albion

If you have some background in programming it should be easy enough.
When I came into modding about 2 months ago I mosly looked through other mods at first and tried to figure out what they did and how. It's the best and easiest way in my experience. Bonus points if you read a guide or two ;)

By the way I wouldn't necessarily lower the budget. Long bows are quite expensive too, especially with better quality.

And as already mentioned: if you run into any problems just post and ask.

silentlord

no programming background, but like you i have been in and around the various mods xmls for awhile, usually toning down OP added guns and ranges etc....
i have a form of ADHD (ADD) makes it difficult to focus and stick to the task at hand, and generally takes far longer to do stuff.... but hey it eventually sticks and committed to memory.

i have been reading the guide you linked, and the guides it links too.
but i still have a question im unsure of....

just been looking at the pawnkinddef of one of the new factions, it has listed 3 weapontags... do i then make 3 separate patches? or lump them into a single patch code?

This is the single i have put together:
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/PawnKindDef[@Name="FrijjidCivBase"]/weaponTags//li[1]/</xpath>
<value>
<weaponTags>
<li>MedTimes_Weapon_Soldier</li>
</weaponTags>
</value>

</Operation>
</Patch>


And this is the multiple one, i have not seen anywhere that shows or explains multiples, which leaves me to think i have to make loads of singles, as the code looks messy:
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/PawnKindDef[@Name="FrijjidCivBase"]/weaponTags//li[1]/PawnKindDef[@Name="FrijjidCivBase"]/weaponTags//li[2]//PawnKindDef[@Name="FrijjidCivBase"]/weaponTags//li[3]/</xpath>
<value>
<weaponTags>
<li>MedTimes_Weapon_Soldier</li>
</weaponTags>
</value>

</Operation>
</Patch>


other than this issue i have pretty much got the hang of it, just lots of text to look through to find the xpath's

Albion

No, those are not correct unfortunately.
With xpath you have to find the general value you want to replace. The easiest way is to completly rip out the entire weaponTags and replace it with a new weaponTags with the desired values (like you're already doing). If you look at everything "inside" <value></value> you'll see that you're already replacing <weaponTags> with a new version of <weaponTags>.
So the xpath should stop at weaponTags since that is the one you want to replace. Subparameters will be removed and replaced as well so you don't need to worry if there are multiple entries in the list.

In both cases all you need to have is this: <xpath>*/PawnKindDef[@Name="FrijjidCivBase"]/weaponTags</xpath>
At least if you do it with:
<value>
<weaponTags>
<li>MedTimes_Weapon_Soldier</li>
</weaponTags>
</value>


The entire code should therefore look like this:
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/PawnKindDef[@Name="FrijjidCivBase"]/weaponTags</xpath>
<value>
<weaponTags>
<li>MedTimes_Weapon_Soldier</li>
</weaponTags>
</value>

</Operation>
</Patch>

silentlord

ah... i understand now. if weapontag was a folder and the various weapon types are files. the xpath patch simply just replaces the new weapontag folder of my choosing and everything in it.

been reading the guides over and over between breaks for it to set in. this patching is ingenious and saves a boat load of time for either making mods compatible and or changing adding stuff without a complete rewrite.
im growing more confident now.   

You sir, get an extra large thank you cookie! :P

CannibarRechter

Yes, just be careful with the PatchOperationSequence directive. It's... I'll say it's not fully baked yet. Stick to Add, Replace, Remove, Insert and all will be well. You might also use AttributeAdd, Set, Remove, but this is more rare.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Albion

Yeah I too stick to Add, Replace and Insert.

And the comparison to folders is actually quite accurate. Should have used that in my explanation.
Enjoying my cookie 8)