Help - Search - Members - Calendar
Full Version: Ladder Climbing Done Right
RPG RPG Revolution Forums > Scripting > Script Tutorials > RGSS2
BigEd781
Ladder Climbing Animation
By BigEd781
Credit to DerVVulfman for his tile id formula


Introduction
By default, when you climb down a ladder you face straight at the screen. I was making a mountain map and really didn't like it, so I made this. It doesn't need any configuration, but things can be adjusted if they need to be. All this does is turn the player around (i.e., facing up) when you are walking on a wall tile. Because wall tiles are generally unpassable, the only time this happens is when you are climbing up or down a ladder. This won't effect events or anything else but the player. Maybe I will add an option for events later on, but I really just did this because it was annoying me. This script also allows you to use a custom animation if you wish to, but as I had none that option is turned off by default.

Configuration / Use
Just place it in the materials section. This script does not overwrite anything, so if you have any problems try placing it at the end of your list of scripts.

There are some things that you can configure if you wish. Like I said before, this works by setting certain tile id's which will act like "climbing ladder" tiles. All of the wall tiles in the RTP are already ON by default, so you probably will never have to configure anything. Most alternative tilesets place the walls in the same places as the RTP. If you are using tilesets which do not have wall tiles in the same places as the RTP, you can use the debug window to figure out which ones to remove. By default and when in test mode, pressing F5 will display a window that tells you the id of the tile you are standing on. When you need to add or remove a ladder tile, step on it in test mode and press F5. Remove that number from the collection of id's in the config section (shown below).

CODE
# this is the key that you may use to
  # display the id of the tile that you
  # are on.  You shouldn't need to use
  # this, but if you would like to add
  # more tiles to the "ladder tile"
  # collection you can use this to find
  # the id.
  DEBUG_KEY = Input::F5
  # this is a collection of tile ids.
  # this default set is all of the "wall"
  # type tiles in the RTP.  If you need
  # to add or remove tiles to this set
  # you can use the debug window to do so.
  # to add a tile id, simply type in the
  # id number where noted below and add a
  # comma after it.  Always keep the id's
  # between the two braces ('[' and ']').
  # if you are using the Mack tileset, comment out
  # the two lines labeled "comment out for Mack".
  # you can do this by adding a '#' character
  # to the beginning of the line.
  TILE_IDS = [
                56,  57,  58,  59,  60,  61,  62,  63,
                72,  73,  74,  75,  76,  77,  78,  79,
                88,  89,  90,  91,  92,  93,  94,  95,
                104, 105, 106, 107, 108, 109, 110, 111,
                120, 121, 122, 123, 124, 125, 126, 127,
                152, 153, 154, 155, 156, 157, 158, 159, # <-- comment out for Aërendyll's Mack tilesets
                168, 169, 170, 171, 172, 173, 174, 175,
                184, 185, 186, 187, 188, 189, 190, 191, # <-- comment out for Aërendyll's Mack tilesets
                    # <-- Add id's here.  
             ]
  # set this to true if you would like to
  # use a different graphic when climbing.
  USE_GRAPHIC = false
  # the file name of the custom graphic.
  # you do not need to add the file extension,
  # i.e., 'Actor1' not 'Actor1.png'.
  CHARACTER_NAME = 'Actor1'
  # the index of the character in the sheet.
  # in an 8 character sheet, '1' is the
  # top-left, '2' is the next to the right,
  # and '4' is the bottom left.
  CHARACTER_INDEX = 1


