The VillagerLife prefab is an entity that can be placed in a scenario to spawn a group of villagers and control their behavior.
When the mission starts, the villagers will be spawned and sent to work, performing a variety of tasks that can include both gathering resources or wandering randomly. Throughout the mission, villagers who become idle will be given a "wander" instruction by the VillagerLife prefab so they appear to be busy.
Using this prefab, villagers can also be configured to react to the player's approach by attacking or fleeing, as desired.
Creating a VillagerLife Prefab
To add a VillagerLife prefab to your custom scenario, perform the following steps:
- In the Scenario Tree, Right-Click on Prefabs and select +Add.
- Using the interface provided, name your new prefab and press OK.
- Right-Click your new prefab and select +Add.
- Select VillagerLife from the blueprint options and press OK.
- Select the prefab in the Scenario Tree, this will open its Property Panel.
- In the Property Panel, use the Villager Response drop-down to set the type of behavior you wish to tie to the selected VillagerLife entity. Options include: Attack, Flee, and None.
(These options are described in detail in the section below)
- Depending on which Villager Response option you chose, your prefab will change to have a set number of Markers, which allow you to control the behavior of the villagers tied to the node. These markers are covered in the section below. Regardless of which type of entity you chose, they will all have a Proximity Circle Component which controls the size of the VillagerLife detection radius. Select this component
Select this component and use the Properties penal to set the Radius you wish the VillagerLife prefab to use.
- Your VillagerLife mkr_home marker will now show a radius around it, indicating the detection radius of your chosen effect.
- The VillagerLife prefab is now ready to be used. Refer to the section below on how to manipulate the behavior of the different types of VillagerLife entities.
Depending which VillagerLife type you chose using the Villager Response field, the VillagerLife entity will have a number of unique markers that allow you to control the villager behavior tied to them.
- Attack causes villagers to attack the player then return to work once the threat either leaves or has been eliminated.
- Flee causes villagers to flee from the player towards a pre-set destination.
- None causes villagers to not respond at all to the player.
The Attack entity causes villagers to attack a player if they enter a set area.
This entity has only has a single marker, mkr_home, indicated by a Purple circle. This location sets the center of the aggro area of the villagers, and if the player enters this radius, the villagers will attack them.
The Flee entity causes villagers to flee towards a pre-set location if a player enters a set area. Once reaching this area, villagers will despawn. After fleeing, despawned villagers are permanently removed from the map
The Flee entity contains three markers, indicated by Purple, Yellow, and Blue circles.
- The mkr_home marker, indicated by the Purple circle, sets the area that will cause the villagers will flee if the player enters it.
- The mkr_flee marker, indicated by the Yellow circle sets the location to where the villagers will flee to and despawn at.
- The mkr_flee_backup marker, indicated by the Blue circle, only appears if Require Garrison is checked in the Properties panel. Villagers will only flee to the mkr_flee marker if there is a garrisonable building nearby, otherwise they will run to mkr_flee_backup.
The None entity causes villagers to go about their set tasks and not react to the player at all.
This entity has only has a single marker, mkr_home, indicated by a Purple circle. This location simply indicates where the villagers will spawn and perform their work.
Unique VillagerLife Properties
There are a number of unique properties that can be changed to configure a VillagerLife prefab, detailed below.
Owned by Player sets the owner of the villagers spawned by the prefab. You can set this to World to cause the villagers to be not owned by any specific player.
The numerical settings control the number of villagers that will be set to perform actions within the prefab. Any value set to "0" will result in no villagers performing that task.
- Villagers Roaming sets the number of villagers roaming around randomly within the area.
- Villagers on Wood sets the number of villagers chopping wood within the area.
- Villagers on Farms sets the number of tending farms within the area.
- Villagers on Stone sets the number of villagers mining stone within the area.
- Villagers on Gold sets the number of villagers mining gold within the area.
Interacting with VillagerLife at Runtime
There are a number of key ways VillagerLife prefabs can be interacted with using Runtime, detailed below.
Creating VillagerLife Instance
You can create a VillagerLife instance at runtime with this function.
- Enter: (player, name, sg_roaming, sg_wood, sg_food, sg_stone, sg_gold, villager_response, mkr_home, mkr_flee, b_require_garrison, mkr_flee_backup)
- Creating a VillagerLife in this way does not handle spawning villagers. You must pass existing villagers into this function in one of the 5 sgroup parameters (sg_roaming, sg_wood, sg_food, sg_stone, sg_gold)
- If you only want villagers to perform one of these 5 possible jobs, leave the other 4 as nil values.
Accessing VillagerLife Instance
You can access a VillagerLife instance in two ways:
- local myVillagerLife = VillagerLife_Create(...) OR
- local myVillagerLife = VillagerLife_Find(name)
Adding Villagers to Existing VillagerLife Instance
You can add villagers to an existing VillagerLife with this function.
- Enter: (instance, sgroup, job)
- "job" should be one of the following strings, "roaming", "wood", "food", "stone", or "gold". Leaving it as nil is equivalent to "roaming".