Been playing this game for years but only recently got into modding it, and I just wanted to say that the work you guys have done with this mod is incredible!
I was wondering if there is perhaps a way to set it up so that NPCs can spawn with their faction randomly chosen between a selection of values (without having to make new entities)? I've been using khzmusik's lovely Civilians add-on, and I thought it'd make for interesting situations if the player couldn't immediately tell whether they will be friendly or hostile on approach.
I tried
<property name="Faction" value="whiteriver,bandits" /> , thinking that would work (still very new to all this XML/XPath stuff), but it just made them not spawn and give a null reference error in the console instead.
Each entity can have only one faction, that property does not accept a list.
What you want can be done, but it's not easy. It would involve creating new entity classes for every single NPC you want duplicated (including weapon variations), and then adding those NPCs to spawn in the game.
Let's say you wanted to make unfriendly versions of my "Male Cowboy" civilian NPC. I am going to assume you want them to be of the "bandits" faction (not one of the other unfriendly factions like "whisperers").
The first thing to do is to make bandit versions of the character and weapon type. Example:
<entity_class name="npcBanditMaleCowboyKhzClub" extends="npcMaleCowboyKhzClub">
<property name="Tags" value="entity,male,npc,melee,bandit" />
<property name="Faction" value="bandits" />
</entity_class>
<entity_class name="npcBanditMaleCowboyKhzKnife" extends="npcMaleCowboyKhzKnife">
<property name="Tags" value="entity,male,npc,melee,bandit" />
<property name="Faction" value="bandits" />
</entity_class>
<!-- ...etc. for all weapon types -->
The "Tags" property doesn't extend so you need to specify it, and you need to change the "Faction" property value to whatever faction you want the NPCs to be. I'm pretty sure that's all you need to change to get things working.
The next step is to get them to spawn into the world. In general there are two ways NPCs can spawn:
- In the world, outside of POIs. This is controlled by the biome spawn groups.
- In NPC specific POIs. This isn't widely used yet but will be in the near future when people start making POIs that are dedicated to NPCs.
In both cases, spawning is controlled in the "entitygroups.xml" file.
For
biome spawning, I suggest just copying-and-pasting the XPath that puts the NPCs into the "ZombiesAll", "ZombiesNight", and "SnowZombies" entity groups. You can mess around with other groups later once everything is working, if you want.
For
POI spawning, I suggest copying the XPath that puts the NPCs into the various "npcWhiteriver" and "npcFreindly" groups, except that you should instead put them into the equivalent "npcBandits" and "npcEnemy" groups.
There is a catch: the Civilian NPCs (and in general other folks' friendly NPCs) can be interacted with and hired, and that means they can't be spawned into horde groups (wandering hordes or blood moon hordes). It's possible to modify them so they can be spawned into these groups without throwing errors, but that's more complicated. I can tell you how to do that if you want.
Hope that helps.
FWIW, I do plan to make a "Rogues" pack that has more "normal looking" unfriendly NPCs. They will still be distinct, but perhaps not so obviously "bad" as other NPC bandit packs. (There will also be others that are more obviously "bad" though.) I still have a lot more to do before I get to that - mainly making NPC POIs - but it's on the roadmap.