Region Common Events, but with "Same as Character" Priority

I have a map that uses a ton of events (all of which actually just say "Call Common Event"). I would like to get rid of these events in order to reduce lag, and perhaps replace them with region events (or something else if someone has an idea). I've attempted to use Yanfly's Region Events but in this plugin, the player needs to be on top of the tile. I don't want the player to be able to walk on top of this tile, and I'm not sure how to change the priority system to "same as character" in the javascript.


For example, I have a dungeon full of Spiked Walls. I don't want the player to actually walk on top the wall to be damaged, and they can stand next to them safely enough, but when they try walking into wall, I'd like a common event to run. Again, it works fine with events, but I'm hoping to see if I can reduce some clutter a bit.


Thank you!
Perhaps looking at how Shaz dealt with this in her Ace script might give you some ideas.  For that script there is the 'standing on the tile' option, but there is also 'facing' the event as an option as well - useful for events on e.g. a cliff wall.
I think I have another approach, but I'm not sure if it will stutter the game or drop FPS.


Let's suppose you have a room like this


xxxxxxxxxxxx


x51111118x


x2000003 x


x2000003 x


x6444447 x


xxxxxxxxxxxx


Where "x" is a spiked wall, and the numbers are floor tiles.


If you create those following common events:


1) Activated when stepped on region 1 -> Turns switch [10 ON] [11 OFF] [12 OFF] [13 OFF]


2) Activated when stepped on region 2 -> Turns switch [10 OFF] [11 ON] [12 OFF] [13 OFF] 


3) Activated when stepped on region 3 -> Turns switch [10 OFF] [11 OFF] [12 ON] [13 OFF]


4) Activated when stepped on region 4 -> Turns switch [10 OFF] [11 OFF] [12 OFF] [13 ON]


5) Activated when stepped on region 5 -> Turns switch [10 ON] [11 ON] [12 OFF] [13 OFF]


6) Activated when stepped on region 6 -> Turns switch [10 OFF] [11 ON] [12 OFF] [13 ON]


7) Activated when stepped on region 7 -> Turns switch [10 OFF] [11 OFF] [12 ON] [13 ON]


8) Activated when stepped on region 8 -> Turns switch [10 ON] [11 OFF] [12 ON] [13 OFF]


0) Activated when stepped on region 0 -> Turns everything OFF


Where...


Up hurts = switch 10


Left hurts = switch 11


Right hurts = switch 12


Down hurts = switch 13


And then you create another common event (parallel process) that check for collision. (pseudo-code below)

Code:
if ((switch 10 is ON) AND Input.isTriggered('up') ) then DAMAGE

if ((switch 11 is ON) AND Input.isTriggered('left') ) then DAMAGE

if ((switch 12 is ON) AND Input.isTriggered('right') ) then DAMAGE

