Scroll Map Options

Purpose:
This script allows the map to be scrolled to a certain x, y position. It also allows the map to be scrolled to the player's position.

Instructions:
Paste anywhere above Main to use. No set-up required.

Call $game_map.scroll_to(x posiition, y position, speed) in a call script to scroll to position x, y.

Call $game_map.find_player(speed) in a call script to scroll to the player's position.

Call $game_map.clear_scroll to stop any scroll_to or find_player actions. Use $game_map.clear_scroll(false) to stop any current scrolling as well.

This script is free-to-use. Credits are appreciated but not necessary at all.

To wait for the completion of the scroll, use the following loop:
Image

This loop can be called from a common event and in any type of event except for a parallel process will also stop the player from moving.

Code:
  1.  
  2. ###############################################################################
  3. #SCROLL-TO
  4. #by Pokemaniac
  5. #
  6. #Call $game_map.scroll_to(x posiition, y position, speed) in a call script to
  7. #scroll to position x, y.
  8. #
  9. #Call $game_map.find_player(speed) in a call script to scroll to the player's
  10. #position.
  11. #
  12. #Call $game_map.clear_scroll to stop any scroll_to or find_player actions. Use
  13. #$game_map.clear_scroll(false) to stop any current scrolling as well.
  14. #
  15. #This script is free-to-use. Credits are appreciated but not necessary at all.
  16. ###############################################################################
  17.  
  18. class Game_Map
  19.  
  20.   #Initialize variable
  21.   alias initialize_scroll_to initialize unless $@
  22.   def initialize
  23.     initialize_scroll_to
  24.     @scrollWaiting = []
  25.   end
  26.  
  27.   #Scroll to
  28.   def scroll_to(x, y, s = 4)
  29.    
  30.     @scrollWaiting << [x, s, true]
  31.     @scrollWaiting << [y, s, false]
  32.   end
  33.  
  34.   #Get scroll details
  35.   def scroll_details(dis, s, hor)
  36.    
  37.     #if x-axis
  38.     if hor == true
  39.       dis -= 8
  40.       dis -= @display_x / 256
  41.    
  42.       #Get direction
  43.       if dis > 0
  44.         dir = 6
  45.       else
  46.         dir = 4
  47.         dis *= -1
  48.       end
  49.    
  50.     #if y-axis
  51.     else
  52.       dis -= 6
  53.       dis -= @display_y / 256
  54.       #Get direction
  55.       if dis > 0
  56.         dir = 2
  57.       else
  58.         dir = 8
  59.         dis *= -1
  60.       end
  61.     end    
  62.    
  63.     dis = 0 if dis < 0
  64.     return [dir, dis, s]
  65.   end
  66.  
  67.   #Clear Scroll List
  68.   def clear_scroll(finish = true)
  69.     @scrollWaiting = []
  70.     if !finish
  71.       @scroll_rest = 0
  72.     end
  73.   end
  74.  
  75.   #Return to player
  76.   def find_player(speed = 4)
  77.     @scrollWaiting << [-1, speed, true]
  78.     @scrollWaiting << [-1, speed, false]
  79.   end
  80.  
  81.   #Change refresh
  82.   alias update_scroll_to update unless $@
  83.   def update
  84.     update_scroll_to
  85.  
  86.     #If not already scrolling and if there are more scroll commands
  87.     if !scrolling?
  88.       if @scrollWaiting == nil
  89.         @scrollWaiting = []
  90.       elsif !@scrollWaiting.empty?
  91.         newScroll = @scrollWaiting[0]
  92.  
  93.         #If scroll to player
  94.         if newScroll[0] == -1
  95.           if newScroll[2] == true
  96.             xy = $game_player.x
  97.           else
  98.             xy = $game_player.y
  99.           end
  100.         else
  101.           xy = newScroll[0]
  102.         end
  103.        
  104.         newScroll = scroll_details(xy, newScroll[1], newScroll[2])
  105.         dir = newScroll[0]
  106.         dis = newScroll[1]
  107.         spe = newScroll[2]
  108.         start_scroll(dir, dis, spe)
  109.         @scrollWaiting.shift
  110.       end    
  111.     end
  112.   end
  113.  
  114. end
  115.  
