Settlement Modding - Research and Development

Users who are viewing this thread

Has anyone managed to change the starting owner/faction of a settlement?
I've tried changing Ortysia:

<Settlement id="town_EW4" name="{=Settlements.Settlement.name.town_EW4}Granada" owner="Faction.clan_aserai_1" posX="304.702" posY="331.418" culture="Culture.empire" prosperity="5600" gate_posX="306.2194" gate_posY="334.3485">

The name change works, however the owner does not. Any ideas?
 
Has anyone managed to change the starting owner/faction of a settlement?
I've tried changing Ortysia:

<Settlement id="town_EW4" name="{=Settlements.Settlement.name.town_EW4}Granada" owner="Faction.clan_aserai_1" posX="304.702" posY="331.418" culture="Culture.empire" prosperity="5600" gate_posX="306.2194" gate_posY="334.3485">

The name change works, however the owner does not. Any ideas?
what you do works if you edit directly in the native sandbox module.
it you want to do it within your own module you need to write a dll for it.
you can look here for example with configuration file https://github.com/cyzada/KingdomTemplate


and this is the call you need to do it you want to write your own

Code:
                                   if (p.Leader.StringId.Equals(kC.kingdomLeaderId))
                                    {
                                        TaleWorlds.CampaignSystem.Actions.ChangeOwnerOfSettlementAction.ApplyByDefault(p.LeaderHero, targetSettlement);
                                    }
 
Last edited:
Are we limited to the 3 types of 'settlement' on the map? City, village, and castle? It would be nice to have a variety of different types, big, small versions on the map, and maybe additional things in a historical mod, like monasteries, abbeys etc.

Settlements are built from two base classes. Data and behavior are mixed in those two classes like a salad.

First, SettlementComponent class in the TaleWorlds.CampaignSystem namespace.

Also, Settlement class in the TaleWorlds.CampaignSystem namespace.

Villages and Fiefs inherit from SettlementComponent; Town inherits from Fief.

I don't believe "Castle" is its own class. It's likely a boolean flag.

Code:
namespace TaleWorlds.CampaignSystem
{
    [SaveableClass(20256)]
    public abstract class SettlementComponent : MBObjectBase
    {
        [SaveableEnum(20653)]
        public enum ProsperityLevel
        {
            Low,
            Mid,
            High,
            NumberOfLevels
        }

        [SaveableEnum(20654)]
        public enum ManagmentType
        {
            Tax,
            Militia,
            Project
        }

        public static int NumberOfWorkshopSpotsAtTown = 9;

        [SaveableField(55)]
        public static int NumberOfWorkshopSpotsAtVillage = 4;

        [SaveableField(56)]
        public bool IsTaken;

        private PartyBase _owner;

        protected const int UnrestMilitiaAddition = 200;

        [SaveableField(58)]
        public Settlement TradeBound;

        [SaveableProperty(50)]
        public int Gold
        {
            get;
            private set;
        }

        public float BackgroundCropPosition
        {
            get;
            protected set;
        }

        public string BackgroundMeshName
        {
            get;
            protected set;
        }

        public string WaitMeshName
        {
            get;
            protected set;
        }

        public string CastleBackgroundMeshName
        {
            get;
            protected set;
        }

        public PartyBase Owner
        {
            get
            {
                return _owner;
            }
            internal set
            {
                if (_owner != value)
                {
                    if (_owner != null)
                    {
                        _owner.ItemRoster.RosterUpdatedEvent -= OnInventoryUpdated;
                    }
                    _owner = value;
                    if (_owner != null)
                    {
                        _owner.ItemRoster.RosterUpdatedEvent += OnInventoryUpdated;
                    }
                }
            }
        }

        public Settlement Settlement => _owner.Settlement;

        public TextObject Name => Owner.Name;

        public virtual bool IsTown => false;

        public virtual bool IsCastle => false;

        public virtual ProsperityLevel GetProsperityLevel()
        {
            return ProsperityLevel.Mid;
        }

        protected abstract void OnInventoryUpdated(ItemRosterElement item, int count);

        public virtual void OnPartyEntered(MobileParty mobileParty)
        {
            mobileParty.Ai.SetAIState(AIState.Undefined);
        }

        public virtual void OnPartyLeft(MobileParty mobileParty)
        {
        }

