# Creating Communities

## Usage

* Communities are used to spawn almost all NPCs that aren't crowd NPCs
* As the name suggests, communities can be used to add large amounts of NPCs to the world while retaining a lot of control over:
  * What NPCs to spawn
  * Where those NPCs should be, what workspots they should use
  * What they should do during what time of day

## Requirements

### Tools

* [World Builder](https://github.com/justarandomguyintheinternet/CP77_entSpawner/releases) (v.0.91 or newer)
* [ArchiveXL](https://github.com/psiberx/cp2077-archive-xl)
* [Codeware ](https://github.com/psiberx/cp2077-codeware/releases)(1.15.0 or newer)
* [WolvenKit](https://github.com/WolvenKit/WolvenKit) (With latest version of World Builder import script)

### Knowledge

* You need to have a basic understanding of:
  * Working with WolvenKit
  * Using World Builder (Spawning things and [importing](https://wiki.redmodding.org/cyberpunk-2077-modding/modding-guides/world-editing/object-spawner/exporting-from-object-spawner) into WolvenKit)
  * Know how to place `AISpot`'s, see the [corresponding page](https://wiki.redmodding.org/cyberpunk-2077-modding/modding-guides/world-editing/ai-and-npcs/placing-aispot-nodes)

## General Setup

* Each community can serve a large area
  * How many NPCs and how much of an area you serve with a single community is up to you, but it is generally recommended to have one community per location
* Start by spawning a community, found under `AI -> Community`
  * The community should be placed in the rough area of where the AISpots that you want to use are

{% hint style="warning" %}
Make sure to assign a unique NodeRef to the community (Is the same as the `Community ID`)
{% endhint %}

* In general, a community consists of the following hierarchical data:
  * Entries:
    * Each entry corresponds to one **NPC template**, e.g. Judy or some generic NPC
    * Phases:
      * Phases are **used by quests**, to switch between different setups
      * They are not of interest if you just want to place some NPCs without quests involved
      * Periods:
        * Periods define **how many NPCs** should be placed **where**, per **time period**

{% hint style="info" %}
To delete an entry, phase or period, simply right click its header
{% endhint %}

### Setting up an entry

* Let's start by making our community spawn a NPC, do this by adding a new entry under the `Entries` header

<figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-b039687905176a11ef5296be4cf03059a5808e82%2FnewCommunityEntryExample.png?alt=media" alt="" width="444"><figcaption><p>Example of a community with a single entry</p></figcaption></figure>

* Here you can define a name for the entry, make sure it is unique
* Here you can also define what NPC template should be used
* Initial Phase Name and Active On Start are only of interest for quest modding, so ignore those for now

### Setting up a phase

* For our example, we will only need one phase, named `default`
* As before, use the `+ [Phase]` button to create a new phase for our entry

<figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-3d949430e6cbadcebd014f0fedc86d89266cc8cd%2FcommunityDefaultPhaseExample.png?alt=media" alt="" width="417"><figcaption><p>Example of an entry with a single default phase</p></figcaption></figure>

* Here you can also define what appearances the NPCs of that entry should use
  * Do this by adding more names under the appearances header
  * This is totally optional, and the default will do

### Setting up periods

* This defines how many of the specified NPC should be spawned, where they should be spawned, and **when** they should be spawned
* As before, use the `+ [Period]` button to create a new period for our phase
* For this example, let's create two periods

<figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-9f3b72b34fd682d28eb8395ccf3b6ce0baaded20%2FphaseWithTwoPeriodsExample.png?alt=media" alt="" width="382"><figcaption><p>Example phase with two time periods</p></figcaption></figure>

* Each period has the following options:

  * Hour: This controls when the period is active
    * E.g. If you have two periods, `8:00 PM` and `Day`, then from 8:00 PM until 9:00 AM (That's the start of `Day`), the `8:00 PM` period will be active, from 9:00 AM until 8:00 PM, the `Day`period will be active
  * Is Sequence: Only relevant if the AISpots are not set to be infinite. If checked, the NPCs will cycle through the specified spots in the same order as they are listed
  * Quantity: How many of the specified NPC should be spawned
  * Markings and Spot NodeRefs: This is where you actually define what AISpot's should be used, will be explained in the following section

  <figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-26cf85c89ff8568cfe1799589551f57538acf4e3%2FtimePeriodProperties.png?alt=media" alt="" width="251"><figcaption><p>The properties of a time period</p></figcaption></figure>

## Markings and Spot NodeRef's

### Spot NodeRef's

* This list defines what AISpot's the NPCs from that time period can use
* Make sure that you have enough spots for the amount of NPCs
* Simply add the NodeRefs of the AISpots that you want to be used during this time period

<figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-d2769d2307d0605497506e0fd43d41e4a39ba77f%2FtimePeriodspotRefsExample?alt=media" alt="" width="322"><figcaption><p>Example of making the NPC of the "Day" period use one of the two defined AISpots</p></figcaption></figure>

### Markings

* Markings allow you to simply tell the NPCs "Use any of the AISpots that have this marking"
  * You can think of a marking as a Tag that you assign to AISpots
* This makes it very easy to assign many NPCs to a large amount of AISpots, randomly
* E.g.

  * Assign the marking `test_marking` to all AISpots that you want to be used
  * Add that same `test_marking` name to the list of markings of the period

  <figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-a5e1b0569ddc579db797e87e241ed08cf2ffa19e%2FtimePeriodMarkingExample?alt=media" alt="" width="321"><figcaption><p>Example of making a time period use all AISpots with the marking "test_marking"</p></figcaption></figure>

  <figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-b8b9bff611fa331923588f0786620bd3f83383f7%2FaiSpotMarkingExample.png?alt=media" alt="" width="322"><figcaption><p>Example of marking an AISpot, should be done to a group of multiple spots</p></figcaption></figure>

### Full example with SpotNodeRef's

* This is a full example of having either one or two Judy's spawn in specified spots, depending on the time

<figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-2ed72efcc32d91c45cd8871e4ad860e702004479%2FfullJudyExampleSpotNodeRefs?alt=media" alt=""><figcaption></figcaption></figure>

## Full example using markings

* Using markings is especially worth it for larger amounts of NPCs and spots

<figure><img src="https://1427525421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gzcGtLrr90pVjAWVdTc%2Fuploads%2Fgit-blob-304887f1104ee919584b9892651ba83f3fbf7ec8%2FmarkingsFullExample?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
You can right-click any entry/phase/period, to delete or duplicate it
{% endhint %}

## Randomization

* It is possible to enable random selection of workspots using both direct **NodeRefs** and **Markings**.\
  To do so, set a lower NPC **Quantity** than the total number of available workspot NodeRefs/Markings.
* For example, if an entry has a **Quantity** of `1` but references multiple workspot NodeRefs, one of those workspots will be selected at random each time the sector is loaded.

## Finishing up

* In order for the community to be functional, export your group from World Builder, and import into WKit using the World Builder [import feature](https://wiki.redmodding.org/cyberpunk-2077-modding/modding-guides/world-editing/object-spawner/exporting-from-object-spawner)