Script
CODE
module Ladder_Config
    
  # this is the key that you may use to
  # display the id of the tile that you
  # are on.  You shouldn't need to use
  # this, but if you would like to add
  # more tiles to the "ladder tile"
  # collection you can use this to find
  # the id.
  DEBUG_KEY = Input::F5
  # this is a collection of tile ids.
  # this default set is all of the "wall"
  # type tiles in the RTP.  If you need
  # to add or remove tiles to this set
  # you can use the debug window to do so.
  # to add a tile id, simply type in the
  # id number where noted below and add a
  # comma after it.  Always keep the id's
  # between the two braces ('[' and ']').
  # if you are using the Mack tileset, comment out
  # the two lines labeled "comment out for Mack".
  # you can do this by adding a '#' character
  # to the beginning of the line.
  TILE_IDS = [
                56,  57,  58,  59,  60,  61,  62,  63,
                72,  73,  74,  75,  76,  77,  78,  79,
                88,  89,  90,  91,  92,  93,  94,  95,
                104, 105, 106, 107, 108, 109, 110, 111,
                120, 121, 122, 123, 124, 125, 126, 127,
                152, 153, 154, 155, 156, 157, 158, 159, # <-- comment out for Aërendyll's Mack tilesets
                168, 169, 170, 171, 172, 173, 174, 175,
                184, 185, 186, 187, 188, 189, 190, 191, # <-- comment out for Aërendyll's Mack tilesets
                    # <-- Add id's here.  
             ]
  # set this to true if you would like to
  # use a different graphic when climbing.
  USE_GRAPHIC = false
  # the file name of the custom graphic.
  # you do not need to add the file extension,
  # i.e., 'Actor1' not 'Actor1.png'.
  CHARACTER_NAME = 'Actor1'
  # the index of the character in the sheet.
  # in an 8 character sheet, '1' is the
  # top-left, '2' is the next to the right,
  # and '4' is the bottom left.
  CHARACTER_INDEX = 1
  
end

#---------------------------------------------------------------------
# * Debug class
#---------------------------------------------------------------------
class Debug
  
  def initialize
    @debug_window = nil
    @frame_count = 1
  end
  
  def hide_window?
    @frame_count += 1
    @frame_count = 0 if @frame_count == 180
    return (!@debug_window.nil?) && (@frame_count == 0)
  end
  
  def hide_window
    unless @debug_window.nil?
      @frame_count = 1
      @debug_window.dispose
      @debug_window = nil
    end
  end
  
  def long_line(lines)
    long = ''
    lines.each { |line| long = line if line.size > long.size }
    return long
  end
  
  def find_width(line)
    return Bitmap.new(544, 416).text_size(line).width + 32
  end
  
  def find_height(num_lines)    
    return (num_lines * 24) + 32
  end
  
  def log(text, x=0, y=0)  
    @debug_window = Window_Base.new(x, y, find_width(text), find_height(1))
    draw(text)
  end
  
  def log_lines(lines, x=0, y=0)
  @debug_window =
    Window_Base.new(x, y, find_width(long_line(lines)), find_height(lines.size))
  draw_lines(lines)
  end
  
  def draw(text)
    @debug_window.contents.draw_text(@debug_window.contents.rect, text)
  end
  
  def draw_lines(lines)
    i = 0
    for line in lines
      @debug_window.contents.draw_text(0, i, 544, 416, text)
      i += 24
    end
  end
  
end

class Scene_Title
  
  alias :eds_debug_create_game_objects :create_game_objects
  def create_game_objects
    eds_debug_create_game_objects
    $debugger = Debug.new
  end
  
end

class Scene_Base
  
  def update
    $debugger.hide_window if ($debugger.hide_window? && $TEST)
  end
  
end

class Game_Map
  
  #--------------------------------------------------------------------------
  # * DerVVulfman method L get_tile_index
  #--------------------------------------------------------------------------
  def tile_index(tile_id)
    case tile_id
      # Multi-tiled ids in Tileset 'A'
      when 2048..8191; return ((tile_id - 2000) / 48) - 1
      # Individual tile ids in Tileset 'A'
      when 1536..1663; return(tile_id - 1408)
      # Tilesets 'B' to 'E'
      when 0..1023; return (tile_id + 256)        
    end
    return 0  
  end  
  
end

