Kai Monkey's Random Dungeons! -- Now with Version Two!

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
KaiMonkey's Random Dungeons!
Version 2

Intro
Welcome to Kaimonkey's Random Dungeons. With this script you can have the game randomly produce floor after floor of unique environments for your player to explore. Forest, sewers, caves, mines and more can all be generated, and all options can be fine-tuned to get the perfect dungeon for your game!
 
Screenshot:
 
Script:
150 demo downloads, and only 23 script downloads? Just download the demo! (Up to 300 now!)
 
Features
  • Generate an infinite number of randomly generated dungeons for you to explore.
  • Have different settings for different dungeons, allowing your "Happy Forest" dungeon to be entirely different from your "Deep Hell" dungeon (And your players would expect not less) 
  • Populate your dungeon with events: Anything which can be built using events can be generated straight into your dungeon!
  • Use a powerful Room system to create unique features in your game

    New in Version 1.1:
  • Create rooms in rectangular shapes, not just squares!

    New in Version 2.0
  • Teleport events (and the character) to the nearest available square upon entering the dungeon, allowing for more complex dungeons
  • Have rooms which contain other rooms
  • The room system gets even more powerful with Required Rooms: Tell the game to put a particular room "Somewhere" in the dungeon (Allowing for dungeons with complex lever puzzles, keys hidden around the dungeon, monster which must be slain ect, as well as giving the designer more control over when certain features appear in the game)
New in Version 2:
  • Updated Optional Lesson 3
  • Added Optional Lesson 4 and 5
Demo
Demo here!
 
How-To-Guide
Alright, I admit it, there is quite a lot of work required to get the most out of this script. For this reason I will be posting a number of step-by-step lessons on how to best use KaiMonkey's Random Dungeons. Lessons 1,2,3 and 4 must be taken in order. Optional lessons can be taken in any order (Although 5 requires 3)
 
Lesson 1: Building the tiles

The random generator works by piecing together pre-built map segments (Which I will refer to as tiles) to build up the dungeon in a maze like fashion. 
At the end of this lesson you should have something which looks like this:

 
Although this may look basic and boring. That is because it is, but this is only lesson one. Each of the option lessons which follow will allow the extra detail you need to create the perfect dungeons for your game!
Steps:
  • Decide your dungeons Tile-Size; how big your tiles are going to be. Bigger tiles mean you can have more detailed tiles, but also tends to produce simpler dungeons. Note, that you can have small dungeons with big tiles, and vice-versa. For your first dungeon, I suggest a size of seven.
  • Create a new map (and call it something like DungeonTiles) Make note of its ID, which is at the top of it's property panel. It should be a three digit number like "004". We will call this number the Tile Map ID
  • Set both the width and the height of the map to be equal to (Tile-Size x 4) + 5. So if you are using a tile-size of seven, that means the map is going to be (7 x 4) + 5 = 28 + 5 = 33 tall and 33 wide.
  • Use any terrain draw a 4x4 grid on the map. This will not show up in game, and is just there to visually show you, the designer, where each tile is. 
  • In each tile draw out the segment of the maze. You can put anything you want here (even events!). 
  • Refer to the screenshot in the spoiler to ensure you place the right tile in the right place. For example, the top right corner should only have exits to the top and right. If you do not follow the same placement pattern as this template, there generation will not work
This blog post discussing Shift-Click mapping, which is a very useful tool in ensuring that that the tiles seamlessly connect. 

 
Lesson 2: Building the Floor Entrances and Exits
When the player starts a dungeon, whichever tile they start on will have a special overlay placed onto it. (This can, of course, be empty, if you do not want to mark the floor starting point in anyway). Similarly the  a random tile in the dungeon is designated to be the floor's exit. One this tile, we want an event to appear which either transfers the player out of the dungeon (Perhaps to a boss fight, or back to the main map) See the optional lessons on how have the exit event generate a new floor, allowing for dungeons with multiple floors.


In this dungeon we have a rope event at the end of each dungeon, and a section of darkened dirt at the start.
  • Create a new map (call it something like DungeonDetails. I suggest putting it "inside" the map where you designed the tiles, by right clicking on that map and selecting new map, to keep your game organized). Make note of it's ID also, we will call this number the Detail Map ID
  • Ensure that the tileset in use is the same as you used when you designed your tiles
  • Set the map's size to be atleast Tile-Size + 2 in height, and Tile-Size x 2 + 3 in width. So if we are using tile-size of seven this means our detail map will be 17 wide and 9 tall. Ofcourse, this is too small for RPGMaker, so the default of 17x13 is fine.
  • Like we did for our tile map, use any terrain to draw a grid, this time with 2 squares, side by side, each the same size as your tiles
  • In the right most tile place anything you want to appear exactly once per dungeon floor. This should include some way of your player leaving the dungeon, such as being transferred to a different map. See the option lessons for creating dungeons which have multiple floors.
  • In the left most tile, place anything which you want to appear on the tile where the players starts the floor. If you want nothing special to appear, just leave that section blank

 
