Randomizing a Map with Premade rooms?

I'm driving myself in circles with this trying to do it all with events because I do not know how to script and I'm almost cross-eyed. I am wondering if I am making this harder than it needs to be and there's a simpler solution or if I'm SOL and I just gotta suck it up.

I want to make my map randomized with a set of premade maps that I have made.

For instance there is a hub world with 6 doors that can lead to 6 different premade areas that I have made but I don't want any overlap.

If Door A draws room 1 room 1 is taken out of the 'deck' so to speak and then it goes down the line.
Trying to do this manually I'm getting confused with myself and every Randomize map plugin or google I lookup is trying to draw the maps, but it's not what I want.

I have my maps made, I want their locations randomized if this makes sense.

I've successfully done this on a small scale with 2 rooms, but adding more variants in I confuse myself.

This is something I have my heart set on in my game so I will power through if I must. But I am hoping that there is a simpler solution but I'm not seeing it due to my inexperience. Thank you!
1721708853436.png
1721708911972.png
So, what you are trying is :

- Have a map (Map 1 for example) that has 6 doors
- Each door leads to Map2 ~Map7 (2,3,4,5,6,7 = 6 doors)
- Each door leads to a randomized map (Door1 can lead to any door, door2 also, and so on)
- Once a room has been "linked" to a door, remove that from the "map pool", so if door 1 leads to map 5, remove map 5 from the pool so that door2~7 lead to map 2,3,4,6,7

Is that correct?
Declare one of the game variables as an array of possible map IDs, randomly pick an index from the array and splice it out.

Edit: Oh, you said no scripting. Well, honestly scripting is the easier option here.
It's not so hard to do without scripting. Longer to write out, but certainly less complicated.

You have 6 variables to store the states of the 6 doors.

Do something like this.

1721712405560.png


And just keep going through all six - make a loop, assign it a random value, then if it's not equal to any of the prior doors, break the loop.

Then your events for the doors have either conditional branches or 6 pages to send the player to the appropriate map depending on the value of that door's variable.

@Artille​

Looks like you understand what I'm going for yes.

​

@AquaEcho ​

Sorry yea, I am not very knowledgeable on scripting So I was trying to get this with events.​


@ATT_Turan
This looks so much easier than I was trying. I'm going to see if this works! I haven't tried working woith Loops since I'm still a novice but I THINK I understand the concept.
It's not so hard to do without scripting. Longer to write out, but certainly less complicated.

You have 6 variables to store the states of the 6 doors.

Do something like this.

View attachment 312284

And just keep going through all six - make a loop, assign it a random value, then if it's not equal to any of the prior doors, break the loop.

Then your events for the doors have either conditional branches or 6 pages to send the player to the appropriate map depending on the value of that door's variable.
I know I'm not supposed to double post but OMG THANK YOU SO MUCH! This is so much easier than what I was trying to do and it works. I appreciate you so very much!!! Thank you!!!
You saved me hours and hours of headaches. Bless you good sir! May all of your projects be successful and get millions of downloads/buys etc.
It's not so hard to do without scripting. Longer to write out, but certainly less complicated.

You have 6 variables to store the states of the 6 doors.

Do something like this.

View attachment 312284

And just keep going through all six - make a loop, assign it a random value, then if it's not equal to any of the prior doors, break the loop.

Then your events for the doors have either conditional branches or 6 pages to send the player to the appropriate map depending on the value of that door's variable.
Haha, I guess that is why people are so tempted to use script because it takes only 1 sort funcion to shuffle the 6 doors. And if the random function is bad this can be an endless loop if it never rolls a certain number.
Haha, I guess that is why people are so tempted to use script because it takes only 1 sort funcion to shuffle the 6 doors. And if the random function is bad this can be an endless loop if it never rolls a certain number.

If I knew more about scripting I'm sure I could do something with it that is more simple and would run more efficiently, I hope to one day reach that skill level.
Honestly, it would be much easier with some scripting, even if it can look a bit scary when you start. ^^

First declare an array :
JavaScript:
AvailableMaps = [ID1, ID2, ID3, ID4, ID5, ID6];
Use the 6 map ID's you want to use here