        public virtual void OnStart()
        {
        }

        public virtual void OnInit()
        {
        }

        public virtual void DecideOwnerFaction()
        {
        }

        public virtual void OnFinishLoadState()
        {
        }

        public virtual float GetNeededWallScoreForNextLevel()
        {
            return 0f;
        }

        public void ChangeGold(int changeAmount)
        {
            Gold += changeAmount;
            if (Gold < 0)
            {
                Gold = 0;
            }
        }

        public virtual int GetMaximumTroopNumber()
        {
            return 0;
        }

        public int GetNumberOfTroops()
        {
            int num = 0;
            foreach (MobileParty party in Owner.Settlement.Parties)
            {
                if (party.IsMilitia || party.IsGarrison)
                {
                    num += party.Party.NumberOfAllMembers;
                }
            }
            return num;
        }

        public override void Deserialize(MBObjectManager objectManager, XmlNode node)
        {
            base.Deserialize(objectManager, node);
        }

        public virtual int GetItemPrice(ItemObject item, MobileParty tradingParty = null, bool isSelling = false)
        {
            return 0;
        }

        public virtual int GetItemPrice(ItemRosterElement itemRosterElement, MobileParty tradingParty = null, bool isSelling = false)
        {
            return 0;
        }

        public virtual string OnGetInfoText()
        {
            return "";
        }

        public virtual bool OnEncountered(PartyBase defenderParty, ref bool isHandled)
        {
            isHandled = false;
            return false;
        }

        public virtual void StartRaid(MobileParty party)
        {
        }

        public virtual bool IsAmbush()
        {
            return false;
        }

        public virtual bool IsHideout()
        {
            return false;
        }

        public virtual bool IsMinorFactionBase()
        {
            return false;
        }

        public virtual bool IsThereManagement(ManagmentType type)
        {
            return false;
        }

        public virtual bool CheckProvacating()
        {
            return false;
        }

        public bool CheckExistingMapEvent()
        {
            foreach (MobileParty party in Owner.Settlement.Parties)
            {
                if (!party.IsMainParty && party.MapEvent != null)
                {
                    return true;
                }
            }
            return false;
        }

        public virtual float GetUnrestProbabilityChange(bool addEffectOfExtraRelationChange)
        {
            return 0f;
        }

        public virtual void OnRelatedPartyRemoved(MobileParty mobileParty)
        {
        }

        public List<CharacterObject> GetPrisonerHeroes()
        {
            List<PartyBase> list = new List<PartyBase>
            {
                Owner
            };
            foreach (MobileParty party in Owner.Settlement.Parties)
            {
                if (party.IsCommonAreaParty || party.IsGarrison)
                {
                    list.Add(party.Party);
                }
            }
            List<CharacterObject> list2 = new List<CharacterObject>();
            foreach (PartyBase item in list)
            {
                for (int i = 0; i < item.PrisonRoster.Count; i++)
                {
                    for (int j = 0; j < item.PrisonRoster.GetElementNumber(i); j++)
                    {
                        CharacterObject character = item.PrisonRoster.GetElementCopyAtIndex(i).Character;
                        if (character.IsHero)
                        {
                            list2.Add(character);
                        }
                    }
                }
            }
            return list2;
        }
    }
}

The Settlement class is too big to post. If I wrote a class more than 48,000 characters long, I think I would need to refactor it.
 
Last edited:
I don't believe "Castle" is its own class. It's likely a boolean flag.

Hello,
from what i have seen yes castle seem to be a Town


i have a small question for the recruitment process :
i tried to play with recruitment, changing what fief give base on type.
It seem to work for the basic but i still see some noble troop in village, maybe it's because they were generate before and so until someone recruit them they stay here?


for people interested in the example :