class Game_Player < Game_Character
    
  def character_name=(value)
    @character_name = value
  end
  
  def character_index=(value)
    @character_index = value
  end
  
  alias :eds_pre_ladder_turn_left :turn_left
  def turn_left
    tile_index = $game_map.tile_index($game_map.data[x, y, 0])                  
    return if Ladder_Config::TILE_IDS.include?(tile_index)
    eds_pre_ladder_turn_left
  end
  
  alias :eds_pre_ladder_turn_right :turn_right
  def turn_right
    tile_index = $game_map.tile_index($game_map.data[x, y, 0])                  
    return if Ladder_Config::TILE_IDS.include?(tile_index)
    eds_pre_ladder_turn_right
  end
  #--------------------------------------------------------------------------
  # * Processing of Movement via input from the Directional Buttons
  #--------------------------------------------------------------------------
  alias :eds_pre_ladder_move_by_input :move_by_input
  def move_by_input        
    @move_failed = true
    eds_pre_ladder_move_by_input
    unless @move_failed
      tile_index = $game_map.tile_index($game_map.data[x, y, 0])                  
      if Ladder_Config::TILE_IDS.include?(tile_index)
        if Ladder_Config::USE_GRAPHIC
          $game_player.character_name = Ladder_Config::CHARACTER_NAME
          $game_player.character_index = Ladder_Config::CHARACTER_INDEX                    
        else
          turn_up
        end
      else
        if Ladder_Config::USE_GRAPHIC
          $game_player.character_name = $game_party.members[0].character_name
          $game_player.character_index = $game_party.members[0].character_index
        end
      end
    end
  end  
  #--------------------------------------------------------------------------
  # * update
  #--------------------------------------------------------------------------
  alias :eds_pre_ladder_update :update
  def update
    eds_pre_ladder_update    
    if $TEST && Ladder_Config::DEBUG_KEY != nil
      if Input.trigger?(Ladder_Config::DEBUG_KEY)
        $debugger.hide_window        
        $debugger.log($game_map.tile_index($game_map.data[x, y, 0]))
      end
    end
  end
  
end


Compatibility / Bugs
Let me know of any issues.
SojaBird
You could do the same with events...though perhaps a script is a bit more easy if you don't want to spent time copy and pasting 2 events biggrin.gif

Greatzz,
SojaBird.
Mickadell
Comment
Rate: Good

I find it very good and useful for climbing. it does make it more interesting in the game.
I tryed it and it worked but it was a test and I didn't need it yet. Maybe I might add a climbing
thing.
BigEd781
QUOTE (pim321 @ Jan 18 2009, 05:28 AM) *
You could do the same with events...though perhaps a script is a bit more easy if you don't want to spent time copy and pasting 2 events biggrin.gif

Greatzz,
SojaBird.


Yeah, you would have to line every ladder though, and it just seemed unnecessary to me. Truthfully, I'm not a big fan of scripting things that could be done with events either, but I was making a map in my own game with a ton of ladders I did this solely for convenience. now I don't have to think about it.
sandy
Great idea, BigEd! One of those little things most people don't even think about smile.gif
woratana
Good idea~! I've never think about this. >_>/
BigEd781
QUOTE (woratana @ Jan 18 2009, 07:10 PM) *
Good idea~! I've never think about this. >_>/


Thanks Wora. Like they say, necessity is the mother of invention.
woratana
My suggestion is that class 'Debug' is not the best name I can think of using in my script.

The script might crash with other script that make class with the same name.
You may want to change the name to something that is not too simple. ^^
BigEd781
If that class also had a Debug class with a method of the same name that did not take the same parameter number or type I suppose it could. I could change it DebugTileId or something I suppose.
DragonRaw22
I like this script but I can't seem to get it to work along with the catipillar script, any help would be nice. Cheers happy.gif
BigEd781
QUOTE (DragonRaw22 @ Jan 26 2009, 03:28 PM) *
I like this script but I can't seem to get it to work along with the catipillar script, any help would be nice. Cheers happy.gif


I don't use the caterpillar script, but it would be easy, so I'll make a patch for it. Can you link me to the script that you are using?
DragonRaw22
Sorry about the delay internet went down, this is the script i am using, thanks for this.

http://www.rpgrevolution.com/forums/index.php?showtopic=8040

