Stairs Movement

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by FenixFyreX, Feb 12, 2013.

    Tags:
  1. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    Stairs Movement v1.0
    FenixFyreX
    Introduction
    This script allows movement on a diagonal line to emulate scaling staircases.

    Features
    - Easily designate a staircase via a region
    - Change the speed at which steps are taken to match the pace of moving up/down the staircase
    - Alter the y coordinate offset of the character sprite to match the tileset staircase center

    Screenshots
    Not really applicable as you'd need to see it in action. Just put it in your project, set up a staircase, and try it out.

    How to Use
    1> Install the script below the default scripts and above Main.
    2> Edit the script config to change the staircase region id to your liking.
    3> Create a staircase on the map with your tileset.
    4> Along the path of the staircase, put that region down.
    5> Playtest!

    Demo
    Mediafire - Stairs Movement

    Script
    Code:
    #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=## Stairs Movement v 1.1#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=### FenixFyreX## Final Fantasy VI had stairs that the player actually walked up. Their direction# became two way on these stairs, left or right. This script replicates that# feature.##-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#StairsRegionID = 10   # The region ID to use for designating staircasesStairsOffset   = 4    # The height of one tileset staircase plank (about 4px)CharAnimSpeed  = 2    # The speed at which a sprite cycles through frames#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=## End of Config. Do not edit below.#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#class Game_Map  def stairs?(x,y)    region_id(x,y) == StairsRegionID  endendclass Game_CharacterBase    # give other coders access to checking stairs status  attr_reader :on_stairs, :stairs_d  alias on_stairs? on_stairs    # check whether character is on stairs  def check_stairs    @on_stairs = stairs?(0)  end    # Checks if there are any sets of stairs in the given direction  def stairs?(d)    return case d    when 0      $game_map.stairs?(@x,@y)    when 2      $game_map.stairs?(@x-1,@y+1) || $game_map.stairs?(@x+1,@y+1)    when 4      $game_map.stairs?(@x-1,@y-1) || $game_map.stairs?(@x-1,@y+1)    when 6      $game_map.stairs?(@x+1,@y-1) || $game_map.stairs?(@x+1,@y+1)    when 8      $game_map.stairs?(@x-1,@y-1) || $game_map.stairs?(@x+1,@y-1)    else      false    end  end    # Checks passability in the given direction for stairs  def stairs_passable?(x, y, d)    x2 = $game_map.round_x_with_direction(x, d)    y2 = $game_map.round_y_with_direction(y, d)    return false unless $game_map.valid?(x2, y2)    return true if @through || debug_through?    return false unless map_passable?(x, y, d)    return false if collide_with_characters?(x2, y2)    return true  end    # Moves the character in the given direction diagonally up or down stairs  def move_diag_stairs(d, horz, vert, turn_ok)    x,y = @x+horz,@y+vert    horz = [4,6][[-1,1].index(horz)]    vert = [8,2][[-1,1].index(vert)]    @move_succeed = stairs_passable?(x,y,d)    d = [4,6][[[4,8],[6,8],[4,2],[6,2]].index([horz,vert])%2]    set_direction(d) if turn_ok    if @move_succeed      @x = $game_map.round_x_with_direction(@x, horz)      @y = $game_map.round_y_with_direction(@y, vert)      @real_x = $game_map.x_with_direction(@x, reverse_dir(horz))      @real_y = $game_map.y_with_direction(@y, reverse_dir(vert))      increase_steps    end  end    # Returns the stair vector for the given direction  def stair_vector(d)    x,y = 0,0    case d    when 4,6      x = [-1,1][[4,6].index(d)]      y = $game_map.stairs?(@x+x,@y-1) ? -1 : 1    when 2,8      y = [-1,1][[8,2].index(d)]      x = $game_map.stairs?(@x-1,@y+y) ? -1 : 1    end    [x,y]  end    # Checks whether or not the character is not getting on or off stairs  def midstairs?    @on_stairs && stairs?(reverse_dir(@direction))  end    # Alters original move method to put stairs into effect  alias move_straight_no_stairs move_straight  def move_straight(d, turn_ok = true)    if on_stairs? && stairs?(d)      @stairs_d = d      move_diag_stairs(d, *stair_vector(d), turn_ok)    else      d = @direction if @on_stairs && [2,8].include?(d)      move_straight_no_stairs(d, turn_ok)    end    check_stairs  end    alias move_diagonal_for_stairs move_diagonal  def move_diagonal(horz, vert)    if self.is_a?(Game_Follower) && @preceding_character.on_stairs?      check_stairs      if on_stairs? && stairs?(@preceding_character.stairs_d)        d = @preceding_character.stairs_d        move_diag_stairs(d, *stair_vector(d), true)      else        move_diagonal_for_stairs(horz, vert)      end    else      move_diagonal_for_stairs(horz, vert)    end  end    # Shift the y coordinate of the character's sprite to compensate for stairs  alias shift_y_for_stairs shift_y  def shift_y(*a,&bl)    shift_y_for_stairs(*a,&bl) + (midstairs? ? StairsOffset : 0)  end    # Update the sprite more to create pace-per-step effect on stairs  alias update_anime_count_for_stairs update_anime_count  def update_anime_count(*a,&bl)    ac = @anime_count    update_anime_count_for_stairs(*a,&bl)    @anime_count += CharAnimSpeed if midstairs?  endendclass Game_Player < Game_Character  alias move_straight_for_stairs move_straight  def move_straight(*a,&bl)    @followers.move if stairs_passable?(@x,@y,a[0]) if on_stairs?    move_straight_for_stairs(*a,&bl)  endend#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=## End of Script#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
    Credit and Thanks
    - FenixFyreX

    Changelog & Bug Fixes
    Version 1.1
    - Fixed bug where followers wouldn't follow the player up or down stairs.
     
    Last edited by a moderator: Feb 13, 2013
    #1
  2. Cartridge

    Cartridge It's all about the guns, man Veteran

    Messages:
    467
    Likes Received:
    21
    Location:
    The Netherlands
    First Language:
    Dutch
    I usually do this via events, which works perfectly, but this is more smooth as I had to make the player walk one tile away from the stair all the time.

    Nice script Fenix!
     
    #2
  3. ディーノス

    ディーノス Make a new destiny! Veteran

    Messages:
    187
    Likes Received:
    19
    Location:
    Indonesia
    First Language:
    Indonesian
    can you upload the demo version...?

    i don't really understand it...
     
    #3
  4. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    I have uploaded a demo. Try it out to understand how to use this.
     
    #4
  5. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,120
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA
    This looks so useful.  thanks.
     
    #5
  6. Chaos17

    Chaos17 Dreamer Veteran

    Messages:
    1,253
    Likes Received:
    420
    Location:
    France
    First Language:
    French
    The followers aren't following the hero.

    http://uppix.net/c/f/6/13ced32eaa3c8f2f6482e17c92635.html'>[​IMG]
     
    #6
  7. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    Haha, I totally forgot about Ace's follower system, the script is updated accordingly.


    EDIT: Also, the demo is not updated. Put the new script in the demo if you wish to see the followers climb stairs too.
     
    Last edited by a moderator: Feb 13, 2013
    #7
    Tsukihime and Chaos17 like this.
  8. eigwayne

    eigwayne Veteran Veteran

    Messages:
    53
    Likes Received:
    11
    Location:
    Sunny New England
    First Language:
    English
    This is pretty awesome~ It was bugging me that I'd have to event going up stairs, or leave it as-is and have the characters walk funny. This is a perfect solution, and it drops right into a project with several existing scripts and works just fine.

    Thanks, FenixFyre! This is super useful!
     
    #8
  9. ct_bolt

    ct_bolt Creator Veteran

    Messages:
    522
    Likes Received:
    120
    Location:
    Planet Earth
    First Language:
    Javascript
    Primarily Uses:
    RMMV
    Very cool, great script! Love using this instead of eventing everything. BD
     
    #9
  10. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,120
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA
    I've hit a snag with this.

    I have 5 characters in my crocodile, but when I go up the stairs I lose the 5th, and never get him back.  This happens whichever route I take to the larger party i.e. whether I change line 73 in Game Objects, Game_Party script to 5, or with Yanfly's Party System.

    Is there a way of getting all my party to show up?  It seems such a pity if I have to drop your stairs script which is so very useful.
     
    #10
  11. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    I altered Game_Party's line 73 equal to 5 and tested (just like you), and all of my characters stayed with me with no problems, so it isn't my script. It must be a compatibility issue. What scripts are you using with this one ksjp17?
     
    #11
  12. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,120
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA
    They are almost all Yanfly's scripts.  Reading down, the list is in this order:

    Ace Core engine

    Battle Engine

      -  Enemy HP Bars

      -  Enemy Info

      -  Elemental Pop-ups

    Ace Menu Engine

      -  Party System

      -  Party Sized Menu

    Ace Save Engine

    Message system

    Parallax Lock

    FinexFyreX stairs movement

    Todd's difficulty select

    I tried to stick to mainly one person's scripts to reduce incompatability.

    I hope you can think of what might be the problem, as I love the way your script works and have spent a huge amount of time making the various different stair tiles I need.  (It's a huge amount because I'm not very experienced, and so it takes me a lot longer than many people.)
     
    Last edited by a moderator: Apr 25, 2013
    #12
  13. FenixFyreX

    FenixFyreX Fire Deity Veteran

    Messages:
    434
    Likes Received:
    307
    Location:
    A Volcano Somewhere
    First Language:
    English
    Go ahead and try removing each other script individually (You can see how in the spoiler below) and see which script is causing the problems. My bet is on the Ace Menu System - Party System.

    To 'remove' your scripts individually without messing them up, simply follow these steps:1> Click inside the script text (the big box with the script in it)

    2> Press Ctrl + A

    3> Press Ctrl + Q

    Your script is now commented completely out. Now, test the game and see if 5 characters follow correctly. If not, then follow the same steps above to un-comment the script, and try the next script.
     
    #13
  14. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,120
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA
    Okay, the mystery deepens.  I had turned my computer off completely.  When I turned it on and loaded up, there was my party intact.  Don't ask me how this happened, because I don't know.  All I can say is that I'm greatly relieved about this, as it means that I can keep everything.

    Thanks for your help, and I hope it hasn't taken up too much of your time thinking about this.
     
    #14
  15. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,120
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA
    Me again, I'm afraid.  Quite a different problem this time.  I was testing out the first draft of a map which included a longer set of stairs than I had made up till now.  Going up is no problem at all.  It's coming down that something weird happens.  I've got some screen shots to try and make it clear what's happening.  I'm still sorting out the tinting, but I think they should be clear enough.

    Everything's fine for the first few steps.  Then, at the same point each time, the 3rd person in the crocodile hurtles back up the stairs to the end of the line.  You can just see the top of her blue hair behind the last sprite.

    ">http://[​IMG]

    By the time the party is at the bottom of the stairs, the 4th and 5th have done the same thing, but now they are coming downstairs too.

    ">http://[​IMG]

    They do eventually catch up, but if, like in this example, the front two have gone sideways, they catch up by cutting diagonally across the bottom bit of the stair wall, even though normally it is impassable.

    ">http://[​IMG]

    Do you have any idea what might be causing this?

    Thanks
     
    #15
  16. the Skye Mage

    the Skye Mage E=MC Squire Veteran

    Messages:
    154
    Likes Received:
    5
    First Language:
    english
    I feel sooo stupid :( i'm using this and only have a 2 height pix stair so i guess it covers 4 to 6 squares in all... I looked at the demo, i'm tryna put the (below character) events on the spaces you did, and it's not workin >.> don't know what to do. Usin your stairs and everything
     
    #16
  17. Candacis

    Candacis Pixel Pusher Restaff

    Messages:
    1,446
    Likes Received:
    1,933
    Location:
    Vienna
    First Language:
    German
    Great Script! I used it not with stairs but with slopes that go up a hill. Do you have any way to make this script workable for stairs that are wider than 1 tile? Sometimes wide stairs cause a weird zig zag movement.
     
    #17
  18. jimfalcon

    jimfalcon Veteran Veteran

    Messages:
    44
    Likes Received:
    2
    I'm trying hard to learn scripting, and I'm definitely not a natural at it, learning for a few minutes makes me rage. 

    So, for a noob that might one day add to the scripting community, could you dumb this down and tell me how this works?

    script logic in all languages makes my head hurt. Here it says that StairsRegionID is the region ID used for designating staircases. In my head the region ID would be the number you see when you click on an event box, and open up the event menu, in the top left corner. but the stairs start with ID:002... or is that an Event ID, and is not the same as a region ID? IF so how do you find the region ID in the first place. Are people supposed to know terms like StairsRegionID before they use this script?

    Could you, or anyone else start from the beginning and give a step by step on how to make this work. I've found that in many scripts, people give instructions assuming that people are familiar with the structure of ruby. I and many others am not. And it seems that google is no match for finding any tutorials that cater to beginners. And I would love to use this script :(

    StairsRegionID = 10 # The region ID to use for designating staircases
    StairsOffset = 4 # The height of one tileset staircase plank (about 4px)
    CharAnimSpeed = 2 # The speed at which a sprite cycles through frames
     
    #18
  19. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,120
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA
    The number you see when you open an event is the Event ID, useful when you have, for example, one event controlling the movement of NPCs etc., and you want to be able to identify which event is which.

    Region ID is what you get when you select 'Region' from the menu bar at the top - either by clicking on 'Mode' and selecting region, or by clicking on the icon on the bar below and to the right of it.  When you select Region it comes up with a multi-coloured grid with numbers on it.  Each number allocates a region ID to the tiles that you apply it to.  So in this instance, select the number 10 and then click on those tiles where you want the stairs movement to operate.

    In order to use the script that is all you need to know.  The other 2 pieces of information are for more advanced users who would like to have that info if they want to tinker with things.

    It does occur to me that if you don't know about the difference between events and regions, you may find Andar's excellent compilation of tutorials etc. very helpful.  Follow this link: http://forums.rpgmakerweb.com/index.php?showtopic=14727
     
    #19
  20. Candacis

    Candacis Pixel Pusher Restaff

    Messages:
    1,446
    Likes Received:
    1,933
    Location:
    Vienna
    First Language:
    German
    For Mack Sprites I used CharAnimSpeed 1 by the way, works very well.
     
    #20

Share This Page