Lesson 3: Creating the Dungeon Space
Here we are going to create the map which your dungeon will be generated into.
  • Create yet another new map. (Name it something like Dungeon) The good news is you don't need to remember the ID of this one!
  • Decide how many tiles you want it to be wide. Set it's width to be Tile-Size x Your Width in Tiles
  • Decide how many tiles you want it to be high. Set it's height to be (Tile-Size x Your Width in Tiles) + 2
  • Why plus two? This allows for a one square space at the top and bottom of the map.
  • Fill the whole map with the "Ceiling" terrain. This is useful because it allows you to use the full height of the tile-size whilst designing tiles. 
  • Finally set up any map settings which you want to apply to this dungeon, such as Parallax, Random Encounters, Background music, ect.
  • If you wish to have any parallel events* running while the player is in this map, those events must have  
    Code:
     <KEEP>
    in their name, or they will be removed when the dungeon is generated
*Or any other events you do not want removed by the dungeon generator
 
Lesson 4: Finally Generating the Dungeon (Now up-to-date!)
 Here we are, it's taken us quite a bit of work, but we are finally ready to transport the character to the dungeon and have them explore! This lesson will show you how to create an event which transports your player to a newly created unique dungeon
 
Step 1: Creating the Dungeon Door:

  • Create the event which will transport the player to the dungeon, such as a door, cave entrance or over-world location. 
  • Run any event-commands you want to run on that event before you start the dungeon (Such as showing an "Are you sure" message, or checking the player meets the dungeon requirements)
  • Run the "Fade-Out Screen" command
  • Transport your player to any part of your Dungeon Space
  • Set a switch to true (Call this switch "Dungeon Starter", it will be tell the script that you are about to run the script, but on a different map.
Step 2: Adding the script call
  • Go to the Dungeon Space map
  • Add somewhere in the top line, and name it
    Code:
    <KEEP>
  • On the conditions panel on the top-left, set " ☑ Switch: Dungeon Starter" 
  • On the trigger panel on the bottom-left, set the trigger to "Autorun"
  • Add the first event command to "Advanced -> Script" and type:
    Code:
    	rand_dungeon("001","002",7)
    You MUST replace "001" with the map id of your tile-map, "002" with your detail map, and to your tile-size!
    If you do not do this the code will not work.
  • Set the Dungeon Starter switch to off.
  • Fade in the screen!
And that's it! Enjoy your dungeon!

 
By following Lessons 1,2,3 and 4 you will have a basic dungeon generator. It will, however, look rather plain (and/or repetitive). The following Optional Lessons help add the depth the map generation which players expect
 
Optional Lesson 1: Using multiple Tile Maps:
To add more variation to the dungeons generated, you can tell the script to randomly pick between a number of different Tile Maps.
  • Copy the first Tile-Map used for this dungeon. Make note of it's Map ID. 
  • Make the changes you desire to this version of the tile-map. Refer to the above image for inspiration. 
  • Repeat this process to create any number of Tile-Maps you need. These do take quite a while to make, but the more you create the less repetitive your dungeons will be.
  • Modify the code used to generate the dungeon to:
    Code:
    rand_dungeon(["006","013"],"012",7)
    Where inside the square brackets you list all the ID's of the Tile-Maps used, in quotes, separated by commas. Replaced the 012 with your Detail-Map ID and the 7 with your Tile Size as usual.
  • The dungeon will now randomly choose from both sets of tiles. Note that only the first set in the list (In the example, that would be 006) is chosen for the Start and Exit tiles, so you do not need to worry about whether your detail overlays will overlay nicely over your additional tiles, only the first one (For example, if the exit is placing a ladder in the centre of the tile, only the first tile-set NEEDS to have access to the middle tile)
 
Optional Lesson 2: Making use of the Room system:
The room system is a powerful system for creating elements which repeat in your dungeon (Or, perhaps, multiple dungeons). These can be as simple as single tile events (such as treasure chests), terrain decorations, or entire areas taking up most of a tile's space. In this lesson we will design these rooms, and then go back to our tile-map designs, and tell the script where we want these rooms to generate.

  • Decide your rooms width and height. This can be anything from the full size of a tile, to a single square. 
  • Make a map of any size (It can be expanded at any time during development to accommodate more different variety of rooms). Make note of this maps Map ID.
  • Using any terrain type, build a grid of cells the same size as you want your rooms to be. In the example, each room is 5x5, and there 9 rooms. If there is not enough room, and one or more rooms are cut in half, expand the room so that only whole rooms are on the map
  • In each room, design the features which you wish to appear throughout your map. 
  • Go back to your Tile-Map. At each point where you wish to place a room in your dungeon, create an event in the top-left corner of where you wish a random room to appear. The event settings do not matter, as this event is only a placeholder, and will never be seen in game. 
  • Set the events name to match the following:
    Code:
    <room>011,5,6
    Where 011 is replaced with the ID of the map with the room designs, 5 is replaced with the width of the room, and 6 is replaced with height of the room.
  • These rooms will not populate your dungeons! Note: You can have any number of different types of rooms, of different sizes, appearing in your map.
  • Also note that rooms will never appear where the entrance or exit to the floor is.

 
Optional Lesson 3: Making Dungeons with Multiple Floors
In this lesson, we will create a dungeon which has multiple floors, and only after every floor is complete, has the player completed the whole dungeon.
  • Modify the Event which transports the player to the dungeon to set a new Variable to 1. Call this variable "Floor Number" 
  • Modify the Event which is placed at the exit of the dungeon to, instead:
    1. Check if the floor Number is equal to the number of floors in the dungeon
    2. If it is, transport the player out of the dungeon as normal (To the boss fight, cut scene, or dungeon entrance ect.)
    3. If it is not, turn back on the Dungeon-Starter switch, then fade back to normal
  • You now have a dungeon with a set number of floors!
 
Optional Lesson 4: Teleporting Players and Events
If you have a dungeon in which the player, or other events, are likely to spawn in unpassable locations (Such as the sewers in the demo) take the following steps:
  • Set the name of any Event which might spawn in an incorrect location to
    Code:
    <MOVEABLE>
    . This will move it to the nearest available square.
  • To start the player in an allowed square, after you call rand_dungeon, add "Timing -> Wait (1 Frame", and then "Advanced -> Script"), and type
    Code:
    move_char_to_closest_tile($game_player)
 