if ((switch 13 is ON) AND Input.isTriggered('down') ) then DAMAGE
This is just me thinking out loud, and this could get eventing hectic, but you could contain it to one event by paralell process: Set variables playerX and playerY equal to player x position and y position on the map, and then... underneath, if (for example) playerX is 6 and if playerY is 7, then if up or left is pressed (for example, it's a corner where either direction would touch spiked walls) then call common event. That could be a lot of work depending on how many squares there are where this possible. And I assume there's a lot because you're asking this. Also, you would probably need to use javascript script call to take into account both IsPressed and IsTriggered, as these are different things. And, you'd ahve to make these if statement conditional branch trees of if X is, if Y is, if button is both pressed and trigger for every possible square in the same event.

That sounds like not the solution you are looking for, but maybe it will jog someone's thoughts. My first thought was to combine Region Restrictions with Region Common Events but I don't see that as making this possible.

Plugin request?

Anyway, hi L.
I know IsPressed omits the possibility of IsTriggered, but does IsTriggered contain both Triggered and Pressed?
@Crabs Thank you for the detailed response! Awesome! I'm thinking having that many common events being triggered while the player is walking around the room might hurt, but I am using your ideas to see if I can do something. Mainly seeing how how Input.isTriggered or Pressed will work. I think the solution is in there somewhere!


@Zaen! Heya dude 😀  Yeah interesting thoughts, but I'm worried about how to retroactively edit these events whenever I change the map. 
@Zaen! Heya dude 😀  Yeah interesting thoughts, but I'm worried about how to retroactively edit these events whenever I change the map. 



Yeah, I use this method for various things a lot, by tracking player position. But it's definitely not a thing to implement in large quantity until you're certain.
So I made the common event if player is facing left, AND Input.isPressed 'left', then do "this." The region is right in front of the wall. It works! But not reliably. When running into the wall, it works. When I slowly walked up to it, it doesn't. I tried both Pressed and Triggered and neither are perfect.


I can deal with it being unreliable (I simply back off and run at it again), but I'm not so sure my users will have the same patience.


Edit: So obviously it doesn't work when I'm being slow because the plugin will fire the event immediately, not continuously. So I'm gonna figure out some switches to use a parallel process! Stay tuned ;D
Did you try either pressed or triggered, or pressed AND triggered... because the latter would omit a possibility.
input.isPressed returns true when the player holds the button


input.isTriggered returns true when the player just pressed the button.


If you chose "isPressed" to check input, the game will execute the conditional branch multiple times when you press the button. "isPressed" is useful when you want the player to hold the button to charge something, for instance.


For most cases it's more advisable to use "isTriggered".


Here's a reference (refer js library > input for more info.): https://rmmv.neocities.org/
Code:
/**
 * Checks whether a key is currently pressed down.
 *
 * @static
 * @method isPressed
 * @param {String} keyName The mapped name of the key
 * @return {Boolean} True if the key is pressed
 */
Input.isPressed = function(keyName) {
    if (this._isEscapeCompatible(keyName) && this.isPressed('escape')) {
        return true;
    } else {
        return !!this._currentState[keyName];
    }
};

/**
 * Checks whether a key is just pressed.
 *
 * @static
 * @method isTriggered
 * @param {String} keyName The mapped name of the key
 * @return {Boolean} True if the key is triggered
 */
Input.isTriggered = function(keyName) {
    if (this._isEscapeCompatible(keyName) && this.isTriggered('escape')) {
        return true;
    } else {
        return this._latestButton === keyName && this._pressedTime === 0;
    }
};

/**
 * Checks whether a key is just pressed or a key repeat occurred.
 *
 * @static
 * @method isRepeated
 * @param {String} keyName The mapped name of the key
 * @return {Boolean} True if the key is repeated
 */
Input.isRepeated = function(keyName) {
    if (this._isEscapeCompatible(keyName) && this.isRepeated('escape')) {
        return true;
    } else {
        return (this._latestButton === keyName &&
                (this._pressedTime === 0 ||
                 (this._pressedTime >= this.keyRepeatWait &&
                  this._pressedTime % this.keyRepeatInterval === 0)));
    }
};

/**
 * Checks whether a key is kept depressed.
 *
 * @static
 * @method isLongPressed
 * @param {String} keyName The mapped name of the key
 * @return {Boolean} True if the key is long-pressed
 */
Input.isLongPressed = function(keyName) {
    if (this._isEscapeCompatible(keyName) && this.isLongPressed('escape')) {
        return true;
    } else {
        return (this._latestButton === keyName &&
                this._pressedTime >= this.keyRepeatWait);
    }
};
@fallenlorelei


In the worst case scenario you could split your dungeon in many tiny maps - if the main issue is the mess or performance - and use "player touch" events on spiked walls. I know it's not a good option for you since I know from your YT channel that you use parallax mapping, but it's better than releasing an unpolished-looking game, IMO.


But I'm pretty sure you can make it work properly only with events.


Sumrndmdde also has a plugin that checks collision. It won't solve your issue directly but it might be useful for you.
That's actually a super interesting plugin, @Crabs. I think I can find some use for it!


So actually, my problem isn't for "spiked walls." I thought that was a good example for what I need, but apparently saying that wasn't a good idea haha. My project is actually a tile-based sidescroller.


Sidescroller3.gif


Basically I have these "jump" and "fall" events for all tiles that are only 1 tile high. Clearly, I'm gonna have a ton of these events.


Unfortunately the regions aren't working because I can "fall" on a "jump" tile and then end up jumping and getting stuck in the void. I think I'm stuck using events or waiting for a "same as player" region touch event.


Thank you guys for your help! Input Pressed worked! (not triggered actually). But then I realized the fault in my logic.
Oh... I wasn't expecting a system like this. I though you were trying to make a gimmick dungeon. Amazing system!


In your case it's a good idea to make a plugin that changes "map_scene" to make your system run more smoothly. Then you will be able to implement very accurate physics and input for your game.


Also check this plugin. I'm pretty sure you will make a great use of this! 🙂   https://galvs-scripts.com/2016/09/13/mv-map-projectiles/
Thanks for trying @Crabs, I appreciate it!! Its actually a very simple common event that checks if they're facing a certain way and then using the Jump command =] The events are player-touch/same as character. For falls that are more than 1 tile, I simply specify a variable for the amount of tiles - but I think I can use Sumrndmdde's collision checker for it!


But yeah, I neglected to say I was sidescrollin' in an attempt to keep things simple haha. I'm gonna keep this post here to see if someone has any ideas! But will continue using events in the meantime I suppose! Thanks again 😀

Original thread: https://forums.rpgmakerweb.com/threads/region-common-events-but-with-same-as-character-priority.73428/