Create Specific Item X Times

In this topic we handle scenarios in which you want some objects to be instantiated for a specific number of times. This is useful when..

  • You want to define more precisely how often loot chests, enemies or point of interests should appear
  • You want the Player to look for a key or switch first, before he can escape through the exit

In this tutorial I assume you already setup a working map.

  1. Let’s create a map with one or multiple loot chests, or skip this step if you already have such a map.
  2. If not already done, add this map to the Space Maps’s note tags.
  3. Place some Spawn Locations on the snippets. Let’s use Region Id 11 for this.
  4. Open the Script which calls the Generator.
  5. We will modify the line drawDecorations(). Add a list of all the regions which decorations will be drawn without rules as function parameter, in other words: All decorations except for the loot chests. This could be the regions 1, 2 and 3, then we use this call:

    .drawDecorations([1, 2, 3])
  6. Just below this line we add this function call:

    .drawDecorationXTimes(11, 1, 4)

    The numbers 1 and 4 define the range of how often an item will be drawn. At least 1 and not more than 4 loot chests will appear – if possible. If there’s no free location to spawn available anymore, the generator skips this command and nothing happens.

The Parameters 2 and 3, which stands to the minimum and maximum number, are optional. If you leave out the maximum number, then the Generator will draw exactly X times, and if you leave out both, the Generator will draw exactly once.

Now you will have something in between one and four loot chests on every map (unless you put too less locations to spawn). If you have any troubles, look into the Demon Castle of the Demo Project.

Leave a comment

Your email address will not be published. Required fields are marked *