it's part of UpdateVolunteersOfNotables in RecruitCampaignBehavior from TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors
C#:
if (settlement.IsVillage && !settlement.Village.Bound.Town.IsRebeling)
                        {
                            // village prosperity is base on hearts, convert enum to int for later
                            int prosperity = (int)settlement.Village.GetProsperityLevel();
                            // chance to lvlUp troop for recruitment
                            int lvlUpProbability = notable.Power < 200 ? 5 * prosperity : 25 * prosperity;
                            for (int index = 0; index < 6; ++index)
                            {
                                // prosperity values are 0,1,2 from poor to ok
                                if (prosperity > 0)
                                {
                                    notable.VolunteerTypes[index] = TestOverride.getSettlementRecruit(cultureObject.BasicTroop, maxLvlNormal[index], lvlUpProbability);
                                }
                                else
                                {
                                    notable.VolunteerTypes[index] = TestOverride.getSettlementRecruit(cultureObject.BasicTroop, maxLvlPoor[index], lvlUpProbability);
                                }
                            }
                        }
as you can see i only passe basicTroop for village...

well good day to you all :smile:

Ps: someone have found a way to get bandits culture (i have read people talking about adding bandits troops to gang leader somewhere)? i have found this workaround for now :
Code:
Clan bandits = Clan.BanditFactions.GetRandomElement(); // can't be sure of the type of bandits with that, i would need to extract them when starting campaign so that i can easily get looter/seaRaiders/etc... troops
CultureObject banditCulture = bandits.Culture;
// banditCulture.BasicTroop <<< no eliteTroop for them
Clan.BanditFactions give a list of all groups of bandits you can see in game and so you can get their culture, i can give bandits troops to notable with that, for marchant it's easier, all culture have a CaravanMaster or CaravanGuard for the unit :smile:
 
Last edited:
Customized XML's copied from SandBox in custom module loading before SandBox (and after SandBoxCore):

heroes - override failed
lords - override failed
settlements - override success
spclans - override success
spkingdoms - override success

Overwriting the lords.xml and heroes.xml by replacing them in SandBox works fine. Anyone know why? Is it the same reason we can't edit the banner images found in the GUI folders?
 
Tonight's testing.

By applying a custom culture to a village it didn't crash, only a town. I've noticed there are no notable villagers at that village. I'm not completely sure where noteable villagers are defined (are they in specialnpcs?) or why they aren't spawning. Going to continue down this path of experimentation tomorrow. I believe the reason Towns are crashing is possibly because they are reliant on those notables possibly existing.

Update: Confirming. Missing Special Character Notables (Outlaws, etc.) from your custom culture WILL CRASH TOWNS. You need to define the various hooligans to populate towns or else it won't function.

I am currently stuck on this atm, can't figure out how to define them.
would you care to share some more insight ?
 
Here is a list of all notables that needs to have their culture set to the new culture when editing towns to new cultures to avoid getting crash on campaign startup. Hope this can help moving forward as there is more to figure out.

