Dungeon Generator Script v1.0

What is it?
This script is one I have wanted to do since I started working with VX.  It allows a random dungeon to be created from a number of rooms of any size and shape.  This allows for more controllable dungeon design.

How can I use it?
To use this script, place it under “Materials” but above “Main”.  To use a random dungeon, simply use the following script call:

  • create_dungeon(length, alts, width, height)

After using this call, just transfer to a map tagged with “<random>” and the random dungeon will be created.  The 4 arguments of the script call are meant to be numeric and are as follows.

  • length – The total length of the main path of the dungeon.  Using a higher number will create a larger dungeon.
  • alts – The max number of treasure paths to create.  These paths can be any length between 1 and “length” rooms and will start from any existing room EXCEPT the start and end rooms.
  • width – The total allowed width of the dungeon in rooms.  By default a buffer of one room is placed on each edge of the dungeon and includes empty rooms.
  • height – Same as width only vertical.

Maps must be created with a total of 40 “rooms” that the dungeon selects to draw from. This creates a set of rooms that is 8 wide and 5 tall. Every room must be the same size, but the size of the rooms and the size of the set is pretty much infinite. The first 16 rooms are the standard rooms that will show up based on the random value you set in the config section.

The next 16 tiles follow the same pattern. These are the “uncommon” tiles that only appear with a certain chance based on the random value set in config.

The final 8 tiles are the start and end points. The first 4, your start points follow the pattern up, right, down, left. The last 4 are the end points and follow the same pattern.

The end result map should be something like this:

(click to view full image)

There are 2 types of special events that can be placed on a map.  These are as follows:

  • <super> – Any events with this in their name will get placed in the very upper left hand corner of the map.  This is useful for parallel processes and other such events.
  • <treasure> – The event with the lowest id and this in it’s name will get placed on all tiles in treasure rooms that have an ID of 3.

Regions are very important for telling the map where certain things should happen.  The region tags that are reserved by the generator are 1, 2, 3, 4, 6, and 8.

Region 3 is used by the generator to determine where to put treasures. When a room is designated as a treasure room (the end of an alt path) it will search the room for a region 3 and place treasure chests on ANY found (see above for how to mark these).

Regions 1, 2, 4, 6, and 8 are used for the start points.  As it is creating the dungeon, it will take the last of these regions that it copies and set it as the start point.  As a general rule, only put one of any of these in each of the 4 start rooms.  When using region 1, the player’s facing direction is determined by the transfer event.  If you want the direction to change based on which room the player ends up in, user 2, 4, 6, or 8.  These will set the player to face the same direction as the same number on the numpad, for example, region 8 will place the player facing up.

All other events work normally.  When a room is copied over to the newly created map, all events are taken with it and placed in exactly the same spot.  The only exceptions are events marked as treasures and events marked as super.

What does it work with?
This script may not work with scripts that modify how maps, tilesets, or events work.

This script adds an additional command to my Basic Console script that allows you to see a map of the dungeon generated.  To do this, type “map” in the console screen.

How can I get the code?
Version 1.0 (base script, 9.8.2012) is available from my pastebin account here or the demo on my mediafire account here.

I would like to use this code.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
Permissions beyond the scope of this license may be available at https://cphouseset.wordpress.com/liscense-and-terms-of-use/.

Author’s Disclaimer:
I had created a similar dungeon generator to this with events in rpg maker 2k3 and it actually worked really well!  Of course with scripts it’s a lot more controllable.  The main focus of this dungeon generator is to allow large dungeons with multiple “rooms” to be created which allows more control to the shape of dungeons.  The result is random dungeons similar to Persona 4.  Rather than being small, ugly paths, you can create large, robust rooms, and due to standard and special rooms, you can even have some simple little challenges in some of those rooms.  This may be a bit tricky to use, so I included a demo which shows how several aspects of the script work.  If you’re having trouble, be sure to check that out.  As always, enjoy!

  1. SirCumferance

    I likes it, the dark forest has never been so scary….but let me ask you this, once its made, is there a way to ‘leave it’ so that it was randomly made but revisitable? (Only random on creation)

    • SirCumferance

      Ah, nevermind, I just removed the RANDOM DUNGEON GENERATOR from the event but left the teleport…who’s the goose? This guy!
      Thanks for making an awesome script, by the way, gonna get some mileage out of it.

  2. With a map of 136×65 it doesn’t work :( each room is 17×13.
    I got an error message on line 234 : @map.data[blockx + i1, blocky + i2, i3] = square
    It seems that some value is nil and not integer…

  3. It seems the map size must not exceed 103×99. width of 104 or more and it crashes. same for height of 100 or more…
    Don’t know why !

  4. Sorry to post so much… 96*95 (15*19 tiles) doesn’t work. but if I change the size to 103*99, it works ! but unplayable as 103 is not divisible by 8 and 99 not divisible by 5, so I can’t make right tiles…

    • SirCumferance

      No, dont double. I just kept adding 16 and 10 to the room size. Example, my base room is 88×55, I tried to double to 176×110 and it didnt like, so I just added 16×10 a few times and got 168×105, which works nicely.

      Sorry took so long, after work was some Magic, followed by some drinking, lol. HOpe this works out for you. Lemme know

      • SirCumferance

        Which reminds me, the dungeon BIG is the one you want

      • mekka2000

        Thanks, it seems it crashes for me depending of the room size… But it never crashes if I make the rooms square, so I made rooms 20*20 and it works (map 160*100) !

  5. SirCumferance

    I will have a demo for you when I vet home from work. I got A fairly large map going, but the first block is 10×10 if that helps, I can see this for random cities too, nodes for the Matrix….hmm, the thought a flowing

  6. SirCumferance

    take a room thats is half as big as you want and double it, both directions. I think i did the tedious of copy pasting room after room until it worked, lol. couple hours and I will dropbox you what I got

  7. How do you manage the open ended rooms? Everytime I try, the autotiles close it off.

  8. SirCumferance

    If you hold shift when selecting a tile and hold shift when placing it, it will be exactly as the tile selected, ignoring autotile placement. Also, not having the room wrap helps with that as well.

    I have made the individual rooms HUGE and have events that change direction on creation then self switch on direction so that the dungeon rooms, even if the same, will have some different stuff in them. Its a pretty badass script and reminfreminds me of Phantasy Star online alot.

  9. SirCumferance

    Just realized i never dropboxed you my demo, lemme see if I can later on. My bad

Reply to this post

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: