Script that reads when a player is facing a wall

xChikyx

Villager
Member
Joined
Aug 7, 2019
Messages
17
Reaction score
0
First Language
English
Primarily Uses
RMXP
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 :D


EDIT FOR THE 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 :D
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
2,617
Reaction score
3,790
First Language
English
Primarily Uses
RMMV

I've moved this thread to RPG Maker XP. Please be sure to post your threads in the correct forum next time. Thank you.

 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
129
Reaction score
55
First Language
English
Primarily Uses
RMXP
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
 
Last edited:

xChikyx

Villager
Member
Joined
Aug 7, 2019
Messages
17
Reaction score
0
First Language
English
Primarily Uses
RMXP
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 :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Making it a rule that I don't do any world building for my new game before the actual gameplay is concrete and working. I have 16 years of lore to work with anyway.
Cheesy power metal makes everything better. No matter what you do, you'll feel heroic doing it.
Starting to really like the first of my madness areas. I think the eyes looking at them really helps to sell the place. :LZSexcite:
Made idle animation for character. It first had only three frames but looked too different from walking animation and I had to draw five more.
MV and VX Ace both have good qualities.

Forum statistics

Threads
95,694
Messages
931,075
Members
126,032
Latest member
MadAtticGames
Top