Code:
<?xml version="1.0" encoding="utf-8"?>
<NPCCharacters>
  <!-- URBAN CHARACTERS OF STURGIA -->
  <NPCCharacter id="spc_notable_danheim_0" name="{=IaMyN5yr}Cautious Sturgian merchant" voice="ironic" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_0" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <Trait id="Valor" value="-1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_1_t2" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.nordic_tunic" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_0b" name="{=jQt9cLzS}Caustic sturgian merchant" voice="ironic" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_0b" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <Trait id="Commander" value="1" />
      <Trait id="Honor" value="-1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_axe_2_t2" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_1" name="{=tvNIMvN5}curt sturgian merchant" voice="curt" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_1" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <Trait id="Valor" value="-1" />
      <Trait id="Generosity" value="-1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_1_t2" />
      <equipment slot="Body" id="Item.northern_tunic" />
      <equipment slot="Leg" id="Item.battania_fur_boots" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_2" name="{=0YgGQzbw}Adventurous sturgian merchant" voice="earnest" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_2" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <!-- TEMPLATE INFO -->
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <!-- CHARACTER -->
      <Trait id="Valor" value="1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Body" id="Item.northern_tunic" />
      <equipment slot="Leg" id="Item.battania_fur_boots" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_2b" name="{=XPwQab9R}Honest Sturgian merchant" voice="curt" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_2b" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <Trait id="Commander" value="3" />
      <Trait id="Honor" value="1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Body" id="Item.northern_tunic" />
      <equipment slot="Leg" id="Item.battania_fur_boots" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_3b" name="{=9BbsD1MH}Affable sturgian merchant" voice="earnest" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_3b" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <Trait id="Commander" value="1" />
      <Trait id="Generosity" value="1" />
      <Trait id="Calculating" value="-1" />
    </Traits>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Body" id="Item.northern_tunic" />
      <equipment slot="Leg" id="Item.battania_fur_boots" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_3" name="{=lbIgOHea}Honorable female sturgian merchant" voice="earnest" is_template="true" is_female="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.townswoman_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_3" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="Honor" value="1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Body" id="Item.northern_tunic" />
      <equipment slot="Leg" id="Item.battania_fur_boots" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_3c" name="{=TuBXZ80e}Devious female sturgian merchant" voice="ironic" is_template="true" is_female="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Merchant">
    <face>
      <face_key_template value="NPCCharacter.townswoman_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_3c" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="RusHair" value="1" />
      <!-- Add skill groups -->
      <Trait id="Commander" value="1" />
      <Trait id="Honor" value="-1" />
      <Trait id="Calculating" value="1" />
    </Traits>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Body" id="Item.northern_tunic" />
      <equipment slot="Leg" id="Item.battania_fur_boots" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_4" name="{=pbcUnQS9}Sturgian seer" voice="curt" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Preacher">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_4" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="Honor" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.nordic_tunic" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_5" name="{=ldArPXQE}Sturgian female mystic" voice="softspoken" is_template="true" default_group="Infantry" is_female="true" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Preacher">
    <face>
      <face_key_template value="NPCCharacter.townswoman_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_5" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="Honor" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.nordic_tunic" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_6" name="{=K27WpkiE}Sturgian gang leader" voice="ironic" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="GangLeader">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_6" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="Valor" value="1" />
      <Trait id="Mercy" value="-1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.nordic_tunic" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.wrapped_axe" />-->
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.wrapped_axe" />-->
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.tundra_tunic" />
      <equipment slot="Leg" id="Item.wrapped_shoes" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.battania_leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_7" name="{=ucL7DjaP}Sturgian female gang leader" voice="ironic" is_template="true" default_group="Infantry" is_female="true" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="GangLeader">
    <face>
      <face_key_template value="NPCCharacter.townswoman_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_7" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="Valor" value="1" />
      <Trait id="Mercy" value="-1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.nordic_tunic" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.wrapped_axe" />-->
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.wrapped_axe" />-->
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.tundra_tunic" />
      <equipment slot="Leg" id="Item.wrapped_shoes" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.battania_leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_8" name="{=RJ3WezQ9}Sturgian artisan" voice="curt" is_template="true" default_group="Infantry" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Artisan">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_8" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="Generosity" value="1" />
    </Traits>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.nordic_ancestral_sword" />-->
      <equipment slot="Item0" id="Item.sturgia_sword_4_t4" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.nordic_tunic" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.wrapped_axe" />-->
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.leather_boots" />
    </equipmentSet>
    <equipmentSet>
      <!--<equipment slot="Item0" id="Item.wrapped_axe" />-->
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Head" id="Item.nordic_leather_cap" />
      <equipment slot="Body" id="Item.tundra_tunic" />
      <equipment slot="Leg" id="Item.wrapped_shoes" />
      <equipment slot="Cape" id="Item.scarf" />
    </equipmentSet>
    <equipmentSet>
      <equipment slot="Item0" id="Item.sturgia_axe_3_t3" />
      <equipment slot="Body" id="Item.northern_padded_gambeson" />
      <equipment slot="Leg" id="Item.battania_leather_boots" />
    </equipmentSet>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_9" name="{=5nthUXyw}Sturgian land captain gruff notable" voice="curt" is_template="true" default_group="Infantry" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="RuralNotable">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_9" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="WandererEquipment" value="1" />
      <Trait id="RusHair" value="1" />
      <Trait id="Generosity" value="-1" />
    </Traits>
  </NPCCharacter>
  <NPCCharacter id="spc_notable_danheim_10" name="{=PGHtN3Jx}Sturgian land captain helpful notable" voice="softspoken" is_template="true" default_group="Infantry" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="RuralNotable">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_10" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="WandererEquipment" value="1" />
      <Trait id="RusHair" value="1" />
      <Trait id="Calculating" value="1" />
      <Trait id="Generosity" value="1" />
    </Traits>
  </NPCCharacter>
  <NPCCharacter id="spc_sturgia_outlaw_1" name="{=HXqZbme3}Sturgia bold outlaw" voice="ironic" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Outlaw">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_sturgia_outlaw_1" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="WandererEquipment" value="1" />
      <Trait id="Valor" value="1" />
      <Trait id="Honor" value="-1" />
      <Trait id="Generosity" value="1" />
    </Traits>
  </NPCCharacter>
  <NPCCharacter id="spc_danheim_outlaw_2" name="{=aDby4Ikv}Sturgia menacing outlaw" voice="softspoken" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Outlaw">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_danheim_outlaw_2" faction="Kingdom.sturgia" />-->
    <Traits>
      <Trait id="WandererEquipment" value="1" />
      <Trait id="RusHair" value="1" />
      <Trait id="Mercy" value="-1" />
      <Trait id="Calculating" value="1" />
    </Traits>
  </NPCCharacter>
  <NPCCharacter id="spc_danheim_headman_1" name="{=bVBu4bRa}sturgia rebellious headman" voice="earnest" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Headman">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_4" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="BalancedFightingSkills" value="5" />
      <Trait id="Valor" value="1" />
      <Trait id="Calculating" value="-1" />
    </Traits>
  </NPCCharacter>
  <NPCCharacter id="spc_danheim_headman_2" name="{=K42QfOpv}sturgia conservative headman" voice="curt" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Headman">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_4" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="BalancedFightingSkills" value="4" />
      <Trait id="RusHair" value="1" />
      <Trait id="Valor" value="-1" />
      <Trait id="Generosity" value="1" />
    </Traits>
  </NPCCharacter>
  <NPCCharacter id="spc_danheim_headman_3" name="{=2g1DUtuy}sturgia devious headman" voice="ironic" is_template="true" default_group="Infantry" is_hero="false" culture="Culture.doc_danheim" battleTemplate="NPCCharacter.npc_armed_wanderer_equipment_template_sturgia" civilianTemplate="NPCCharacter.npc_wanderer_equipment_template_sturgia" occupation="Headman">
    <face>
      <face_key_template value="NPCCharacter.villager_sturgia" />
    </face>
    <!--<Hero id="spc_notable_danheim_4" faction="Kingdom.sturgia" />-->
    <skills></skills>
    <Traits>
      <Trait id="RusHair" value="1" />
      <Trait id="BalancedFightingSkills" value="3" />
      <Trait id="Calculating" value="1" />
      <Trait id="Honor" value="-1" />
    </Traits>
  </NPCCharacter>
