As a continuation of the Fun With Variables tutorial, I thought I’d try something a little different.
What if you wanted to create a simple but effective event-based map teleporter? Of course, a more complex teleport system is possible using scripts, but for the purposes of keeping things simple, events are better.
This will work in RMXP and RMVX, although not the same way in RM2K3.
To achieve this, we’ll need to create 4 variables:
- 0001: Randomize
- 0002: Coord-X
- 0003: Coord-Y
- 0004: Map ID
Next, we’ll need our maps to teleport between. For this tutorial, we’ll be using two maps and teleporting (randomly) between the two. Let’s create the first one, setting the dimensions to their minimums – 20×15 (RMXP) and 17×13 (RMVX). Make a note of these numbers (the maximum x-value and y-value), as we’ll need them later.
In the centre of the map, create an event (called Teleporter or something similar) with an appropriate graphic for the Teleporter event. This can be a path tile or animated event graphic, or it can be blank for the element of surprise. Set the “Trigger” to “Player Touch”. In RMVX, you might want to set the “Priority” to “Below Characters” as well. Leave the Event Commands blank for now; we’ll come back to that shortly.
You might also want to place a flower tile or event or other feature to distinguish this map from the second one. Simply copy and paste this first map, then change the flower tile, event or feature to something else. That way when teleporting between the maps you’ll know which one you’re on.
In the Database, create a Common Event, called something like Teleport. In the Events Commands, we’ll need the following:
- Set the variable Randomize to a number between 0 and the maximum x-value (from earlier), subtracting 1 because the coordinates actually start at 0, of the map. (If in doubt, in the Events Mode click on any of the right-most squares and note the first number.)
- Set the variable Coords-X to Randomize.
- Set Randomize to a number between 0 and the maximum y-value from earlier, again subtracting 1, of the map. (If in doubt, in Events Mode click on any of the bottom-most tiles to note the second number.)
- Set Coords-Y to Randomize.
- Finally, “Transfer Player” to their corresponding map and x/y coordinates. Select “Appoint With Variables” (RMXP) or “Designation With Variables” (RMVX). “Map ID”, “Map X” and “Map Y” is set to their corresponding variables (i.e. 0004: Map ID, 0002: Coords-X and 0003: Coords-Y respectively.
Before we can do anything, we’ll need to go back to the Teleport Events on both maps and in the Event Commands, add a “Call Event” set to our “Teleporter” event from the Database.
When the game is run, every time the player steps on the “teleporter” it will transfer him to a random location on either map. If you added a distinguishing tile or feature to the map, you’ll be able to tell which map you’ve been transported to.
One possible application for this could be for a maze-like series of maps, adding switches to the Event Commands according to which map you’re on to trigger other events. In the next Fun With Variables tutorial – whenever that will be – I think I’ll expand on this idea and create a map maze similar to the ones used in several Zelda games.