Random Choice

From Runic Games Wiki
Jump to: navigation, search

Contents

Overview

This tutorial will cover the basics of how to create a script to randomly select one of two Unit Spawners every time the Player enters a specific area and then spawn a Monster. It will assume you already have a fundamental understanding of how to navigate and use the GUTS editor along with being familiar with Basic Scripting.

Step-by-Step

Completed "Random Choice" Level Set Up
Completed "Random Choice" Script

Initial Set Up

  • Create/Load a level with a pathable area for the Player to walk and Monster Objects to spawn.
  • Turn Show Helpers on ( Ctrl + H ) to make the logic objects that will be created visible in the editor.

Add Necessary Objects

Right-click on an empty space in the Layout Scene Manager and add the following objects:

Move Objects

Change Properties

Select the first Unit Spawner and change the following properties in the Properties Window:

  • "Spawn on Create" to False.
    This sets the Unit Spawner to only spawn when it receives a "Spawn Units" Input event instead of automatically on level load.
  • "Resource" to "Skeleton".
    This determines the type of Monster to spawn.
  • "Count" to 1.
    This is the total number of Monsters to spawn.

Select the second Unit Spawner and change the following properties in the Properties Window:

  • "Spawn on Create" to False.
    This sets the Unit Spawner to only spawn when it receives a "Spawn Units" Input event instead of automatically on level load.
  • "Resource" to "Zombie".
    This determines the type of Monster to spawn.
  • "Count" to 1.
    This is the total number of Monsters to spawn.

Select the Player Sphere Trigger and change the following properties in the Properties Window:

  • "Radius" to 4.
    This sets the size of the Player Sphere Trigger. The Player must enter this sphere to trigger it.

Select the Random Choice Object and change the following properties in the Properties Window:

  • "One" and "Two" to 1.
    This creates two choices for the Random Choice Object to pick between and gives them both an equal weight of 1

Edit Logic Group

Select the Logic Group, open the Logic Editor, and add the Player Sphere Trigger, Random Choice, and two Unit Spawner objects to the Logic Editor window.

Link the "Triggered" Output to the "Roll" Input. Then link the "One" Output to the "Spawn Units" Input on one Unit Spawner and the "Two" Output to the "Spawn Units" Input on the other Unit Spawner.

Conclusion

When the Player enters the Player Sphere Trigger the Random Choice Object will randomly select one of the two Unit Spawners and spawn the specified Monster. The Player can enter and exit the Player Sphere Trigger repeatedly to re-roll the Random Choice Object and verify it is actually randomly choosing one of the Unit Spawners every time. Random Choice Objects can have up to five different choices and be linked to other Random Choice Objects for even further randomization.

Personal tools
Namespaces

Variants
Actions
Navigation
Runic Sites
Toolbox