BDR Height v1.1

BDR Height Version: 1.1 for RMVX
By: Fustel

Introduction
Ever wanted to make simple bridges and 3D mazes ??
With this new BDR script, it is now up to you. All you have to do is define tiles height, decoration size, and put simple bridge events.
And you have the choice of the method to map your heights: directily on your map, or via a height map linked to your real map.

Features
  • Define the maximum height the Hero can cross from one tile to another.
  • Define base ground tiles height by
    • assigning it to ground tile and puting them on the real map
      OR
    • assigning it to decorative tile and puting them on a height map linked to the real map
  • Define decorative tiles size, which is added to the base height
  • Define the height of an event. The final height of a tile is the higher of its own (plus any decorative) and that of any event plaved on it.
  • Tiles that are too high/low for one another are mutually impassable.
  • Define the game variable containing the Hero height and decide if an event is drawn ABOVE or BELOW the Hero depending on the value of this variable. Thus easyly making bridges.
  • The Hero cannot interact whith event on tiles he cannot reach.
  • If a height map is defined, it is used instead of the 'direct mapping' method.

Screenshots
None worth it Spoiler
The purpose of this script is about moving. No static image could be of any help


Demo
Talk to the old man...twice Spoiler
http://www.mediafire.com/file/nnz34gmngtm/BDR%20Height%20-%20v1.1.zip

