How to spawn more villagers in a village scene? (Bannerlord)

Users who are viewing this thread

KingKastro

Recruit
I have been trying to find out how to spawn more villagers in a village scene, since mine is a little bit larger than a normal village scene. Right now it looks barren since there is only 20 ish villagers and I need probably about 40 to 60 ish.
 
I have this script under another called center_remove_walker_type_from_walkers, I don't remember more but this when modifying the number below (3) more bots appear in the same entry point, maybe someone else can guide you.
Code:
# script_init_town_walkers
  # Input: none
  # Output: none
  ("init_town_walkers",
  [
    (try_begin),
      (eq, "$town_nighttime", 0),
      (try_for_range, ":walker_no", 0, num_town_walkers),
        (store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
        (party_get_slot, ":walker_troop_id", "$current_town", ":troop_slot"),
        (gt, ":walker_troop_id", 0),
        (store_add, ":entry_no", town_walker_entries_start, ":walker_no"),
        (set_visitors,":entry_no", ":walker_troop_id",3), #  more town_walker mas aldeanos
      (try_end),
    (try_end),
  ]),
 
Upvote 0
I would really like to find maybe a work around that would work in the base game. I am trying to make a scene for the village scene competition and cannot modify the base game. If I did this, would it then work for anyone else who has my scene files? Or would they have to do this to their files in order to get the same effect? If any devs see this, can you please make a villager spawn modifier to the mod tools? Unless there is already a way to modify it... if there is please tell.
 
Upvote 0
Does anyone know the algorythm that the scene uses to determine how many npc/villagers spawn? And also if there is a cap on villagers?

At least knowing this I can find out how to maximize the amount of villagers in my scene.

And I still would like to ask the devs if they can impliment a system to put a specific, non-capped, number of npc in your scene.
 
Upvote 0
This answer assumes that you know C# and worked on BL modding

My advice is listening the LocationCharactersAreReadyToSpawn event.
Like this
C#:
  CampaignEvents.LocationCharactersAreReadyToSpawnEvent.AddNonSerializedListener((object) this, new Action<Dictionary<string, int>>(this.LocationCharactersAreReadyToSpawn));
then call something like this inside that function
C#:
// settlement is your current settlement. You can get it from event or simply from player encounter
Location locationWithId = settlement.LocationComplex.GetLocationWithId("village_center");
int count = 10;
locationWithId.AddLocationCharacters(new CreateLocationCharacterDelegate(this.CreateVillageMan), culture, LocationCharacter.CharacterRelations.Neutral, count);

Obviously, you will also need a CreateVillageMan method. It can be something like this
C#:
private LocationCharacter CreateVillageMan(
      CultureObject culture,
      LocationCharacter.CharacterRelations relation)
    {
      Tuple<string, Monster> actionSetAndMonster = CommonTownsfolkCampaignBehavior.GetRandomTownsManActionSetAndMonster();
      return new LocationCharacter(new AgentData((IAgentOriginBase) new SimpleAgentOrigin((BasicCharacterObject) culture.Villager, -1, (Banner) null, new UniqueTroopDescriptor())).Monster(actionSetAndMonster.Item2).Age(MBRandom.RandomInt(Campaign.Current.Models.AgeModel.BecomeTeenagerAge, Campaign.Current.Models.AgeModel.MaxAge)), new LocationCharacter.AddBehaviorsDelegate(SandBoxManager.Instance.AgentBehaviorManager.AddOutdoorWandererBehaviors), (string) null, false, relation, actionSetAndMonster.Item1, true, false, (ItemObject) null, false, false, true);
    }

Simply modify culture.Villager to culture.VillageWoman for spawning woman. Or make a simple random function to spawn randomly.

I didn't test it yet but I'm guessing that it should work fine since the original game code is more or less same
 
Upvote 1
Back
Top Bottom