Ha! This time I stumped a few more of you, but a few of you managed to find a solution that worked. The best solution I saw from fans was conceived by Ryan Neal, who came up with a good solution on our Facebook page. It wasn’t the exact solution I used, but some parts were better and some parts were worse than how I had originally did it. In fact, the solution he came up with inspired me to come up with a third way to do it that is probably the MOST elegant of the bunch. It’s cool that through these challenges, I manage to learn a few things, too!
But anyway, let’s get on to the solution. (If you don’t remember what we were attempting to do, head back to Challenge 3 for a full explanation!)
Step 1: Creating the Spike Traps Events
There are a bunch of small missteps you can take on the spike traps themselves. The first one is thinking that you need to have the spike traps actually do the knockback, or have them control when they go up and down. Here is why I suggest against it:
- Move routes to make them go up and down can lead to some issues when you have a larger map of some of them getting out of synch.
- Player Touch/Event Touch only activate on first contact, so if you are ALREADY standing on the event when it switches pages, it won’t register to activate.
- Using each one as a parallel process is an EXTREME number of checks and can cause slowdown, on top of being illegal for this challenge.
So what am I doing with the spike trap events themselves? Only the graphical representation. There will be no timing with them at all.
To do this is several easy steps. Each one has two event pages, with no event commands, as technically they NEVER trigger. First page has no conditions, second page has the condition of Switch Spikes1Active On for the set that alternate every second, or Switch Spikes2Active On for the set that alternate every 0.75 seconds.
In the Move route, select custom, crank the frequency and speed up to max, and then go into the custom move route and on page 1 create the turns to make the spike trap animate going down, and on page 2 create the turns to make the spike trap animate going up. Make sure to put in some waits so that its a visible animation. MAKE SURE YOU UNSELECT REPEAT ACTION. If you have repeat action on it will cause it to repeat the animation over and over instead of doing it once per cycle.
This is literally all you need to do on the Spike Trap Events. No joke, its that simple. Just copy paste all the ones that go with the 1 second interval and paste them where you want them, and repeat for the 0.75 second interval ones.
Step 2: Setting RegionIDs
And here you thought RegionIDs were just for setting enemy encounters! RegionIDs have a lot of uses in RPG Maker because they can be checked by events. It makes doing a lot of checks much much simpler.
For this setup we need 4 RegionIDs. Why four? We have a total of four types of spike traps:
- Spike traps that alternate every second and knock the player South during steps 1 and 3.
- Spike traps that alternate every 0.75 seconds and knock the player North during step 2 and South during step 3.
- Spike traps that alternate every second and knock the player North during steps 1 and 3
- Spike traps that alternate every 0.75 seconds and knock the player South during step 1 and North during step 3.
So take RegionIDs 1-4 and then draw them underneath the spike traps.
During this step, you could have easily added in some traps that knocked east and west, they would have just needed their own RegionIDs. I had planned the scenario on purpose though to use as few as possible and still remain challenging. Adding in 2 more directions would add 4 more RegionIDs and a good bit more work.
Step 3: Switches and Doors!
Now that we have the Spike traps down, let’s lay down some simple switches. The switches should be fairly simple, they just control the flow of the scenario. You can use 3 Switches or 1 Variable for this part. I used the switches as I wasn’t exactly in fear of running out in a short demo. But instead of having Door1, Door2, Door3, you could easily just set a Variable for 0-3 as the order is linear and the switches can’t be flipped out of order.
Each switch has 2 pages, the first one is an Action Button trigger event page that does the animation of it turning (along with the sound effect of the switch turning and the door opening) and switches its corresponding switch, and a second blank page of it flipped with the condition of its switch being on.
The Doors are incredibly simple events. All they need to be is same as character priority with no event commands for page 1, and a page 2 that has a below characters priority and a custom move route similar to page 1 of the spike traps to animate it going down that has a condition of its switch being turned on. REMEMBER TO HAVE REPEAT ACTION TURNED OFF ON THE MOVE ROUTE.
Step 4: The Control Event!
Ok, this one is the big daddy. It has to do EVERYTHING, so this step will be broken down into parts. Here is a list of all the things we have to make the Control Event capable of doing:
- Track through the separate stages of the event. From 0 doors open (Stage 1) all the way to all 3 doors open (Stage 4).
- Alternate Switch 0001:Spikes1Active every 1 second during Stage 1 and 3.
- Alternate Switch 0002:Spikes2Active every 0.75 seconds during Stage 2 and 3.
- Determine what RegionID the character is standing on at all times.
- Knock back the character in the correct direction if that RegionID corresponds to the RegionID of a currently active Spike Trap.
So let’s break it down by those parts.
Step 4a: Tracking Each Stage of the Event.
This one is super simple. Just give the control event 4 pages. The first page has no conditions, the second page has the condition of the Switch for Door1 being on, third has the condition of the Switch for Door2 being on, and the fourth and final page has the condition of the Switch for Door3 being on. Remember that Ace will always use the RIGHT MOST event with all conditions met. Its important to put the event pages in this order!
Step 4b: Alternating the Spike1Active and Spike2Active Switches.
The first though I’m sure would be to set this within the parallel process of the page, but I think its best if we don’t do that. Placing long waits in the loop of the parallel process can cause it to not check other things it needs to check, and doing it with short waits will cause you to have to use variables and arithmetic to keep track of when to turn them off.
But then where can we put it? One of the things that many people overlook is that move routes can manipulate switches! Go switch all four pages to custom move routes.
Now for page 1, we need to have Switch 0001 alternate on and off every 1 second. This is easy. Multiply the number of seconds you want by 60 to get the number of frames to wait, and then create a move route on page 1 that waits 60 frames (1 second * 60 frames/second) then turns Switch 0001 on, then waits 60 more frames and turns Switch 0001 off.
Page 2 is equally as easy. Create a move route that waits 45 frames (0.75 seconds * 60 frames/second) then turns Switch 0002 on, then waits 45 more frames and turns Switch 0002 off. I also added a Switch 0001 off command at the beginning of each loop, to account for the fact that Switch 0001 could have been on when this page was activated.
Page 3 is a bit more complex! How are we going to keep track of two different loops? Easy, every 6 seconds, Switch 0001 will have turned on and off exactly three times, while Switch 0002 will have turned on and off exactly 4 times. This means we can create a 6 second loop to have it synchronize with each other perfectly. Let’s figure out those wait times!
So for Page 3, we can go through the above chart, select the appropriate wait times from the center, then alternate switches as necessary. Instead of switching off Switch 0002 at the very end, I instead put it at the beginning. Since it loops, this behaves identically, but it also catches turning it off if it was on when this page is activated.
Page 4’s move route only needs to do one thing. Turn off the switches in case they were active when the event page started. As such, all you have to do is have it do Switch OFF: 0001, Switch OFF 0002 and deselect repeat action. It only needs to do this once!
Step 4c: Determine RegionID the character is standing on.
This will need to be done for Pages 1-3 of the Control Event. No reason to do it on Page 4, as all the spikes will be inactive then. Anyway, switch Pages 1-3 to Event Trigger: Parallel Process. We want it to be doing this constantly while the player can still move around.
Parallel Processes automatically loop. Once it finishes once, it will repeat back to the beginning. So let’s use that loop to update the information of where the player is continuously.
Now, we are going to save the player’s x, y, and current RegionID to three variables. This is so useful I would suggest just setting the first 3 variables aside for this in every game you ever make. I would also suggest going ahead and making this a common event so you can reference it faster, which is what we will do in this Tutorial.
Open up the database and head over to the Common Events tab. I’m going to create a common event in slot 001 called X/Y/RegionID.
In the commom event use a Control Variable command to set Variable 0001 to GameData: Player’s Map X. Then use another Control Variable command to set Variable 0002 to GameData: Player’s Map Y.
Head over to the third tab of the event Commands and look in the Map subsection and put in a Get Location Info command. In Variable 0003, Grab Info Type: RegionID using Designation with Variables: Map X: 0001, Map Y: 0002.
Head back over to your Control Event, and underneath the Wait 1 Frame command on pages 1-3, add the Call Common Event command: 001:X/Y/RegionID.
Now the first three pages will check where your player is at all times! Let’s put that to work.
Step 4d: Knockback the Player When he is on an Active Trap.
Let’s start with Page 1 since it and Page 2 are both the simplest. After the Common Event Call, add in a conditional branch that checks to see if 0001:Spike1Active is on. There is no reason to check anything else if its not on, as the player wouldn’t be knocked back anyway.
If that Conditional Branch comes back as True (0001:Spike1Active is on) we then want to check if the Player is on RegionID 1. To do that, just add in a conditional branch that checks if the Variable 0003 is equal to 1, since we are updating that Variable every loop with the RegionID of the Player.
If this one comes back true, we want to knock the player South. I did this with the Jump move route, because I thought it looked cooler. Set it to Jump the Character’s Y +1.
If this one comes back FALSE, we want to check and see if the Player’s Region ID comes up as 3, the other RegionID set to this set of Traps (If you are wondering why we nest this, its simple, If it comes back as Variable 0003 is equal to 1, it can’t very well equal 3 as well can it?). In this grouping, we’ll set the Jump to Character’s Y -1.
Below shows both a flowchart, and in editor view of the event page:
For Event Page 2, just change it to check for Switch 0002: Spikes2Active, and RegionIDs 2 and 4. Also make sure you are knocking the player’s the right direction! Here is the flowchart and editor view of this page:
For the third page, all we are doing is combining the checks in page 1 with the checks in page 2, and switching which direction the two RegionIDs on page 2 knock the player. And here again, more flowcharts and editor views!
Step 5: Sprucing it up.
We can easily add some extra things to this now. For the simple version, I ran around adding a few sound effects and graphical effects.
First, head into your Control Event. Before each Move Route that jumps the player, add in a red screenflash! I also added in Sound Effect: Slash1 into each of the Jump move routes.
You can also add sound effects to the Spike Traps moving. Grab one of the Spike traps that alternates every 1 second (not all of them, you only need the sound to play once) and go into the move routes. Select on sound effect for when it activates and play that one in the move route on Page 2 (I selected Key), and then you can make another sound effect play when it goes down by adding it into the move route on page 1 (I selected Switch1).
Then repeat the process for ONE of the Spike trap events that alternates every 0.75 seconds.
Also, we can add a Victory Event. I set this to Priority: Same as Characters, Event Trigger: Player Touch and put it right above the top of the ladder. Then I added the following commands:
Play ME: Victory1
Text: You Win!
Return to Title Screen.
You can add plenty more to this simple spike trap demo, but this is where I am stopping the tutorial! There are two versions of this demo in the download. One is the demo exactly as described in this tutorial. It is labelled Spike Trap Demo Simple. The second is a more advanced demo that adds lose conditions! Both lives and a timer are added. It is labelled Spike Trap Demo Advanced. You can open either in the editor to get a better idea of how I did everything! You can download both by clicking the button below:
Wow! That one was a mouthful! Did you learn anything along the way? Any questions? Have some ideas on how to use some of the techniques in this tutorial to make your game easier to make? Join the Conversation in the comments section below! And as always, happy RMing!