Try and speak to the old man, taking note of where you can (and can't move), and of what is under your feets or over your head.
The 2 map are basically the same except:
  • The first uses the 'direct mapping' method
  • The second uses non-mapped tiles, but is linked to its 'height map'


Script
  1. #==============================================================================
  2. # ** BDR Height
  3. #------------------------------------------------------------------------------
  4. #  © Fustel, 2010
  5. #  13/04/10
  6. #  Version 1.1
  7. #------------------------------------------------------------------------------
  8. #  VERSION HISTORY:
  9. #   - 1.0 (13/04/10), Initial release
  10. #   - 1.1 (19/04/10), dual height mapping ('direct' or 'height map')
  11. #-------------------------------------------------------------------------------
  12. #  INSTRUCTIONS:
  13. #   - Install the 'BDR Tile v1.2' script
  14. #   - Place this script in the 'Materials' section
  15. #   - Set the following constants:
  16. #     - BDR::Height::VAR (ID of variable to store player height)
  17. #     - BDR::Height::NO_WALK (height difference with is impassable)
  18. #     - for mapping on real map
  19. #       - BDR::Height::Real_Height (Base height for ground tiles on real map)
  20. #     - for mapping on height map
  21. #       - BDR::Height::Map_Height (Base height for deco tiles on height map)
  22. #       - BDR::Height::Map (linking real map and height map)
  23. #     - BDR::Height::Deco_Size (added height added for deco on real map)
  24. #---------------------------------------------------------------------------
  25. # NOTES
  26. #   You cannot interact with event on a tile too high/low (events_xy returns [])
  27. #   To make a bridge/ladder, create an event with 2 pages:
  28. #     - one is the defaut and drawn ABOVE the hero
  29. #     - the other is drawn BELOW the hero, but is set when the vriable identified
  30. #         by BDR::Height::VAR is at bridge height. Also, thit page MUST have a
  31. #         comment with containining the line:
  32. #           BDR_HEIGHT=<h>
  33. #         where h is the desired height for the bridge.
  34. #     - remeber to put the bridge within height reach of its extremities
  35. #     - also remember to put the bridge high enough so the hero could not
  36. #         reach it from below.
  37. #==============================================================================
  38.  
  39. module BDR
  40.   module Height
  41.  
  42.     # both systems
  43.     #=============
  44.     # variable ID to store the player tile height
  45.     #--------------------------------------------
  46.     VAR = 1
  47.  
  48.     # both systems
  49.     #=============
  50.     # Max height difference tha is passable while walking
  51.     #----------------------------------------------------
  52.     NO_WALK = 2
  53.  
  54.     # HEIGHT MAP
  55.     #===========
  56.     # Links between height map and real map
  57.     # key  = real map ID
  58.     # data = height map ID
  59.     #----------------------------------
  60.     Map = {}
  61.     Map[2] = 3
  62.  
  63.     # HEIGHT MAP
  64.     #===========
  65.     # Base height from decorative tile put in height map
  66.     # key  = [ column in panel,
  67.     #          row in panel,
  68.     #          panel ("B" to "E")
  69.     #        ]
  70.     # data = height
  71.     #------------------------------------
  72.     Map_Height = {}
  73.     Map_Height[ [ 0, 0, "E"]] = -2
  74.     Map_Height[ [ 1, 0, "E"]] = -1
  75.     Map_Height[ [ 3, 0, "E"]] =  1
  76.     Map_Height[ [ 4, 0, "E"]] =  2
  77.     Map_Height[ [ 5, 0, "E"]] =  3
  78.     Map_Height[ [ 6, 0, "E"]] =  4
  79.  
  80.     # DIRECT MAPPING
  81.     #===============
  82.     # Base height from ground tiles in real map (panel A)
  83.     # key  = [ column in panel A,
  84.     #          row in panel A
  85.     #        ]
  86.     # data = height
  87.     #------------------------------------
  88.     Real_Height = {}
  89.     Real_Height[ [ 0,  1]] = -2  # water pool
  90.     Real_Height[ [ 4, 10]] =  4  # roof
  91.  
  92.     # both systems
  93.     #=============
  94.     # Additional height from decorative in real map (panel B to E)
  95.     # key  = [ column in panel,
  96.     #          row in panel,
  97.     #          pane ("A" to "E")
  98.     #        ]
  99.     # data = height adjustment
  100.     #---------------------------------
  101.     Deco_Size = {}        # height adjustment for items (tiles B to E)
  102.     Deco_Size[ [ 4,  0, "C"]] = 3 # ladder: top
  103.     Deco_Size[ [ 4,  1, "C"]] = 2 # ladder: middle
  104.     Deco_Size[ [ 4,  2, "C"]] = 1 # ladder: bottom
  105.     Deco_Size[ [ 0,  0, "C"]] = 1 # stairs
  106.     Deco_Size[ [ 1,  2, "B"]] = 1 # wooden stairs
  107.     Deco_Size[ [ 5, 14, "B"]] = 2 # bushes
  108.   end
  109. end
  110.  
  111.  
  112.  
  113. class Game_Map
  114.   attr_reader :bdr_height_map
  115.  
  116.   alias bdr_height_initialize initialize
  117.   def initialize
  118.     @bdr_height_map = nil
  119.     bdr_height_initialize
  120.   end
  121.  
  122.   alias bdr_height_setup setup
  123.   def setup( map_id)
  124.     bdr_height_setup( map_id)
  125.  
  126.     m = BDR::Height::Map[ map_id]
  127.     @bdr_height_map = m != nil ? load_data( sprintf( "Data/Map%03d.rvdata", m)) : nil
  128.   end
  129. end
  130.  
  131. class Game_Event < Game_Character
  132.   BDR_HEIGHT_HEIGHT = "BDR_HEIGHT_HEIGHT"
  133.   BDR_HEIGHT_SIZE   = "BDR_HEIGHT_SIZE"
  134.  
  135.   attr_reader :bdr_height_height
  136.   attr_reader :bdr_height_size
  137.  
  138.   alias bdr_height_initialize initialize
  139.   def initialize(map_id, event)
  140.     @bdr_height_height = nil
  141.     @bdr_height_size   = 0
  142.     bdr_height_initialize(map_id, event)
  143.   end
  144.  
  145.   alias bdr_height_setup setup
  146.   def setup(new_page)
  147.     bdr_height_setup( new_page)
  148.     @bdr_height_height = nil
  149.     @bdr_height_size = 0
  150.     if @page != nil
  151.       for command in @page.list
  152.         next unless [ 108, 408].include?( command.code)
  153.         s = command.parameters[ 0].upcase.delete " "
  154.  
  155.         k = BDR_HEIGHT_HEIGHT.upcase + "="
  156.         begin
  157.           @bdr_height_height = s.sub( k){|v| ""}.to_i if s.index( k) == 0
  158.         rescue
  159.         end
  160.  
  161.         k = BDR_HEIGHT_SIZE.upcase + "="
  162.         begin
  163.           @bdr_height_size = s.sub( k){|v| ""}.to_i if s.index( k) == 0
  164.         rescue
  165.         end
  166.       end
  167.     end
  168.   end
  169. end
  170.  
  171. class Game_Map
  172.   def tile_height( x, y)
  173.     return 0 if x == nil or y == nil
  174.  
  175.     if $game_map.bdr_height_map == nil
  176.       tile_grnd = $game_map.tile_id( x, y)
  177.       height = BDR::Height::Real_Height[ tile_grnd]
  178.     else
  179.       tile_grnd = $game_map.bdr_height_map.tile_id( x, y, 2).with_panel
  180.       height = BDR::Height::Map_Height[ tile_grnd]
  181.     end
  182.     height = 0 if height == nil
  183.  
  184.     tile_deco = $game_map.tile_id( x, y, 2).with_panel
  185.     plus = BDR::Height::Deco_Size[ tile_deco]
  186.     height += plus if plus != nil
  187.  
  188.     for ev in events.values
  189.       height = [ ev.bdr_height_height+ev.bdr_height_size, height].max if ev.bdr_height_height != nil and ev.pos?(x, y)
  190.     end
  191.  
  192.     return height
  193.   end
  194.  
  195.   # no event at ( x, y) if too high/low from player
  196.   #------------------------------------------------
  197.   alias bdr_height_events_xy events_xy
  198.   def events_xy(x, y)
  199.     return ( ( tile_height( x, y) - $game_player.height).abs < BDR::Height::NO_WALK ? bdr_height_events_xy( x, y) : [])
  200.   end
  201. end
  202.  
  203. # Event management
  204. #-----------------
  205. class Game_Character
  206.   alias bdr_height_map_passable? map_passable?
  207.   def map_passable?( x, y)
  208.     return false unless bdr_height_map_passable?( x, y)
  209.     return false if ( $game_map.tile_height( @x, @y) - $game_map.tile_height( x, y)).abs >= BDR::Height::NO_WALK
  210.     return true
  211.   end
  212. end
  213.  
  214. class Game_Player < Game_Character
  215.   attr_reader :height
  216.  
  217.   alias bdr_height_initialize initialize
  218.   def initialize
  219.     bdr_height_initialize
  220.     @height = nil
  221.   end
  222.  
  223.   def bdr_height_update
  224.     h = $game_map.tile_height( @x, @y)
  225.     return if h == @height
  226.     @height = h
  227.     return if BDR::Height::VAR == nil
  228.     $game_variables[ BDR::Height::VAR] = @height
  229.     $game_map.need_refresh = true
  230.   end
  231.  
  232.   alias bdr_height_moveto moveto
  233.   def moveto(x, y)
  234.     bdr_height_moveto(x, y)
  235.     bdr_height_update
  236.   end
  237.  
  238.   alias bdr_height_increase_steps increase_steps
  239.   def increase_steps
  240.     bdr_height_increase_steps
  241.     bdr_height_update
  242.   end
  243.  
  244.   alias bdr_height_map_passable? map_passable?
  245.   def map_passable?( x, y)
  246.     return false unless bdr_height_map_passable?( x, y)
  247.     return false if ( $game_map.tile_height( @x, @y) - $game_map.tile_height( x, y)).abs >= BDR::Height::NO_WALK
  248.     return true
  249.   end
  250. end
  251.  
Expand to see the code.


InstructionsInsZ
Installation

Configuration
  • Set parameters in the BDR::Height module in the script
    • the 'VAR' constant identies the Game_Variables that will contain the Hero height.
    • the 'NO_WALK' constant containd the height difference the hero cannot cross
    • for the 'direct mapping' method
      • the 'Real_Height' hash contains the ground tiles (panel A) base height. The default height of a tile is 0. Only tiles that have a different height need to be placed in this hash.
        • the key is an array containing [ tile column in the A panle, tile row in the A panel]
        • the data is the tile height
    • for the 'height map' method
      • the 'Map_Height' hash contains the base height assigned to decorative tiles (panle B-E) thet will be put in the height map. If no deco is put on a tile in the height map, its height will be 0.
        • the key is an array containing [ tile column in the A panle, tile row in the A panel, panel ID ("B" to "E")]
        • the data is the tile height
      • the 'Map' hash contains the links between 'real maps' and 'height maps'
        • the key is the ID of the real map
        • the data is the ID of the height map
    • the 'Deco_Size' hash contains the decoratinve tiles (panel B-E) size which is added, if set, to the ground tile base height.
      • the key is an array containing [ tile column in the panle, tile row in the panel, tile pabel ID ("B" to "E")]
      • the data is the tile size

Usage
  • for 'direct mapping'
    • assign base height to ground tiles (Real_Height)
    • draw the real map with ground tiles
  • for 'height map'
    • assign base height to decorative tiles (Map_Height) (also, see E panel in demo)
    • copy the real map into a height map
    • put the 'height-defined-deco' tiles on the height map
    • link the height map to the real map (Map)
  • for both
    • define size for decoratives (Deco_Size)
    • put them on the real map

To make a bridge
  • Create an event with 2 page, each with the same graphic (if necessary)
    • the first (the Hero is blew the bridge) is drawn ABOVE the hero.
    • the second (the Hero is at bridge level or above)
      • is drawn BELOW the hero
      • has is height set by adding the following line in a comment: 'BDR_HEIGHT=<h>' where <h> is the bridge desired height
      • is conditioned by the value of the Game_Variables identified by BDR::Height::VAR, which must be equal or lower than the bridge, but within reach
  • Remember to set the bridge height close enought to that of its extemity tiles so the Hero can access it.
  • Remember to set the bridge height far enough from the bottom so that the Hero cannot access it from ther.

FAQ

Compatibility
No issue known, although the Game_Map.events_xy returns an empty array when the tile is too high/low from the Hero

Credits and Thanks
All done by myself

Author's Notes
If you have any trouble setting your hieghts, look thoroughly at the demo, and do not hesitate to ask the silly question.
Also, note that I considered giving size to events (thus definig a base height and a top height). Remember when the Hero push a pillar into a gap from below, climbs a stair and cross the gap ON TOP of the pillar ? But this brings up the matter of BIG events (more than 32*32 pixels), their full size mapping (not every 32*32 square should have the same 'size') and the time consuming process to compute a tile height considering any far event that may overlap the tile from afar. But the discussion is still open on the subject. I am expecting your opinion on this.

v1.0 to v1.1
  • Dual height mapping: on real map, of via a linked height map
  • Requires 'BDR Tile' v1.2 or higher
  • Keus for tile IDs in hash are now [ column, row, panel]
  • Configuration constants renamed

Terms and Conditions
You may not use this in a commercial game without my explicit permission.
You may not post this script anywhere without my explict permission.
You must give me credit.
Kind of bump to advertise on the last minute comment I added in the Autor's Notes.
Interestingly, this is exactly what I talked about with Zeriab yesterday ^^ Well, not your script, but a version I made back in my RMXP days that was quite unuseable because I used terrain tags to define heights. Your version isn't all that different to be honest, as to have multiple height grass tiles, you need it multiple times on your tile sheet, right? (at least as far as I understand it... even if I'm wrong, what I'm about to tell you is a better solution ^^)
Because I was thinking about it yesterday, I can already supply you with a way I think would make this a lot easier and less cluttered to use: Instead of script definitions of tile heights, use a complete tile panel for height assignment. Similar to my Tile Overlay script, it'd contain tiles labelled "G", "1", "2", "-1", and so forth... you'd need to set these to 25% opaque or something, and actually write that text on them. If you don't have the necessary programs, give me a call and I'll do that (as it's not really any effort ^^)
Now, actually placing those tiles on your map will define the height level - areas with the tile labelled "G" on them will be your ground level, tiles with "1" will be 1 higher up. That was, you spare the user from ANY setup aside from putting in a custom tileset and sparing a tile panel, which - considering RMVX has about 50 of them - shouldn't really matter. This way, however, you can get it to work within a minute with any sized tileset you can think of.

Other than that, it's a nice idea obviously (as it was mine as well XD ). You already know about my view of using one-time-used constants or blurry method or class names, so I guess you like to fight the power ;)
As far as your mentioned compatibility note goes, you might think about fixing that though, unless it's intentional...

Keep up the good work!
Sorry... I didn't know you already did something about height. Just tell me what you DIDN'T make a script about... :thumb:
There are many XP features missing in VX, as there are may VX features missing in XP. Terrain Tags was a great one, although I VX was out before I scripted XP 😢
I considered a couple solutions before choosing this one. It has its limits, but also some litlle advantages. But perhaps the one I just used for the famous soon-to-come 'BDR Sweep' is better... Time will say.
See ya at 'BDR Sweep'.... unless you already wrote it :tongue:
Lol... well, there'd be no way to know about this, as I scrapped it (I found the terrain method way too insufficient, so yeah... back then, I didn't think about what I told you earlier ^^" ). If you say you started scripting when VX was out already, I guess I have a bit more experience than you, which exlains why I made some more scripts than you XD However, I'm kind wonder where you got your ideas, now that you mention it... :huh:

Anyway, I never made anything sweepy, so I think you're good there XD
v1.1 released
  • 2 methods are now available to map the heights:
    • direct mapping as in v1.0
    • use of a heght map
  • now requires 'BDR Tile' v1.2 or higher (see main post for link)
  • some configuration constants renamed
  • some hash keys for configuration constants have changed.

Enjoy

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70510