Node Graph Examples

Example functions built using the Node Graph. Most of these examples are in the context of making a quasi-infection game mode with bots, but the broadstrokes and principles apply universally.

Many more individual examples can be found on the articles for each specific Node, for example Play 3D Audio For Team.

## Spawn Bots

This simple script will add 5 bots into the game.

When **Gameplay Starts (On Gameplay Start)**, the script will **Repeat (For N Iterations)** the following function 5 times: **Wait 1 second (Wait for N Seconds)**, then **Add a Bot (Add Bot)**. The **Wait for N Seconds** node is essential because without it only a single bot or two will join.

> IMPORTANT: Note in the above example how the 'Execute Iteration' property is connected directly to 'Wait for N Seconds' node. In many cases **we can connect circles to diamonds**.
>
>

## Traits

Traits are properties that can be applied to players (Note: Bots are considered players). They are akin to the settihgs that can be set in custom game types, except we can set them here in Forge and preview their effects.

They are comprised of 2 main pieces:

* **Traits**, which define the individual properties
* **Trait Sets**, which turn traits into something that can be applied to players.

**Trait Lists** are an optional component. As seen in the image below, **Declare Trait Set** only supports two traits. If we wish to use more, we need to use a **Trait List**, which gives us 4 slots. We can take this a step further by using **Combine Trait Lists**, letting us put many more Traits into a single Trait Set:

We take the following **Traits**:

* **Prevent Grenade Throwing:** Zombies can't throw grenades.
* **Equipment Pickup:** Zombies can't pickup grenades.
* **Infinite Ammo:** Zombies have infinite ammo in their swords.
* **Movement Speed:** Zombies move slower.
* **Sprint Enabled:** Zombies can't sprint.
* **Weapon Dropping:** Zombies can't drop their swords.
* **Weapon Pickup:** Zombies can't pickup human weapons.
* **Damage Resistance:** Zombies take double damage.

And merge them all into a single **Trait List**. We then make a **Trait Set** named *traitlistZombies*. This **Trait Set** can now be applied to any player at any time using any criteria we wish.

It is important to note that Trait Sets CANNOT be modified after their declaration. This means that you cannot update trait values in real-time, and instead you must apply a new Trait Set entirely.

## Applying Trait Sets

> Remember! Traits **must be defined as a Trait Set** to be applied to players!
>
>

The following example takes our zombie Trait Set and applies it to all bots. It also gives them an energy sword:

This code is triggered **whenever a player spawns (On Player Spawned)**. We then use a **Branch** logical condition to determine what should happen next. If that **player is a bot (Get Is Bot)**, then we **Apply Trait Set** to them, and give them an energy sword **Give Player New Weapon**. If not, then nothing happens. The **Trait List** we are using is the one defined in the previous example.

Again, do note that we are connecting a circle to a diamond between **Branch** and **Apply Trait Set**. This is how we get the code to continue.