Then loop through your doors, asigning a random map ID to each door :
JavaScript:
for (door = 1; door <= 6; door++) {
 
  randomIndex = Math.randomInt(AvailableMaps.length);
  selectedMap = AvailableMaps[randomIndex];
randomIndex = Math.randomInt(AvailableMaps.length);
This part means it will apply a random value between 0 and the number of entries in the array AvailableMaps - 1. (In javascript index start at 0, not 1)
So the first time, there will be 6 entries, meaning the output will be from 0 to 5 (total 6)
The second time there will be 5 entries, and so on.
selectedMap = AvailableMaps[randomIndex];
This part means it will apply the actual value (so the provided variable ID) to a variable called selectedMap, based on the randomIndex (which contains the array entry ID, or index).
So if randomIndex is 3, it will look for the 4th entry in AvailableMaps which is ID4.
(again, javascript index start at 0, not 1)

Then assign the map to the door :
JavaScript:
$gameVariables.setValue(door, selectMap);
This logic would set a random value between the 6 map ID to variables 1 to 6.
You can modify this logic to use specific variable ID's.


Then splice the array :
JavaScript:
AvailableMaps.splice(randomIndex, 1);
This will remove the element at the randomIndex generated from the pool of available maps, by its position.
So if randomIndex = 3, it will remove the 4th index of the array (which is ID4).
1 means you want to remove 1 index at a time.


Meaning the complete script would look like this :
JavaScript:
AvailableMaps = [ID1, ID2, ID3, ID4, ID5, ID6];

for (door = 1; door <= 6; door++) {
  randomIndex = Math.randomInt(AvailableMaps.length);
  selectedMap = AvailableMaps[randomIndex];

  $gameVariables.setValue(door, selectedMap);

  AvailableMaps.splice(randomIndex, 1);
}


If you need to modify the logic for the door variables (say you use different variables for the doors), you can apply this instead :
JavaScript:
AvailableMaps = [ID1, ID2, ID3, ID4, ID5, ID6]; //Map ID's
doorVariables = [ID1, ID2, ID3, ID4, ID5, ID6]; //Door variable ID's

for (door = 1; door <= 6; door++) {
  randomIndex = Math.randomInt(AvailableMaps.length);
  selectedMap = AvailableMaps[randomIndex];

  $gameVariables.setValue(doorVariables[door], selectedMap); //Use the 1st ID for door1, etc...

  AvailableMaps.splice(randomIndex, 1);
}


At that point, you have it all set up for your event.
Make an event and select "Transfer Player" but use variable values instead of direct values.

So for example :
Create 6 variables, called Door 1, Door 2, Door 3, etc..
Create a door event called Door 1
Select Transfer Player, choose Set with Variables, select ID: Door 1
Set X and Y position (if it's not all the same, you will need an extra step though)
Repeat for each Door event.
It is OK I guess. Using event commands is another form of "scripting", just in another form.
Honestly, it would be much easier with some scripting, even if it can look a bit scary when you start. ^^

First declare an array :
JavaScript:
AvailableMaps = [ID1, ID2, ID3, ID4, ID5, ID6];
Use the 6 map ID's you want to use here

Then loop through your doors, asigning a random map ID to each door :
JavaScript:
for (door = 1; door <= 6; door++) {
 
  randomIndex = Math.randomInt(AvailableMaps.length);
  selectedMap = AvailableMaps[randomIndex];

Then assign the map to the door :
JavaScript:
$gameVariables.setValue(door, selectMap);
This logic would set a random value between the 6 map ID to variables 1 to 6.
You can modify this logic to use specific variable ID's.


Then splice the array :
JavaScript:
AvailableMaps.splice(randomIndex, 1);

Meaning the complete script would look like this :
JavaScript:
AvailableMaps = [ID1, ID2, ID3, ID4, ID5, ID6];

for (door = 1; door <= 6; door++) {
  randomIndex = Math.randomInt(AvailableMaps.length);
  selectedMap = AvailableMaps[randomIndex];

  $gameVariables.setValue(door, selectedMap);

  AvailableMaps.splice(randomIndex, 1);
}


If you need to modify the logic for the door variables (say you use different variables for the doors), you can apply this instead :
JavaScript:
AvailableMaps = [ID1, ID2, ID3, ID4, ID5, ID6]; //Map ID's
doorVariables = [ID1, ID2, ID3, ID4, ID5, ID6]; //Door variable ID's

for (door = 1; door <= 6; door++) {
  randomIndex = Math.randomInt(AvailableMaps.length);
  selectedMap = AvailableMaps[randomIndex];

  $gameVariables.setValue(doorVariables[door], selectedMap); //Use the 1st ID for door1, etc...

  AvailableMaps.splice(randomIndex, 1);
}


At that point, you have it all set up for your event.
Make an event and select "Transfer Player" but use variable values instead of direct values.

So for example :
Create 6 variables, called Door 1, Door 2, Door 3, etc..
Create a door event called Door 1
Select Transfer Player, choose Set with Variables, select ID: Door 1
Set X and Y position (if it's not all the same, you will need an extra step though)
Repeat for each Door event.
You're right this is intimidating!! But I'm trying to read over it and understand it. Thank you for taking the time to explain this to me. It's a bit over my head but I'm going to save this for when I've learned more. My .js script knowledge is 0 but I'm trying to learn as I go!

I get lost around the portion
JavaScript:
for (door = 1; door <= 6; door++) {

I will admit this looks simpler than what I'm currently doing. I love randomness in my games and will save this for a later game when I inevitably do this concept again with hopefully more knowledge.
I get lost around the portion
JavaScript:
for (door = 1; door <= 6; door++) {

I will admit this looks simpler than what I'm currently doing. I love randomness in my games and will save this for a later game when I inevitably do this concept again with hopefully more knowledge.
The portion of code you mentionned is called a loop.

The for loop will take 3 parameters, the Initialisation door = 1;, the condition door <=6; and an operator (or increment) door++
Then it will read whatever script is in the the for loop so long as the condition is true. (Meaning door is at least 1 and equal or less than 6)

So, to oversimplify it, it does the same thing as :
Code:
If door == 1, read the code
If door == 2, read the code
..
If door == 6, read the code
If door == 7, don't read the code

Each time it reads the code, the value of door in the loop will be the value of the loop cycle.
The first time door will be worth 1, then second time it will be worth 2, etc...

door++ means you increase the value of door after every cycle.
So when it arrives at the end of the for loop, it does : door = door + 1 (or door++)
I actually made a tutorial for something like this quite a while back. But I am pretty sure that the solutions offered here are probably much more efficient than whatever I did at the time. These solutions are very helpful so a big thanks to everyone for sharing.
The key issue here is how to get the numbers 1-6 in a random but non-repeating order. I'll focus on that, because once you have the numbers, the rest is pretty straightforward. Here's how I would do that in MV if going the pure eventing route with 6 variables and 7 switches (3 temp variables & 1 temp switch)
1721733494416.png
1721733600083.png


I have split my main common event up into 3 pieces for the sake of brevity in this post. They could just as well have been part of one common event.
  1. Number sequence (main event)
  2. Reduce range
  3. Find number
1721733440983.png


The idea is that I want to reduce the 1-6 range to focus only on the available numbers. I do this by going through each switch to check if it's turned on or not. The common event Map use lookup uses variable Temp1Ref to find out which of the numbers to check. It sets switch #0011 TempMapInUse to ON if the number has already been used, otherwise it is set to OFF
1721733842761.png


Find number scans through the numbers again where it takes care to skip maps already used. Note that when all numbers are used variable #0003 Number will be set to -1. You can check against this in a conditional branch.
1721733981199.png


You may wonder what the Map use lookup and Set map used common events do. Their purpose is to mimic the missing variable-by-variable reference options. (Been missing since RM2K3 :rsad:)
1721734758277.png


Since the range is only 6 numbers we can brute-force it, and that's exactly what I have done.
1721734924827.png
1721734975315.png

Tedious to implement, but hey, at least it works.

You can test it out by creating an event and calling the Number sequence common event
1721735021845.png



If we ease off a bit on the eventing-only requirement, we can implement the variable reference via script calls. We can do the in use lookup via this script call:
$gameSwitches.value($gameVariables.value(11))

I.e. replace this
1721735512262.png

with this
1721735481577.png



For Set map used we can use:
$gameSwitches.setValue($gameVariables.value(11), true)

I.e. replace this
1721735637376.png

with this
1721735658725.png


Hope this makes things clearer

*hugs*
- Zeriab
if the random function is bad this can be an endless loop if it never rolls a certain number.
There's realistically 0 possibility of that happening, though. You might as well be concerned that your computer monitor is going to spontaneously explode in your face. 😛

Honestly, it would be much easier with some scripting, even if it can look a bit scary when you start. ^^
The point is, for the OP - and anyone else using RPG Maker because of the advertisement that "you don't need to learn to code" - it's not easier.

I have no problem with you also providing a scripting-based solution, of course, it's good to have all the information in one place.

But my intent was to demonstrate to the OP that it's perfectly doable using the included, language-based event commands and a logical progression. A scripting solution could not have been achieved without someone else's help.

Their purpose is to mimic the missing variable-by-variable reference options. (Been missing since RM2K3 :rsad:)
I think it's way overkill in this situation, but I made a plugin for that.
. A scripting solution could not have been achieved without someone else's help.
Isn't that a bit ironic since the OP would not have come to your solution without your help?

Realistically you can't do everything with just the included eventing despite the engine's claims unless you're ok with your game playing and feeling just like a template project. Pretty much everyone is going to use outside scripts from plugins or asking the forum for a snippet.
Isn't that a bit ironic since the OP would not have come to your solution without your help?
No, I don't see how it's ironic at all.

The OP could have come to my solution, given sufficient time/thought/experimentation.

And now that I've shown it to them, it's a technique they can understand and apply to other scenarios.

Just shoving in a good bit of code (even with Artille's helpful explanations) doesn't mean anything to someone who has no JavaScript training, and can't be used to extrapolate to any other situations since they don't know what the other necessary functions would be.

Realistically you can't do everything with just the included eventing despite the engine's claims
No one in this thread said you could, and I don't see where the engine claims you can.
Personally some of these eventing solutions pain me to look at, and the OP's problem isn't that complicated as far as scripting it in Javascript goes and you could learn to do it from w3schools tutorials. For example, as pointed out, your solution could result in the game locking into an infinite loop and freeze the game for the player, even if the chance is infinitesimally small, it is not zero.
Personally
And that's fine for you, but the OP has stated their personal knowledge and preference.

For example, as pointed out, your solution could result in the game locking into an infinite loop and freeze the game for the player, even if the chance is infinitesimally small, it is not zero.
That seems like a silly thing to focus on, to me. For how many times this random number will get rerolled in a fraction of a second, the possibility that it will continue generating one of the 5 taken values for any noticeable amount of time is functionally zero.

And if it bothers anyone, or actually comes into play, I'm sure someone could take a few minutes and use a mathematical process to determine which values have been taken and just assign the last one - personally, formulating math like that is not my strongest suit, so I didn't try to whip that out.

When someone asks how to do something in an event which is pretty easily doable in an event, telling them "it's easier to learn how to code" is, to me, not a good answer.
The point is, for the OP - and anyone else using RPG Maker because of the advertisement that "you don't need to learn to code" - it's not easier.

I have no problem with you also providing a scripting-based solution, of course, it's good to have all the information in one place.

But my intent was to demonstrate to the OP that it's perfectly doable using the included, language-based event commands and a logical progression. A scripting solution could not have been achieved without someone else's help.

I totally agree, I was going to point out to your eventing solution, but was caught in my scripting logic.

RPG Maker is user friendly and does not require one to have scripting logic/knowledge, however understanding how scripting works will help to make better events (even without scripts).

I just tried to give a condensed script (I can't think of something simpler), especially since OP seem to have somewhat interest in extending his knowledge. 🙂

Again,I agree that, without proper knowledge, my script probably looks like magic or alien stuff. 😊

Original thread: https://forums.rpgmakerweb.com/threads/randomizing-a-map-with-premade-rooms.170538/