</NPCCharacters>

so that fixes crash on campaign startup when adding towns with new cultures.
But still getting crash when entering settlement scenes belonging to new cultures.

at TaleWorlds.CampaignSystem.SimpleAgentOrigin.get_Party() at TaleWorlds.CampaignSystem.SimpleAgentOrigin.get_Seed() at TaleWorlds.Core.AgentData..ctor(IAgentOriginBase agentOrigin) at TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors.Towns.TownMerchantsCampaignBehavior.CreateMerchant(CultureObject culture, CharacterRelations relation) at TaleWorlds.CampaignSystem.Location.AddLocationCharacters(CreateLocationCharacterDelegate createDelegate, CultureObject culture, CharacterRelations relation, Int32 count) at TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors.Towns.TownMerchantsCampaignBehavior.AddTradersToCenter(Dictionary`2 unusedUsablePointCount) at TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors.Towns.TownMerchantsCampaignBehavior.LocationCharactersAreReadyToSpawn(Dictionary`2 unusedUsablePointCount) at TaleWorlds.CampaignSystem.MbEvent`1.InvokeList(EventHandlerRec`1 list, T t) at TaleWorlds.CampaignSystem.CampaignEvents.LocationCharactersAreReadyToSpawn(Dictionary`2 unusedUsablePointCount) at TaleWorlds.CampaignSystem.CampaignEventDispatcher.LocationCharactersAreReadyToSpawn(Dictionary`2 unusedUsablePointCount) at SandBox.MissionAgentHandler.SpawnLocationCharacters(String overridenTagValue, Boolean hasTorch) at SandBox.Source.Missions.TownCenterMissionController.AfterStart() at TaleWorlds.MountAndBlade.Mission.AfterStart() at TaleWorlds.MountAndBlade.MissionState.FinishMissionLoading() at TaleWorlds.MountAndBlade.MissionState.OnTick(Single realDt) at TaleWorlds.Core.GameStateManager.OnTick(Single dt) at TaleWorlds.Core.Game.OnTick(Single dt) at TaleWorlds.Core.GameManagerBase.OnTick(Single dt) at DMD?45081919::OnApplicationTick_Patch2>(Module this, Single dt)