Optional Lesson 5: Using Required Rooms
Required Rooms are a powerful feature which allow you to, with a script call, force a certain room into the dungeon. This can be used for, to name just a few:
  • Place a missing major's daughter somewhere on the final floor, and only if the dungeon is not yet complete
  • Place a Switch somewhere in the dungeon which must be pressed to continue
  • Have hidden game events depending on Party composition, time of day, ect
  • And much more!
It works by, whenever the dungeon generator places in a room as normal, it checks to see if there is a required room of the same size. If there is, it uses the required room instead. If there are no slots of the correct size, then it will never get placed.
  • Create the Room(s) you want to appear, as per normal (See Optional Lesson 3)
  • Make note of that Maps Map Id. This is the Room Map Id.
  • If you want a particular Room or Row/Column of Rooms, make note of the x, y index
  • When you want to tell the game to start requiring that room, call
    Code:
    	Dungeon_Settings.add_required_room(	12 ,1,2, 3, 4)
    , replacing 12 with the Room Map Id, 
    1 with the width, 2 with the height,
    3 with the x-index (Or "-1" for random)
    4 with the y-index (or "-1" for random)
  • When you no longer want that room to be required, call
    Code:
    Dungeon_Settings.clear_required_rooms


FAQ:
  • My Tile-Map has decorations from layers B,C,D and E, but sometimes I want rooms to remove them, like if I have a building or big hole in that room?: Ah, in that case all you need to do is go to that room, and use the Region tool to mark those squares at region 63. On these squares any terrain that is not from page A will be removed.
  • I have a script or parallel process system that works using Region ID's, will this still work for randomly generated dungeons: With the exception of region 63 (See above), Absolutely! Remember that the region ID of the room takes precedent over the region ID of the tile it is placed on.
  • Can I have dungeons generate differently depending on which floor I am on? Of course! All this requires is some clever eventing to change which script you run. Want to have different tiles appear when you are above floor 10? Just check the floor variable and tell it to run a script with different list of tile ID's. You can also have events that appear in your rooms and tiles check the floor number and behave differently depending. Using this technique you can also have the dungeon change depending on other factors, not just floor number. Want the dungeon to produce more treasure chests if the player has the magic amulet on? Simply make the event check for the item, and if the player does, then call the script which also has the tile-set which has more treasure in it's list!
  • Oh no! My tile's have really clear edges, and look like they have been clicked together! Other than the fact I think this looks quite nice, there problem here is one of autotiles.This blog post discussing Shift-Click mapping, which is a very useful tool in ensuring that that the tiles seamlessly connect. 
  • Oh no again! There are shadows in the middle of corridors when tiles connect to the right! Okay, this one DOESN'T look nice, but it is easy to fix. Simply go to the tile map, and use the shadow tool to remove those pesky shadows on the right side of the bottom eight tiles!
  • Oh no, once again! My character (or some event) was placed in the middle of a Wall/Water/Tree! See Optional Lesson 4!
  • Can I display the current floor? Because the current floor is stored in the Variable, it can be accessed like any other. If you want the Floor Number displayed in a HUD, I recommend XS - Variable Hud, hiding the HUD when not in dungeons.
  • Couldn't the Required Room System be used to create a complicated Quest/Job system? Why yes, and it is going to come in a separate Add-On!
  • Can I have a placeholder room which can be replaced with a Required Room, if there is one, but nothing else? Yes, replaced the map id with 0
  • Can I say that a particular room can never be replaced with a required room? Use <!room> instead of <room>.
 
