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 add some loot chest on the Decoration Map and assign it to eg. Region Id 11. I drew 4 loot chests, whereas 3 are small ones and 1 is a more epic one. This way we get a 3:1 ratio.


  2. Place some Spawn Locations on the snippets (again with Region Id 11).
  3. Open the Script which calls the Generator.
  4. 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])
  5. 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