what I can tell from that is that we also need to set CharacterRelations (?)
and CampaignSystem.SandBox.CampaignBehaviors for new cultures needs to be set.

No idea how to do that atm...
 
I have a somewhat related problem/question that i posted in the mod Q&A
I'm trying to make a very "simple" mod which colors the Nameplates(specifically SettlementNameplates) to a color for each faction, unlike originally where the color is selected based on the current relation with the player(Neutral, Ally, Enemy). My understanding is that the color is set by selecting a style for the brush of the widget via Widget.SetState(string) using a string corresponding to a brush-style in the Nameplates.xml("NeutralTown" etc).

My line of thinking have been to add styles to the brushes in Nameplate.xml("aseraiTown" etc) then changing SetNameplateRelationType(int type) to call SetSate not with a string based on the relation but rather the faction name. To do this I need to figure out what faction the current Nameplates settlement belongs to. The Widget have no direct access to the settlement its representing but it has the name of it stored in SettlementNameplateWidget.(Big, Normal, Small)NameplateWidget.SettlementNameWidget.Text.

So finding a Settlement from its name now becomes the next task. The Settlement.Find(string) dont seem to work with the name, as it is using the idString which I think is semi randomly generated(no real clue tho?). So to get around this I have tried to make a Dictionary that uses the name as the key and a Settlement/idString, building it by iterating over Campaign.Currnet.Settlements during the loading of a campaign(tried DoLoading, OnGameLoaded, OnGameInitializationFinished) but as soon as I try to access Settlement.StringId or adding the Settlement to the dictionary the game crashes with no error messages.

Clearly I am doing something wrong, but I don't understand what. Very possible that there is a easier/more correct way of doing it but I'm very new to modding games so I'm not really used to the flow of execution/listener structur/interface system(Gauntlet) that bannerlord has. Any help is much appreciated

This is the code in question that for a reason I dont understand gives the game some sort of panic.

C#:
        public override bool DoLoading(Game game) {
            base.DoLoading(game);    //load everything is my hope so i can operate on parts of the Campaign maybe?
            try
            {
                if(Campaign.Current != null && Campaign.Current.Settlements != null) {
                    foreach (Settlement s in Campaign.Current.Settlements)
                    {
                        if (s != null && !s.IsHideout())
                        {
                            //string id = s.StringId;     //ref to the settlement via idstring, also crashes
                            string name = s.ToString();
                            SettlementRef.NamesToSettlement.Add(name, s);
                        }                         
                    }
                }
            } catch (Exception ex)    //this exception has never triggerd, straight CTD with messagebox askin to collect logs
            {
                MessageBox.Show($"Failed to to build Dictionary of settlements:\n{ex.Message}\n{ex.InnerException.Message}");
            }
            return true;
        }
 
Done! Was able to successfully add multiple branches of which you can recruit from notables in town, below is what I've done.

First add a new notable and troop to TaleWorlds.CampaignSysytem.Helpers.HeroHelper
C#:
        public static bool HeroShouldGiveGangleaderBodyguard(Hero sellerHero)
        {
            return sellerHero.IsGangLeader && sellerHero.Power >= 2;
        }
    }
}

