Help: Events only trigger from one side

Status
Not open for further replies.

lucofthewind

Suikoden FanBoy
Veteran
Joined
Dec 11, 2012
Messages
213
Reaction score
17
First Language
English
Primarily Uses
Hello, I'm looking for help in creating events that only trigger when touched from one side, be it left or right side, but not top or bottom.

As example: One of the things I am trying to set up is a moving wall, in a maze. Said wall will shift back and forth in a attempt to crush the player. If the player would touch the wall from the front, the event would still trigger, crushing them when obviously they were not. So my question is, is it possible to set up a event so it only triggers from a certain side (not from the direction the player is facing, as I saw in other threads).

Thanks for any help!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
you don't change the trigger, but you'll need to change the effect.
When triggered, have the event use conditional branch to check the player facing, that will tell you from which direction the player tried to trigger the event.
Then give different effects depending on what that direction is.
 

lucofthewind

Suikoden FanBoy
Veteran
Joined
Dec 11, 2012
Messages
213
Reaction score
17
First Language
English
Primarily Uses
Maybe Im not understanding this right, so Ill write out a quick thing, and go from there.

The moving wall
|---------|
| ------- |
|---------| x
Y


Assuming the wall is only going from left to right, and the player can only move forward. I would set the condition to if player is facing up. Or to prevent cheating, have it set to all directions when the player is in the X spot.

However, with it set like that, wouldn't the event still trigger if they touched the wall from the Y position? What I am trying to say is I only want it to trigger when event touches the player in the X spot, but not the y.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
the event always triggers, and there is nothing you can do to change that - and there is nothing you should change in that regard.

what you change is the effect depending on the direction. And yes, you need to set every direction for an effect.

and that effect will be nothing if the player is in direction Y, and kill him or hurt him if he is in direction X.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
So it triggers by touching the player, not by the player touching the wall, so the player could be facing any direction.

I would use regions to draw along the path where the wall moves, and when the event triggers, check to see if the player is standing on a tile with that region.

Code:
Control Variables 25: Game Data > Other > Player's Map X
Control Variables 26: Game Data > Other > Player's Map Y
Get Location Info: Region from variables 25 and 26 into variable 27
Conditional Branch: Variable 27 = 8 (the region you used to draw the wall's path)
  ... player is hit, do whatever needs to be done
End
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
What Shaz said looks like a very good way to do it, especially because it works no matter how far the wall goes so it is quite flexible.
However if you want to check player position when activating the event you could simply check the current facing direction (even if this is not what you want to use in this case it might be useful knowing it for a later date).
Example:
If you only want your event to trigger when activated from the right side you can use this
Code:
$game_variables[id] = $game_player.direction
and then put everything in your event in a conditional branch that checks that variable.

> Conditional Branch: variable[ID] == 4 (this means the player is facing left)
* > Everything goes here

This prevents all your commands from running when the player is not facing the right direction.

NOTE: direction is always an integer and its value is as follows.
DOWN = 2
LEFT = 4
RIGHT = 6
UP = 8
Keep in mind that checking region id only works if the event is set as Same as Characters priority. If not it might run when the player steps on (or below) it since in that case the region would be the same. Unfortunately the same happens if the player touches it from behind (I am not sure this can happen in your case) and this happens even if the event has the right priority. This is why - at least in my opinion - you should bring the region system a step further.
Probably the best way to prevent this might be using a common event to move your wall along a path made using regions and check if the player is standing on the next square before taking each step. This way it only triggers if the player is actually in the way and not just touching the event.

Use a parallel process to move your wall (the wall itself might be a parallel process event) and draw your path using regions. Use a variable to store your previous position (you don't want the wall to go backward unless there are other options, do you?).

Code:
ev = $game_map.events[your_wall_event_id]
unless ev.moving?
  prev = put_a_variable_id_here
  path = put_your_region_id_here
  $game_variables[prev] = [ev.x, ev.y] if $game_variables[prev] == 0
  prev_step = $game_variables[prev]
  next_step = prev_step
  step_dir = ev.reverse_dir(ev.direction)
  [2, 4, 6, 8].each do |dir|
    new_x = ev.round_x_with_dir(x, dir)
    new_y = ev.round_y_with_dir(y, dir)
    if $game_map.region_id(new_x, new_y) == path
      next if ((new_x == prev_step[0]) && (new_y == prev_step[1]))
      next_step = [new_x, new_y]
      step_dir = dir
    end
  end
  # at this point next_step contains your real next step
  $game_switches[pick_a_switch_id] = ((next_step[0] == $game_player.x) && (next_step[1] == $game_player.y))
  # this switch now tells you if the event is going to hit the player in the next step
  ev.move_straight(step_dir)
end
At the end of the code you can check that switch and put anything you want to happen when the wall hits the player in a conditional branch that only triggers if that switch is active. This should be completely safe and serve your purpose. It only runs when the event is checking its next step, it does not run if the event is still moving from its previous step and it only changes that switch value if the player is standing on the next square.

I always struggle to remember if you have to use round_x_with_dir or round_x_with_direction (similarly for y). Now I do not have access to the code since I am from mobile but if you open your scripts and look for it you will find an answer.
Of course everything is under the assumption that your wall could be touched from more than just a single square. If the example in your previous post (the player only being able to move vertically) is the real case then all this is just useless.
 
Last edited:

lucofthewind

Suikoden FanBoy
Veteran
Joined
Dec 11, 2012
Messages
213
Reaction score
17
First Language
English
Primarily Uses
Thank you so much to everyone who responded, and helped me getting this up and running!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top