• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[v18] Terrain Tag Side Stairs

Boonzeet

Pokémon Secrets of the Ages Developer
188
Posts
15
Years
  • Boon's Terrain Tag Side Stairs​
    [v18] Terrain Tag Side Stairs

    A simple script to allow placing stair tiles that automatically perform as side stairs, with psuedo-depth effect and support for Followers.

    Might conflict with some scripts if they significantly alter Game_Player.

    Setup

    Version 18

    Copy this code above Main.

    Code:
    #-------------------------------------------------------------------------------
    # Boon's Terrain Tag Side Stairs
    # v1.2
    # By Boonzeet
    #-------------------------------------------------------------------------------
    # Sideways stairs with pseudo 'depth' effect. Please credit if used
    #-------------------------------------------------------------------------------
    # v1.2 - Fixed bugs with ledges, surfing and map transfers
    # v1.1 - Added v18 support
    #-------------------------------------------------------------------------------
    
    PluginManager.register({
      :name => "Terrain Tag Side Stairs",
      :version => "1.1",
      :credits => ["Boonzeet"],
      :link => "https://reliccastle.com/resources/397/"
    })
    
    #-------------------------------------------------------------------------------
    # Config
    #-------------------------------------------------------------------------------
    module PBTerrain
      StairLeft       = 19  # Set these to the terrain tags you'd like to use
      StairRight      = 20
    end
    
    #-------------------------------------------------------------------------------
    # Existing Class Extensions
    #-------------------------------------------------------------------------------
    def pbTurnTowardEvent(event,otherEvent)
      sx = 0; sy = 0
      if $MapFactory
        relativePos=$MapFactory.getThisAndOtherEventRelativePos(otherEvent,event)
        sx = relativePos[0]
        sy = relativePos[1]
      else
        sx = event.x - otherEvent.x
        sy = event.y - otherEvent.y
      end
      return if sx == 0 and sy == 0
      if sx.abs >= sy.abs #added
        (sx > 0) ? event.turn_left : event.turn_right
      else
        (sy > 0) ? event.turn_up : event.turn_down
      end
    end
    
    class Game_Character
      alias initialize_stairs initialize
      attr_accessor :offset_x
      attr_accessor :offset_y
      attr_accessor :real_offset_x
      attr_accessor :real_offset_y
     
      def initialize(*args)
        @offset_x = 0
        @offset_y = 0
        @real_offset_x = 0
        @real_offset_y = 0
        initialize_stairs(*args)
      end
     
      alias screen_x_stairs screen_x
      def screen_x
        @real_offset_x = 0 if @real_offset_x == nil
        return screen_x_stairs + @real_offset_x
      end
       
      alias screen_y_stairs screen_y
      def screen_y
        @real_offset_y = 0 if @real_offset_y == nil
        return screen_y_stairs + @real_offset_y
      end
    
      alias updatemovestairs update_move
      def update_move
        # compatibility with existing saves
        if @real_offset_x == nil || @real_offset_y == nil || @offset_y == nil || @offset_x == nil
          @real_offset_x = 0
          @real_offset_y = 0
          @offset_x = 0
          @offset_y = 0
        end
        
        if @real_offset_x != @offset_x || @real_offset_y != @offset_y
          @real_offset_x = @real_offset_x-2 if  @real_offset_x>@offset_x
          @real_offset_x = @real_offset_x+2 if  @real_offset_x<@offset_x
          @real_offset_y = @real_offset_y+2 if  @real_offset_y<@offset_y
          @real_offset_y = @real_offset_y-2 if  @real_offset_y>@offset_y
        end
        updatemovestairs
      end
      
      alias movetostairs moveto
      def moveto(x,y)
        @real_offset_x = 0
        @real_offset_y = 0
        @offset_x = 0
        @offset_y = 0
        movetostairs(x,y)
      end
    end
    
    class Game_Character
       alias move_left_stairs move_left
       def move_left(turn_enabled = true)
        move_left_stairs(turn_enabled)
        if self.map.terrain_tag(@x,@y) == PBTerrain::StairLeft || self.map.terrain_tag(@x,@y) == PBTerrain::StairRight
          @offset_y = -16
        else
          @offset_y = 0
        end
      end
     
      alias move_right_stairs move_right
      def move_right(turn_enabled = true)
        move_right_stairs(turn_enabled)
        if self.map.terrain_tag(@x,@y) == PBTerrain::StairLeft || self.map.terrain_tag(@x,@y) == PBTerrain::StairRight
          @offset_y = -16
        else
          @offset_y = 0
        end
      end
    end
    
    class Game_Player 
      alias move_left_stairs move_left
       def move_left(turn_enabled = true)
        old_tag = self.map.terrain_tag(@x, @y)
        old_through = self.through
        old_x = @x
        if old_tag == PBTerrain::StairLeft
          if passable?(@x-1, @y+1, 4) && self.map.terrain_tag(@x-1,@y+1) == PBTerrain::StairLeft
            @y += 1
            self.through = true
          end
        elsif old_tag == PBTerrain::StairRight
          if passable?(@x-1, @y-1, 6)
            @y -= 1
            self.through = true
          end
        end
        move_left_stairs(turn_enabled)
        new_tag = self.map.terrain_tag(@x, @y)
        if old_x != @x
          if old_tag != PBTerrain::StairLeft && new_tag == PBTerrain::StairLeft ||
            old_tag != PBTerrain::StairRight && new_tag == PBTerrain::StairRight
            self.offset_y = -16
            @y += 1 if new_tag == PBTerrain::StairLeft
          elsif old_tag == PBTerrain::StairLeft && new_tag != PBTerrain::StairLeft ||
            old_tag == PBTerrain::StairRight && new_tag != PBTerrain::StairRight
            self.offset_y = 0
          end
        end
        self.through = old_through
      end
     
      alias move_right_stairs move_right
      def move_right(turn_enabled = true)
        old_tag = self.map.terrain_tag(@x, @y)
        old_through = self.through
        old_x = @x
        if old_tag == PBTerrain::StairLeft && passable?(@x+1, @y-1, 4)
          @y -= 1
          self.through = true
        elsif old_tag == PBTerrain::StairRight && passable?(@x+1, @y+1, 6)&& self.map.terrain_tag(@x+1,@y+1) == PBTerrain::StairRight
          @y += 1
          self.through = true
        end
        move_right_stairs(turn_enabled)
        new_tag = self.map.terrain_tag(@x, @y)
        if old_x != @x
          if old_tag != PBTerrain::StairLeft && new_tag == PBTerrain::StairLeft ||
            old_tag != PBTerrain::StairRight && new_tag == PBTerrain::StairRight
            self.offset_y = -16
            @y += 1 if new_tag == PBTerrain::StairRight
          elsif old_tag == PBTerrain::StairLeft && new_tag != PBTerrain::StairLeft ||
            old_tag == PBTerrain::StairRight && new_tag != PBTerrain::StairRight
            self.offset_y = 0
          end
        end
        self.through = old_through
      end
     
      alias center_stairs center
      def center(x,y)
        center_stairs(x,y)
        self.map.display_x = self.map.display_x + (@offset_x || 0)
        self.map.display_y = self.map.display_y + (@offset_y || 0)
      end
     
      def passable?(x, y, d)
        # Get new coordinates
        new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
        new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
        # If coordinates are outside of map
        unless $game_map.validLax?(new_x, new_y)
          # Impassable
          return false
        end
        if !$game_map.valid?(new_x, new_y)
          return false if !$MapFactory
          return $MapFactory.isPassableFromEdge?(new_x, new_y)
        end
        # If debug mode is ON and ctrl key was pressed
        if $DEBUG and Input.press?(Input::CTRL)
          # Passable
          return true
        elsif d == 8 && new_y > 0 # prevent player moving up past the top of the stairs
          if $game_map.terrain_tag(new_x, new_y) == PBTerrain::StairLeft &&
            $game_map.terrain_tag(new_x, new_y-1) != PBTerrain::StairLeft
            return false
          elsif $game_map.terrain_tag(new_x, new_y) == PBTerrain::StairRight &&
            $game_map.terrain_tag(new_x, new_y-1) != PBTerrain::StairRight
            return false
          end
        end
        super
      end
    end

    Version 17
    Place this script above Main. This version is no longer being supported. Please upgrade Essentials to v18 to get support.
    Spoiler:

    If you'd like to support followers, change this code inside the Followers script:
    Spoiler:

    Then VERY IMPORTANT: set up your stair tiles with the appropriate terrain tags and this exact passability:
    [v18] Terrain Tag Side Stairs


    And it should be good to go! All the movement is handled automatically from here on.
     
    Last edited:
    24
    Posts
    15
    Years
    • Seen Oct 23, 2022
    Is this not meant for single step stairs? I had to flip the bottom passability because it would offset my character by about 16 pixels if I went down them on a single stair as opposed to one with 2 or more.
     
    Is this not meant for single step stairs? I had to flip the bottom passability because it would offset my character by about 16 pixels if I went down them on a single stair as opposed to one with 2 or more.

    I think the GIF shows what you want. The Player is centrally placed when it reaches the end of stairs. It only increases a small pixel when you are moving up or down and resets the position when you reach the end. If I am wrong, SORRY.
     
    24
    Posts
    15
    Years
    • Seen Oct 23, 2022
    I think the GIF shows what you want. The Player is centrally placed when it reaches the end of stairs. It only increases a small pixel when you are moving up or down and resets the position when you reach the end. If I am wrong, SORRY.

    Thanks for pointing out the obvious that doesn't help though.
     

    Boonzeet

    Pokémon Secrets of the Ages Developer
    188
    Posts
    15
    Years
  • Is this not meant for single step stairs? I had to flip the bottom passability because it would offset my character by about 16 pixels if I went down them on a single stair as opposed to one with 2 or more.

    This is meant for single stairs, too. Could you post a screenshot of what you're experiencing? The 16px offset is intentional, as the player is halfway between that tile and the tile 'above'.
     
    24
    Posts
    15
    Years
    • Seen Oct 23, 2022
    This is meant for single stairs, too. Could you post a screenshot of what you're experiencing? The 16px offset is intentional, as the player is halfway between that tile and the tile 'above'.

    I'm currently evacuating due to the weather near me, I will post that in a couple days when I'm back home with more details.
     
    24
    Posts
    15
    Years
    • Seen Oct 23, 2022
    This is meant for single stairs, too. Could you post a screenshot of what you're experiencing? The 16px offset is intentional, as the player is halfway between that tile and the tile 'above'.

    Okay, after doing some digging I found out that the tilesets I was using this on had all of their terrain tags shifted up whole tile. I don't know why or how but that's what the issue was. I've never actually seen that happen before with terrain tags, but I do have some larger tilesets.
     
    Last edited:

    DarrylBD99

    Content Creator and Game Developer
    321
    Posts
    4
    Years
  • I like this script. However, it would be much better if the camera followed the 16px offset. But overall, the script is great.
     

    Boonzeet

    Pokémon Secrets of the Ages Developer
    188
    Posts
    15
    Years
  • Updated to v1.2, fixing several bugs introduced in v18 due to changes with how Game_Character works.

    This fixed:
    • Ledges no longer get the players stuck
    • Surfing no longer triggers an encounter every time if the player's step counter has not incremented
    • Map transfers while a player is on stairs no longer cause the player to be permanently offset until next encountering stairs
     
    2
    Posts
    8
    Years
    • Seen Nov 4, 2022
    Can you help me? I am using gen8 project 18.1 and when using your script it gives me the following error:
    ---------------------------
    Error
    ---------------------------
    Script '[Terrain_Tag_Stairs]' line 107: SystemStackError occurred.

    stack level too deep

    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    from '' line 107 in `` move_left_stairs'
    ---------------------------
    No matter how much I investigate, I cannot find the problem
     
    1
    Posts
    3
    Years
    • Seen Jan 12, 2021
    Having the same issue going up and down is not a problem but turning char right sided or left sided seems to crash the game for some reason. The Terrain Tag is ok tho i leaved it on standard.
     
    1
    Posts
    3
    Years
    • Seen Jun 21, 2021
    --------------------------- Error --------------------------- Script '[Boon's Terrain Tag Side Stairs]' line 117: SystemStackError occurred. stack level too deep from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' from 'Boon's Terrain Tag Side Stairs' line 117 in `move_right_stairs' --------------------------- Aceptar ---------------------------
     
    Back
    Top