Second is add this to TaleWorlds.CampaignSysytem.SandBox.CampaignBehaviours.RecruitCampaignBehaviour
C#:
        // Token: 0x060024B8 RID: 9400
        private static void UpdateVolunteersOfNotables(bool initialRunning = false)
        {
            foreach (Settlement settlement in Campaign.Current.Settlements)
            {
                if ((settlement.IsTown && !settlement.Town.IsRebeling) || (settlement.IsVillage && !settlement.Village.Bound.Town.IsRebeling))
                {
                    foreach (Hero hero in settlement.Notables)
                    {
                        if (hero.CanHaveRecruits)
                        {
                            bool flag = false;
                            CultureObject cultureObject = (hero.CurrentSettlement != null) ? hero.CurrentSettlement.Culture : hero.Clan.Culture;
                            CharacterObject basicTroop = cultureObject.BasicTroop;
                            double num = (hero.IsRuralNotable && hero.Power >= 200) ? 1.0 : 0.5;
                            float num2 = 200f;
                            for (int i = 0; i < 6; i++)
                            {
                                if (MBRandom.RandomFloat < Campaign.Current.Models.VolunteerProductionModel.GetDailyVolunteerProductionProbability(hero, i, settlement))
                                {
                                    if (!RecruitCampaignBehavior.IsBitSet(hero, i))
                                    {
                                        hero.VolunteerTypes[i] = basicTroop;
                                        flag = true;
                                    }
                                    else
                                    {
                                        float num3 = num2 * num2 / (Math.Max(50f, (float)hero.Power) * Math.Max(50f, (float)hero.Power));
                                        int level = hero.VolunteerTypes[i].Level;
                                        if (MBRandom.RandomInt((int)Math.Max(2.0, (double)((float)level * num3) * num * 1.5)) == 0 && hero.VolunteerTypes[i].UpgradeTargets != null && hero.VolunteerTypes[i].Level < 20)
                                        {
                                            if (hero.VolunteerTypes[i] == basicTroop && HeroHelper.HeroShouldGiveEliteTroop(hero))
                                            {
                                                hero.VolunteerTypes[i] = cultureObject.EliteBasicTroop;
                                            }
                                            if (hero.VolunteerTypes[i] == basicTroop && HeroHelper.HeroShouldGiveGangleaderBodyguard(hero))
                                            {
                                                hero.VolunteerTypes[i] = cultureObject.GangleaderBodyguard;
                                                flag = true;
                                            }
                                            else
                                            {
                                                hero.VolunteerTypes[i] = hero.VolunteerTypes[i].UpgradeTargets[MBRandom.RandomInt(hero.VolunteerTypes[i].UpgradeTargets.Length)];
                                                flag = true;
                                            }
                                        }
                                    }
                                }
                            }
                            if (flag)
                            {
                                for (int j = 0; j < 6; j++)
                                {
                                    for (int k = 0; k < 6; k++)
                                    {
                                        if (hero.VolunteerTypes[k] != null)
                                        {
                                            int l = k + 1;
                                            while (l < 6)
                                            {
                                                if (hero.VolunteerTypes[l] != null)
                                                {
                                                    if ((float)hero.VolunteerTypes[k].Level + (hero.VolunteerTypes[k].IsMounted ? 0.5f : 0f) > (float)hero.VolunteerTypes[l].Level + (hero.VolunteerTypes[l].IsMounted ? 0.5f : 0f))
                                                    {
                                                        CharacterObject characterObject = hero.VolunteerTypes[k];
                                                        hero.VolunteerTypes[k] = hero.VolunteerTypes[l];
                                                        hero.VolunteerTypes[l] = characterObject;
                                                        break;
                                                    }
                                                    break;
                                                }
                                                else
                                                {
                                                    l++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

With this all you need to do is change gangleader_bodyguard in spcultures.xml to whatever bandit flavor. Vlandia>Mountain bandit/ Aserai>Desert bandit and so on. Only problem I had was the vanilla code in TaleWorlds.CampaignSysytem.CultureObject contained errors and cannot compile, so I repurposed gangleader_bodyguard.

Sorry for necroing. Is this still possible? TW seems to have moved it in that case, path "TaleWorlds.CampaignSysytem.Helpers.HeroHelper" seems to not exist :S
 
Sorry for necroing. Is this still possible? TW seems to have moved it in that case, path "TaleWorlds.CampaignSysytem.Helpers.HeroHelper" seems to not exist :S

It still does, but it is not under TaleWorlds.CampaignSystem if you are using the project template made for VS, it is under Helpers (using Helpers; )

I've been using the Perk and Skill helpers to apply modifiers to a settlement based on owner if there is no governor. Seems like a waste to have all those perks and not be able to use them as a player.
 
Can anybody explain to me how can I change base Town OnPartyEntered method? In the beggining I want to do basic stuff like if entering party have same clan or kingdom as town, then start a tournament or whatever.
 
Back
Top Bottom