Expand to see the code.
Nice script. This could be useful for cutscenes or showing the layout of areas for recon-esque scenes or when the player first enters an important area. This reminded me of how the later Gex game would do something akin to this, scrolling over to the level's current objective.
Thanks! Yeah, honestly, this could probably be used almost any time you want to use the normal scroll (to save you having to count out the number of spaces to the object) and any time you want to scroll to a variable place or you don't know where you'll be scrolling from(or both at once). It's something I've wanted in RPG Maker for ages and I only just realised today that I knew enough scripting to do it. :P
Can I make instant scroll with this script?
No, but this can:
  1. ###############################################################################
  2. #INSTANT SCROLL
  3. #By Pokemaniac
  4. #
  5. #Call $game_map.instant_scroll(x,y) to instantly 'scroll' to x, y.
  6. #
  7. #Call $game_map.instant_player to instantly 'scroll' to the player.
  8. #
  9. #This script is free-to-use. Credits are appreciated but not necessary at all.
  10. ###############################################################################
  11. class Game_Map
  12.  
  13.   #Set the display to an x, y co-ordinate instantly
  14.   def instant_scroll(x,y)
  15.     x -= 8
  16.     x = 0 if x < 0
  17.     x = (width - 17) if x > width - 17
  18.     x *= 256
  19.     y -= 6
  20.     y = 0 if y < 0
  21.     y = (height - 13) if y > height - 13
  22.     y *= 256
  23.     set_display_pos(x,y)
  24.   end
  25.  
  26.   #Sets the display to the x, y co-ordinates of the player instantly
  27.   def instant_player
  28.     x = $game_player.x
  29.     y = $game_player.y
  30.     instant_scroll(x,y)
  31.   end
  32.  
  33. end
  34.  
Expand to see the code.
Oh yeah, thanks. It's very helpfull.
Sorry for double post - I checked that instant scroll script - it didn't work.

It throws me an error:

Quote:
Script Instant Scroll line 23: NoMethodError
undefined method 'set_display_pos' for <Game_Map>


Any solution?
Are you using XP or VX? This is a VX script.
This is for VX, damn. :x

Can you make same script for XP, please?
Um, I'm a bit busy at the moment. Would someone like to take this? You'd just have to change the vocab, and change the 8, 6, 13 and 17 to the XP screen width/height in tiles, hopefully. Sorry!
Ok, thanks for tips, I'll try that.
  1. ###############################################################################
  2. #INSTANT SCROLL
  3. #By Pokemaniac
  4. #
  5. #Call $game_map.instant_scroll(x,y) to instantly 'scroll' to x, y.
  6. #
  7. #Call $game_map.instant_player to instantly 'scroll' to the player.
  8. #
  9. #This script is free-to-use. Credits are appreciated but not necessary at all.
  10. ###############################################################################
  11. class Game_Map
  12.  
  13.   #Set the display to an x, y co-ordinate instantly
  14.   def instant_scroll(x,y)
  15.     x -= 10
  16.     x = 0 if x < 0
  17.     x = (width - 20) if x > width - 20
  18.     x *= 128
  19.     y -= 7
  20.     y = 0 if y < 0
  21.     y = (height - 15) if y > height - 15
  22.     y *= 128
  23.     @display_x = x
  24.     @display_y = y
  25.   end
  26.  
  27.   #Sets the display to the x, y co-ordinates of the player instantly
  28.   def instant_player
  29.     x = $game_player.x
  30.     y = $game_player.y
  31.     instant_scroll(x,y)
  32.   end
  33.  
  34. end
Expand to see the code.


The centering's pretty bad because XP has a stupid amount of tiles, but there you go!

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