cheers
cello_marl
This is definitely an interesting script, and something I was interested in using. However, I did notice one thing.
If a player is in an airship, and flies over a tile that is designated as a "wall" tile, then it will change direction as though it were
climbing. Is there any way to use a switch to turn on and off the climbing sprite changes?
miget man12
Well first off, this is a great idea!
but unfortunately, it doesn't do anything when you go down, you face up for left, right and up but you face down when you move down...
That might have been very confusing...
thanks,
Miget man12
jick6
Cool, it seems a lot simpler than doing the whole "event at the top of the ladder" thing.
Though, it doesn't work with the Caterpillar script, so I'll have to stick with the "touch a ladder = transfer to other side" thing.
But good job anyway, you've probably saved a lot of people from a big pain in the ass.
BigEd781
QUOTE (miget man12 @ Feb 15 2009, 11:59 AM) *
Well first off, this is a great idea!
but unfortunately, it doesn't do anything when you go down, you face up for left, right and up but you face down when you move down...
That might have been very confusing...
thanks,
Miget man12


That's not true, the whole point of the script is to turn the player up when moving down. There isn't much to do when moving up the ladder.
gamemakernoob
I tested this script and it was conveniently awesome yes.gif
alexstore1
Can you make a demo teehee.gif or screenshot?
alexstore1
I don't understand!

please dont double post - use the edit button instead.

Thanks

kaz
BigEd781
QUOTE (alexstore1 @ Nov 11 2009, 09:36 AM) *
Can you make a demo teehee.gif or screenshot?


I don't think that either of those would be helpful. The screenshot would not be very descriptive, and a demo would be overkill. It is a simple script.

QUOTE (alexstore1 @ Nov 11 2009, 09:43 AM) *
I don't understand!


dry.gif What don't you understand exactly?
ShadoweD
Do you think you can make something that "hide" the actor at certain tiles?
and a function to change the hero grafic to "odd synth" like the commando on "move event" that makes the hero blend with the map


if you're thinking why i'm asking this, it's because on all my doors/curtains I make an event where the hero walks to the door, open and enter it... and on the next map he closes the door (he appear with an odd synth to simulate he's behind the wall) and then walk up

if you want i can make a demo so you can see what i'm talking about, it's really time consuming to do those things by event and it really add to the game


btw, it have to be compatible with Modern Algebra's "compose\visual equipment"


sorry for the bad english, not my first language ;/
musashi_2pedang
the problem is, i can't pass the wall.
ShinGamix
Hey BigEd can this be configed into a ladder slide script? or pole slide?
XerX
I love this script. Thanks.
InfinateX
Love the script!
Just wondering if it's possible to make it so you go behind ladders if you don;t start from the top or bottom.

(I need this script but not the part I asked if it's possible)



EDIT: I had a feeling this was BigEd but I couldn't find the topic...now I can credit you!
Digioso
Heya,

I found this script a vere nice idea but unfortunately it's not compatible to tilesets swapped via SwapXT either. Since I'm heavily relying on SwapXT but don't want to miss the ladder animation I made this one compatible to SwapXT.
Furthermore this script was overwriting the update method in the Scene_Base class which results in compatibility issues with at least Raoul589s Lighting (http://www.rpgmakervx.net/index.php?showtopic=39753&st=0) script (and probably others as well). Now it uses aliasing to prevent this.

Basically you can now create a configuration file where you can store your swapped mapids and set the tileids you want to function as ladder/wall tiles. There is a manual in the script attached.
You do not have to specify all maps in the configuration file. The script will use the default settings provided by BigEd781 if it can't find an entry in the file. If you don't have any config file at all it will use the default settings on all of your maps.

This version here also includes the fix for the "shadow-killer" script which BigEd781 posted over at rpgmakervx.net but didn't include here.

If you have any questions or encountered a bug please feel free to contact me/post here.

Also please add me to the credit list as well when you're using this.
The newest version of this script can always be found here: http://www.digioso.org/Ladder
Digioso
Just a small update. If you pressed F12 to reset the game and then started a new one you could get a "Stack level to deep" error when using this script. This is now fixed.
I attached the newest version here or get it from the link above.
Digioso
Another update. If you saved and loaded your game with this script enabled your game would crash.
I didn't know that I have to save and load the stuff I coded as well... Well... that's fixed now!

Newest version is available at the link above and attached to this posting.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.