RPG Maker MV

RPG Maker MV

343 ratings
Region ID Checks - The first thing to do after starting a new project!
By thesja
Region IDs play a huge role in RPG Maker but many new creators still don't use them. I think setting up a Region ID Check is the first thing you should do after starting a new project. It makes many events a lot easier to trigger and only takes a moment to set up. Here's how:
4
22
4
2
   
Award
Favorite
Favorited
Unfavorite
What this is good for (Example)




Imagine you want to prevent the player to get to the other side of the map (in this case a beach). The first picture shows how many people that are new to RPG Maker (I did it too) tend to solve this problem: Countless events that'll trigger On Touch and send the player back. If used on a large map, this can get really confusing and is unnecessary. A way simpler method is to just mark the specific region(s) with Region IDs and then add a single event that'll constantly check the Region ID the player is currently standing on.



You could label as many tiles with a Region ID as you like and you'd still get the same effect for every Region ID. No tedious copy-pastes of events anymore.

Note: For this guide I'll use Region ID 7. It's entirely up to you what value you use.
Declaring variables

First you need to create three new variables. Since it's best to do this right after you've started a new project, it should be the first three variables. You can use any other variable slot as well.

First variable: Player X
Second variable : Player Y
Third variable: Player Region ID
Creating a common event

Next up is creating a new common event that'll do the actual work: Giving us the Region ID the player is currently standing on. Putting the necessary commands into a common events allows us to simply call the event from anywhere on the map. It works like a shortcut. We'll name it Get Region ID.




The first thing we'll add to our common event is a Control Variables. Set the variable to our first variable (Player X), the operation to Set and the operand to Game Data. Click on the Game Data line so that the Game Data window opens. In the new window choose Character and Player -> Map X. This will set the Game Data line to Map X of Player.



Do the same thing for our second variable (Player Y) and replace
Player -> Map X with
Player -> Map Y



The last line

Next up we'll add our final line to the common event. Choose Get Location Info... and in the window that opens next:
  • Variable: Player Region ID
  • Info Type: Region ID
  • Location: Designation with variables
  • X: Player X
  • Y: Player Y




After that your common event should look like this:



What this is doing: The event saves the value of the X-coordinate of the player's position into the first variable and the Y-coordinate into the second variable. The third line grabs the Region ID of a tile and we specifically tell the event to determine what tile to use by using two variables as coordinates. Since our variables contain the coordinates of the player's position, the event grabs the Region ID the player is currently standing on.
Rules for Region IDs

Create a new event on the map that you want to use Region IDs on.
Set it's trigger to Parallel Process and add our common event to the event code.





Now all you have to do is add a new conditional branch that checks, if our third variable (Player Region ID) equals the value of the Region ID you used on the map. (In our case Region ID = 7)


If the player stands on a tile that is labeled as Region ID 7, the conditional branch is true and the event will run its content: In this case moving the player a tile back


In this Region ID Check event you can add as many conditional branches as you want. That way you only have one event that'll handle all the Region IDs and what happens if the player steps on a tile with a Region ID.



Edit
Thanks for the positive feedback. Someone pointed out that a constant parallel process can make the gameplay a bit laggy, especially on mobile devices. You can fight that by adding a Wait operation at the end of the event. Make the event wait a couple frames before it starts checking again.


Users Cxero and Ghost have pointed out a much faster way to do this. You can also just create a conditional branch with a Script command. Paste the following script into the window:
$gameMap.regionId($gamePlayer.x, $gamePlayer.y) === z
and replace the z with the Region ID you want to check for.

-------------------------

User RainbowBlade mentioned a way to keep things even more efficient than previous methods. You can make the interpreter look directly for the Region ID of the player. For that you have to use the script:
$gamePlayer.regionID == x
in a conditional branch. As you can see, there're many ways to solve a problem in RPG Maker which makes it just more interesting!

Thanks everyone for the kind words and additions to the guide!
51 Comments
malobebote 28 Oct @ 3:37pm 
> $gamePlayer.regionID == x

In MZ, this would be `$gamePlayer.regionId() === x`. In know this is for MV, but I randomly found this on Google.
tcforsdike 6 Oct @ 6:59am 
nice
almightybooda 5 Aug @ 4:13pm 
So I'm not sure if it's just me, but I can walk right through the region. This only seems to push me back if I stop moving forward on the region. This makes it great for hills or maybe conveyor belts, but not so much for a hard wall.
ChimaereJade 6 Oct, 2023 @ 3:10pm 
Hey there, thanks for the tutorial! I was looking for a way to adress regionIDs in an easy and efficient way. The last snippet need a little edit then it works:
"$gamePlayer.regionId() == x"
Mac Killer 96 30 Oct, 2022 @ 2:11am 
You said that many creators dont use them... Well, guide is long, we need search long guides like this instead RPG Maker having some tutorials inside the sofware... Thanks for tutorial but i bet you didnt learn in the sofware, also needed check external guides for know how use them.
Aijane 21 Feb, 2022 @ 4:06am 
The second to last code worked perfectly fine in MZ, but the last one didn't work at all. Maybe it was an MV only script, or maybe it was just me, but yeah, if you're on MZ and the last one doesn't work, try the one before it. Thank you very much <3:steamhappy:
randomness5555 2 Dec, 2021 @ 6:56am 
Thanks, very helpful! I've been trying to setup a system where shadowed areas of the ground will force an encounter every time the player steps on them and this was the missing part to getting it to work.
Aarodar 26 Nov, 2021 @ 9:47am 
@thesja
Sounds good I'll do it asap on my game :)
I Am El Poopio 23 Nov, 2021 @ 10:45am 
I had bought MV years ago and only in the last month really got into it and finally started making my game/ This post was one of the first I read when learning and glad I did! TY!
thesja  [author] 23 Nov, 2021 @ 7:43am 
@Aarodar
I'm not sure if I understand your question correctly. You're wondering if there is any downside to this? Well it sure does block 3 variables and a common event slot. But that's all. It does not interfere with your other variables.