Terrain tag of tile in front of player

Started by Karltheking4, January 18, 2011, 12:24:49 am

Previous topic - Next topic

Karltheking4

I was wondering if anyone knows how to check the terrain tag id of the tile directly infront of the player?
At the moment I have an invisable event going to the spot in front of the player, and check it's terrain tag like that, but I'm guessing there is a simplier and probably more lag free way of checking the tile in front, but I can't find it for the life of me!

The second (kind of related) question, is how can I get the player to stop moving for a second? The closest I've got is a move route with a wait 4 frames command in it, I think it was working, but it doesn't want to do anything anymore :/

Thanks :)

ForeverZer0

Place this below Game_Player.
The variable you define will always be equal to the terrain tag value of the tile in front of the player.

class Game_Player
 
  TERRAIN_VARIABLE = 45
  # Set to the variable that will store the terrain tag of the tile
  # directly in front of player
 
  alias check_front_terrain check_event_trigger_there
  # Have variable refresh every time player takes a step.
  def check_event_trigger_there(triggers)
    # Get coordinates of the tile in front of player.
    front_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    front_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # Set defined variable to its terrain tag value.
    $game_variables[TERRAIN_VARIABLE] = $game_map.terrain_tag(front_x, front_y)
    # Call normal method.
    check_front_terrain(triggers)
  end
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Karltheking4

It would have been enough to tell me you can use this:
$game_map.terrain_tag(front_x, front_y)

But thanking you greatly for the code aswell :)