Terms of Use:
Free to use for non-commercial projects, however you should PM about licensing for commercial projects.
 
Finally:
This script has been the biggest project I have every created for the RPGMaker community. I would really appreciate people taking the time to try and use this to it's fullest. In exchange I will be as active on this site as I can. I really would like to improve this script, and make it into something great If you have any suggestions, find any bugs, or just want to ask a simple question (Remember, no such this as a dumb question!) just post it right here!
 
Last edited by a moderator:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,492
Reaction score
4,968
First Language
English
Primarily Uses
RMVXA
I've been thinking for a while about how to construct a script like this and came up with a fairly similar approach.  I also came up with the idea that it would be extremely hard and time-consuming to make and that I probably wouldn't complete it for quite a while.  But you did!!  So big congrats on that.  I'll definitely be checking this out and I'll let you know what I think when I find the time to test it thorougly!  Thanks for sharing it!!

EDIT: 2 questions that come to mind upon reading your guide.

  1. Is it possible to allow the player to move back to the previous floor of a randomly-generated dungeon (without having it re-randomize the previous floor and the current floor)?
  2. Is it possible to use the Room system to associate a room to only certain tiles (so that, for example, a Room that has an obstacle on the north end won't ever be matched with a tile that has a North exit)?
 
Last edited by a moderator:

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
No, right now you can't return to previous floors. This is because of the way events' self-switches are stored: they are not self-switches at all, but instead global switches referenced with the map Id and event Id of the event. This means I have to manually reset the self switches for the events the dungeon generator creates, otherwise all the chests start generating empty!

2. Yes and no. The only way to do this is have a special type of room, and only place it in the rooms with access from the north
 

Sidbot

Villager
Member
Joined
Oct 16, 2012
Messages
21
Reaction score
4
Primarily Uses
Thank you so much! I can't wait to try this.
 

Mojo907

Veteran
Veteran
Joined
May 21, 2013
Messages
160
Reaction score
36
First Language
English
Primarily Uses
RMMV
This is great! Committing the time to the dungeons isn't too consuming, but I do seem to have problem sorting out the seemless issue lol. It's not too bad, but I would rather not have it, but I've always had that problem with mapping and the autotiles. I will continue to play around with it though, it is great!

EDIT: meant "isn't" not "is"
 
Last edited by a moderator:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,492
Reaction score
4,968
First Language
English
Primarily Uses
RMVXA
Thanks for the responses!  Still really looking forward to trying this out first chance I have a bit of time.

No, right now you can't return to previous floors. This is because of the way events' self-switches are stored: they are not self-switches at all, but instead global switches referenced with the map Id and event Id of the event. This means I have to manually reset the self switches for the events the dungeon generator creates, otherwise all the chests start generating empty!
As cool as it would be to have this feature, I can see why you went without it for the first version.

Hopefully designers will be smart enough to include ample exit points, escape-dungeon items, non-game-overs, etc. if they're using randomized dungeons.

2. Yes and no. The only way to do this is have a special type of room, and only place it in the rooms with access from the north
Think I understand what you're getting at here.  The best way to do this would be to create a separate "room map" with these features so that I would be able to only reference that room map from tile maps that allow/block access in that desired direction?
 

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
Yes, that's exactly what I mean!

I am currently working on the second version and the demo- if anyone has any suggestions let me know!
 

C-C-C-Cashmere

Veteran
Veteran
Joined
May 18, 2012
Messages
584
Reaction score
274
First Language
English
Primarily Uses
This random dungeon generation script looks INTENSE. I'm almost tempted to make a game with it...
 

MHRob

Card Master
Veteran
Joined
Jun 30, 2014
Messages
133
Reaction score
24
First Language
English
Primarily Uses
RMVXA
Looking forward to a demo. This looks pretty neat.
 

omen613

Veteran
Veteran
Joined
May 22, 2012
Messages
309
Reaction score
109
First Language
English
Primarily Uses
Amazing work! I'm gonna have to tinker with this now.

Looking forward to the Demo
 

MHRob

Card Master
Veteran
Joined
Jun 30, 2014
Messages
133
Reaction score
24
First Language
English
Primarily Uses
RMVXA
Very interesting thus far, Kai! Thanks for sharing the demo. Seeing it in action is pretty cool and impressive thus far for just a single script.

Well done!
 

leedragoon

Villager
Member
Joined
Jul 27, 2013
Messages
28
Reaction score
1
First Language
English
Primarily Uses
By far the easiest and smoothest random dungeon generator I have tried! I had a lot of fun playing around with it and doing the tutorial, thank you for all the hard work and effort I know went into it. You rock!!!
 
Last edited by a moderator:

Mojo907

Veteran
Veteran
Joined
May 21, 2013
Messages
160
Reaction score
36
First Language
English
Primarily Uses
RMMV
Demo is excellent, pretty snazzy system you have, and I'm sure you will get phenomenal praise for sharing it. Awesome stuff!! :rock-left: :D :rock-right:
 

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
I'm so glad everybody is enjoying the demo. I'm trying to think of features to improve this script (such as allowing Rooms to auto-adjust to which exits that tile has)- but I'm not coming up with all too many.

If anyone had any suggestions, or requests, now's the time to ask!

/Kaimonkey
 

Myst

Jack Of All Trades
Member
Joined
Oct 28, 2013
Messages
34
Reaction score
2
First Language
Awesomeness
Primarily Uses
Whenever I try to generate a dungeon it's just endless ceiling terrain  .-. and no rooms, except it generates only my exit room over my ceiling terrain
 

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
Can you post, in spoilers, your tile map, your detail map, and your script call?
 

Myst

Jack Of All Trades
Member
Joined
Oct 28, 2013
Messages
34
Reaction score
2
First Language
Awesomeness
Primarily Uses
Show me where I messed up, My tile size is 8

 
 
Last edited by a moderator:

Myst

Jack Of All Trades
Member
Joined
Oct 28, 2013
Messages
34
Reaction score
2
First Language
Awesomeness
Primarily Uses
Oh and I set the tile size to 10 in the event call to see if it'd work, I tried 8 
 

Kai Monkey

Veteran
Veteran
Joined
Apr 3, 2012
Messages
166
Reaction score
119
First Language
RGSS3
Primarily Uses
Okay, I see the issue! 

Your tile-size has to be consistent! 

  1. Your script call should look like rand_dungeon("004","007",8because thats how many squares wide each of your tiles is.
  2. Each tile in your detail map is 9x11, when it has to be 8x8, because that is your tile-size.
Also, remember you can use empty squares in your detail map if you want things to "Put on top" of the existing map, instead of replacing it entirely. 
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Ami
--- Currency ---

Hero: This city cannot accept Gold to buy the items.
Merchant: You can exchange Gold into TC,depending the rate of TC this time.
Hero: Really? Then,i want to exchange 999999999G.
Merchant: Let's see……Wait a second,are you Cheating again?
Hero: Hell No!!! I earn it with myself!!!
There's always a time when you're super excited to create something but you already have no energy left. :I
I think of all the effects in my game, the light passing through fog has got to be my favorite....

...Also I spent all day trying to figure out how I had suddenly messed it up and made it start dropping frames like crazy. So I had all day to look at it... mocking me... with it's previous 60fps reduced to 30fps... At least it's fixed now.
Dalph wrote on slimmmeiske2's profile.
Slimmm, we should team one day and make "Reid in Wonderland" or "Aluxes in boots".
Ami
--- F.Mage Cooking ---

F.Mage: Hey,guys. i made dinner for you!
M.Fighter & Hero: (Shock) Dinner???
(F.Mage Put The Failed And Burnt Dishes Surrounded With Creepy Aura)
Hero: What the...???
F.Mage: It's Curry Rice,Fried Egg And Cakes. I hope you guys like my Dishes.
M.Fighter: Are you kidding me?

Forum statistics

Threads
103,479
Messages
999,640
Members
135,025
Latest member
ErvinDaster
Top