Script that reads when a player is facing a wall

Hi!
I'm currently working on a project using RPG Maker XP in a pretty complicated way. Anyway, I'm trying to create a global event that reads when the player is facing a wall. Is thre anything out there that already does so?
So far the only idea I have is to make a HUGE series of conditional branches in which, for each map, it checks the direction of the player is facing and its coordinates to see if next to a wall, But that is, first of all, insane, and, second, not efficient at all.

Is there any way to interact with the Tile Counters or Tile Terrains using a script maybe to know when I'm adjacent to (not over) them? For example, if I put a wall with a Tile Terrain indicator in 1, then if the player is adjacent to the wall, it would trigger the event.

This is what I have in mid (hope it makes any sense and it's possible):
If Character facing Terrain 1
if Distance between Character and Terrain 1 == 1
Facing Wall Switch = ON
end
else
Facing Wall Switch = OFF
end

If you know how to address terrain tags or counter tags on scripts please elt me know.
If you know a script that does this already please let me know too.
Any help is welcome.



EDIT: Never mind, I think I managed to make a script that does so... I'll put it in the comments in case anyone needs it 😀


EDIT FOR THE SCRIPT:
Spoiler: SCRIPT
class FaceWall
#Script by Sumerian Games
#Call with FaceWall.new

def initialize
if $game_player.direction == 2
viendox = $game_player.x
viendoy = $game_player.y + 1
end
if $game_player.direction == 4
viendox = $game_player.x - 1
viendoy = $game_player.y
end
if $game_player.direction == 6
viendox = $game_player.x + 1
viendoy = $game_player.y
end
if $game_player.direction == 8
viendox = $game_player.x
viendoy = $game_player.y - 1
end

terraintype = $game_map.terrain_tag(viendox, viendoy)
if terraintype == 0 #here the terrain type is the one in the tileset
$game_variables[25] = 0 #change the variable number here
end
if terraintype == 1
$game_variables[25] = 1
end
end
end

Usage:
Put in the terrain tab on the tilesets the Tiles you need to be as walls with a terrain number (in this case 1)
When you need it, call the script and check for variables. In this case, the variable 25. When the character is facing a wall, the variable will be set as 1. When not, it will be a 0.
Then, in the event you're calling the scrip, check for the conditions: If Variable 25 = 1, then do something when facing the wall.
It wasnt that hard to make actually. Hope you find it useful.
If you use it in your game, i'd appreciate a mention in the credits 😀

I've moved this thread to RPG Maker XP. Thank you.

Let me fix it up for you:
Code:
class Game_Player < Game_Character

  def get_tt_in_front
    dir = @direction
    nx = @x + (dir == 4 ? -1 : dir == 6 ? 1 : 0)
    ny = @y + (dir == 8 ? -1 : dir == 2 ? 1 : 0)
    $game_map.terrain_tag(nx, ny)
  end

  def facing_wall?
    !passable?(@x, @y, @direction)
  end
end
Script calls:
Code:
$game_player.facing_wall?
$game_player.get_tt_in_front
You can just use a Conditional Branch--4th tab for Script option--and put something like this:
Code:
$game_player.facing_wall? && $game_player.get_tt_in_front == 1
oh, that's much shorter hahah
I'm pretty new working with scripts, normally I have just really complex engines, but bot scripts. I'll see how yours work 🙂

Original thread: https://forums.rpgmakerweb.com/threads/script-that-reads-when-a-player-is-facing-a-wall.118453/