How do you make a Spike Trap?

I decided to make a simple spike trap. Seemed easy enough. Toggle a switch to make the spikes go up and down. On the "spikes up" page, a player or event touch triggers and damages the party. Only problem is, it doesn't seem to work like that. If you're standing on tile when the spikes go up, nothing triggers. Nothing happens.

So I tried a few other things that revolved around parallel processes and checking to see if the player was standing on a square with spikes while they were in the up position. It sort of worked but it triggered so many times that it pretty much kills you. I really only want it to apply the damage once. There also seemed to be a lag issue as I'd get damaged even when the spikes were down sometimes as if the image swap was behind. Tried adding in some waits but that just made things even more inconsistent.

This is typically where I start writing a plug-in to make my life easier but I wanted to ping the community to see if there was some simple solution that I'm overlooking. This is a standard enough thing in RPGs that the default RTP includes these spiked floor event tiles so I'm thinking there probably some fairly easy way to do this.

So yeah, how do make this kind of spiked floor trap work?
I would use RED_SetRegionID and YEP_RegionEvents myself. Check out my disappearing platform tutorial it's the same principle.

https://forums.rpgmakerweb.com/index.php?threads/simple-disappearing-platform-tutorial.78655/

You could conceivably change the region for only say 1 or 2 frames or have it change once triggered with a variable... I don't know haha, I would have to be actually writing the event.
You seem to be over complicating it.
Simply an event with 3 pages will do for the trap and 2 for the switch.

Spoiler: Spike Trap Event Page
stp1.PNG
stp2.PNG

stp3.PNG

Spoiler: Switch Page
tsp1.PNG

tsp2.PNG

Heres the logic sequence.

if trap is not turned off
  • page 1 - graphic spikes off, player touch, turn on spikes event.
  • page 2 - graphic spikes up, autorun, inflict damage, move player backward, turn off spike event, wait for time (in the above SS 10 frames)
if trap is turned off via switch
  • page 3 - graphic spikes off, do nothing.

Switch logic.
  • page 1 - graphic switch off position (left in my images above), action button, turns on the switch and off the trap.
  • page 2- graphic switch on position (right in my images above), action button, turns off the switch and on the trap.

When you press on the switch while its off, it turns off the trap and the player can walk freely through.
What I was trying to do is make the spikes go up and down on their own but only damage you if you are running across them while they pop up. I like this idea and may switch to it for simplicity sake but it doesn't exactly do what I was trying to accomplish.
Is this what you mean?

@Frogboy - So the spikes are moving automatically not on player touch? Like in the above video, you just need a couple of parallel processes and track location variables.
I figured it out! Thank you @Frogboy, I love a good challenge. Here, it works perfectly.

spike floor 1.png
spike floor 2.png


This uses RED_SetRegion.

Very good by @just1witness

If you don't want to use the plugin here's how I do it.

Set up a blank event in the corner of your map. I called it tracker event.
TrackerEventPg1.PNG

Simply use these 2 pages on your trap. All the work is done above.
trappg1.PNG trappg2.PNG

The reason I like the above method is you don't have to change anything, region setting, location or anything at all if you simply move the trap around because of changes to the map etc...

You can just drag the map trap where you want on the map and it will still work with no tweaking required as the tracker event searches for the location of the spikes and doesn't rely on any other location (except the players). As long as the switch is on and the players X =traps X and the players Y equals traps Y, it will always trigger. I set it to turn off the switch after it hits once to stop the infinite hitting you were getting in your original post.

Note: If your using more than 1 spike trap than the region method is far more effective.
Very cool! @padr81
Yep, that's pretty much what I was trying to do. The only issue with this method is the need to manually enter the location of the event. If you want to move it or copy and paste it somewhere else, it'll break. But it should be fairly trivial to grab the event's location and feed it to the set region id plug-in.

Padr's method is very close to how I was trying to do it. I overlaid a region id on my spike traps to get the location easier because I was planning on using a bunch of them. From the looks of it, I messed up by not turning the spikes switch off of you get stabbed by them so they basically just stabbed you to death.

Thanks for all the input, you two!
Yep, that's pretty much what I was trying to do. The only issue with this method is the need to manually enter the location of the event. If you want to move it or copy and paste it somewhere else, it'll break. But it should be fairly trivial to grab the event's location and feed it to the set region id plug-in.

Thats why the variable method works imho. You can even have the trap follow the player, I actually stole the set up I used from an old event where the player was chased by flames that turned on and off. You don't need to enter location but unfortunately you do need to set up a seperate tracker in the tracker event for every spike trap so if you have 10 on a map that going to be annoying lol. You can though just copy and paste in the event.

With the regions you need locations so its 6 of one a half dozen of the other on which works best.

If your maps are final than regions all the way, if your likely to be moving events, changing maps etc.. then I would go with my method.
Thanks for all the input, you two!

No problem! It was fun to figure out and now I have a ready set spike event for my game, haha!
So I've actually come up with an easier way using Yanfly's Region Events, it works like Just1witness but one event will cover all traps. Gives a minute and I'll get it up and running.

Scratch this.. Found a simpler way posted below.
All I used the region for was to see if you were standing on that region id when the spikes activated. It was just an easier way know where all the spike traps are that didn't require using a lot of variables.
So I've spent too much time on this but I got it quite simple in the end. You can now put in as many traps as you want. Just need to draw the region under every trap.

No plugins, no event locations, no having to enter co-ordinates and no common events. Only one tracking variable set up through "Get location info" for every trap. and the usual tracking of players X and Y co-ordinates.
  1. Set the trap up as I did in my last post.
  2. Set your parallel process event up like the following image.
Capture.PNG


Now wherever you put a trap event just color it with region 1 and thats it. You'll have to add nothing bar the actual traps and paint them region 1.
If you wish to change the region just change the conditional branch
varRegionIDtrack = x , "x" being whatever region you want to use.

Additional Note - If you want more realism where the player doesn't get hurt from hitting the side of the spikes, simply set page 2 of the spike event to "same as characters" in priority.

Working in full flow.
Why not encapsulate everything in the Tracker event and leave the Spike events empty?

snap.png


Edit: Just realized that my Tracker event was called "Spikes". Sorry for the confusion. 😅
@Frogboy - Even better. That way will allow for you to do things with the spikes with the action button. For example have the player stand beside the event, when the spikes pop up (providing they are same level as character) pressing the action button could smash them etc...

Or the player could roll a boulder on top of them when they are down. Then when they pop up they would break, although thats more variable management.
It's crazy how close I was to making this work before coming here. The two things I did wrong was not turning the Spikes switch off when you got hit and using a global Background Processes parallel event to track the players position. I always do the latter anyway but there's a 20 frame delay in it to avoid bogging down my game. That caused a lot of the inconsistencies because it can sometime be behind by just a little.

But I'm glad I did post this. I think this will be useful for a lot of people looking to do this or something similar. Thanks again for all the help!
Yeah, I've actually put what we came up with here into one big file and put it in a thread over at tutorials, which should be approved soon hopefully.

To be honest anytime I've done this before I've used 2 seperate variables for every single spike trap yet strangely for the event where I have fires I was doing it the correct way.
Sweet! An official tutorial is even better.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-you-make-a-spike-trap.79712/