TheoAllen

Theo - Fast Travel V1.1

Apr 30th, 2013
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.83 KB | None | 0 0
  1. # ============================================================================
  2. # TheoAllen - Fast Travel
  3. # Author : TheoAllen
  4. # Version : 1.1
  5. # Contact : www.rpgmakerid.com
  6. # =-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  7. # Requested by : Rusty
  8. # Requires : Theo - Core Movement
  9. # ============================================================================
  10. $imported = {} if $imported.nil?
  11. if $imported[:Theo_Movement]
  12. $imported[:Theo_Travel] = true
  13. # ============================================================================
  14. # CHANGE LOGS:
  15. # ----------------------------------------------------------------------------
  16. # - 2013.05.07 - Add custom picture in maplists
  17. # - 2013.05.01 - Started and finished script
  18. # ============================================================================
  19. =begin
  20.  
  21.   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22.   PENGENALAN:
  23.   Script ini ngebikin kamu bisa bikin fast travel sendiri. Map-map yg bisa
  24.   dipake buat transfer dicatet dalam konfigurasi
  25.  
  26.   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  27.   CARA PEMAKAIAN:
  28.   Pasang script ini dibawah Theo - Core Movement.
  29.   Panggil dalam script call seperti ini:
  30.   -------------------------------------
  31.   map = [1,2,3]
  32.   travel(map) (atau-->) travel([1,2,3])
  33.   -------------------------------------
  34.  
  35.   Angka2 itu adalah id map yg bisa ditransfer yg u database sendiri di
  36.   kofigurasi ntar. Kalo semisal u pengen kasi gambar background, u bisa bikin
  37.   kek gini:
  38.  
  39.   -------------------------------------
  40.   travel([1,2,3],"peta")
  41.   -------------------------------------
  42.   "peta" adalah nama file gambar yg harus ada di folder Graphics/system
  43.  
  44.   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45.   TERMS OF USE :
  46.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  47.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  48.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  49.  
  50. =end
  51. # ============================================================================
  52. # KONFIGURASI ~
  53. # ============================================================================
  54. module THEO
  55.   module TRAVEL
  56.     # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  57.     # MAP DATABASE :
  58.     # -----------------------------------------------------------------------
  59.     # id => ["nama",map_id,x,y],
  60.     # id ntar buat dipanggil di script call
  61.     # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  62.     MAPLIST = {
  63.        1 => ["Alumnea",      1, 1, 1], # <-- kalo mo nambahin jgn lupa koma
  64.        2 => ["Eremidia",     2, 1, 1],
  65.        3 => ["Westerland",   3, 1, 1],
  66.        4 => ["Aldonia",      1, 1, 1],
  67.        5 => ["Vandaria",     2, 1, 1],
  68.        6 => ["Nirbhumi",     3, 1, 1],
  69.        # Tambahin sendiri disini
  70.        
  71.     } # <-- jangan diilangin
  72.    
  73.     # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  74.     # Settingan Window (kalo dirasa g perlu g usah diedit)
  75.     # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  76.     WINDOW_PIC    = "test2"
  77.     # picture pengganti window. tulis "nil" (tanpa petik) kalo g perlu
  78.     # ---------------------------------------------------------
  79.     TEXT_X        = 0       # pergeseran text ke kanan (kalo pake pic)
  80.     TEXT_Y        = 0       # pergeseran text ke bawah (kalo pake pic)
  81.     # ---------------------------------------------------------
  82.     LEBAR_WINDOW  = 200
  83.     # ---------------------------------------------------------
  84.     # Lebar window untuk nampilin nama petanya (kalo g pake pic)
  85.     # ---------------------------------------------------------
  86.     WINDOW_OFFSET = 4      
  87.     # ---------------------------------------------------------
  88.     # Jarak antar window
  89.     # ---------------------------------------------------------
  90.     MOVE_DURATION = 5
  91.     # ---------------------------------------------------------
  92.     # Kecepatan window ngegeser dalam satuan frame
  93.     # Misalnya kalo u nulis 60 maka window butuh waktu 1 detik
  94.     # buat sampe tujuan
  95.     # default : 5
  96.     # ---------------------------------------------------------
  97.     POSISI_X      = 4
  98.     POSISI_Y      = 4
  99.     # ---------------------------------------------------------
  100.     # Untuk ngatur posisi x ama y window
  101.     # ---------------------------------------------------------
  102.     UKURAN_FONT   = 24
  103.     # ---------------------------------------------------------
  104.     # Untuk ukuran font yg ditampilin di maplist ntar
  105.     # Default : 24
  106.     # ---------------------------------------------------------
  107.     TEXT_ALIGN    = 1
  108.     # ---------------------------------------------------------
  109.     # Untuk ngatur letak text
  110.     # 0 = ditulis dari kiri
  111.     # 1 = ditulis di tengah
  112.     # 2 = ditulis dari kanan
  113.     # ---------------------------------------------------------
  114.   end
  115. end
  116. # ============================================================================
  117. # Do not edit pass this line ~
  118. # ============================================================================
  119. class Window_TravelList < Window_Base
  120.   attr_accessor :id
  121.  
  122.   def initialize(x,y,text)
  123.     super(x,y,width,height)
  124.     contents.font.size = THEO::TRAVEL::UKURAN_FONT
  125.     @text = text
  126.     refresh
  127.   end
  128.  
  129.   def refresh
  130.     contents.clear
  131.     draw_text(0,0,contents.width,contents.font.size,@text,THEO::TRAVEL::TEXT_ALIGN)
  132.   end
  133.  
  134.   def width
  135.     THEO::TRAVEL::LEBAR_WINDOW
  136.   end
  137.  
  138.   def height
  139.     24 + THEO::TRAVEL::UKURAN_FONT
  140.   end
  141.  
  142. end
  143.  
  144. class Sprite_Maplist < Sprite
  145.   attr_accessor :id
  146. end
  147.  
  148. class Scene_Traveling < Scene_MenuBase
  149.  
  150.   def initialize(maplists_id, snapshot = nil)
  151.     @maps = []
  152.     maplists_id.each do |key|
  153.       @maps.push(THEO::TRAVEL::MAPLIST[key])
  154.     end
  155.     @snapshot = snapshot
  156.     @index = 0
  157.   end
  158.  
  159.   def start
  160.     super
  161.     create_maplist_window
  162.     update_windows
  163.   end
  164.  
  165.   def create_background
  166.     if @snapshot
  167.       @background_sprite = Sprite.new
  168.       @background_sprite.bitmap = Cache.system(@snapshot)
  169.     else
  170.       super
  171.     end
  172.   end
  173.  
  174.   def create_maplist_window
  175.     y_pos = THEO::TRAVEL::POSISI_Y
  176.     x_pos = THEO::TRAVEL::POSISI_X
  177.     @window_maplists = []
  178.     for i in 0..@maps.size-1
  179.       unless THEO::TRAVEL::WINDOW_PIC.is_a?(String)
  180.         make_window_maplists(x_pos,y_pos,i)
  181.         y_pos += THEO::TRAVEL::UKURAN_FONT + 24 + THEO::TRAVEL::WINDOW_OFFSET
  182.       else
  183.         window_sprite = Sprite_Maplist.new(@viewport)
  184.         window_sprite.y = y_pos
  185.         window_sprite.x = x_pos
  186.         window_sprite.bitmap = create_window_sprite_bitmap(i)
  187.         y_pos += window_sprite.bitmap.height + THEO::TRAVEL::WINDOW_OFFSET
  188.         make_sprite_maplist(window_sprite,i)
  189.       end
  190.     end
  191.   end
  192.  
  193.   def make_window_maplists(x,y,i)
  194.     @window_maplists.push(Window_TravelList.new(x,y,@maps[i][0]))
  195.     @window_maplists[i].id = i
  196.   end
  197.  
  198.   def create_window_sprite_bitmap(i)
  199.     bitmap = Bitmap.new("Graphics/System/" + THEO::TRAVEL::WINDOW_PIC)
  200.     x = THEO::TRAVEL::TEXT_X
  201.     y = THEO::TRAVEL::TEXT_Y
  202.     width = bitmap.width - x
  203.     bitmap.draw_text(x,y,width,THEO::TRAVEL::UKURAN_FONT,@maps[i][0],THEO::TRAVEL::TEXT_ALIGN)
  204.     return bitmap
  205.   end
  206.  
  207.   def make_sprite_maplist(window_sprite,i)
  208.     @window_maplists.push(window_sprite)
  209.     @window_maplists[i].id = i
  210.   end
  211.  
  212.   def update
  213.     super
  214.     update_cursor
  215.     @window_maplists.each {|window| window.update}
  216.     transfer_player if confirm?
  217.     return_scene if return?
  218.   end
  219.  
  220.   def update_cursor
  221.     if Input.repeat?(:DOWN)
  222.       @index += 1
  223.       correct_index
  224.       update_windows
  225.     elsif Input.repeat?(:UP)
  226.       @index -= 1
  227.       correct_index
  228.       update_windows
  229.     end
  230.   end
  231.  
  232.   def correct_index
  233.     @index = max_index if @index < 0
  234.     @index = 0 if @index > max_index
  235.   end
  236.  
  237.   def max_index
  238.     @maps.size - 1
  239.   end
  240.  
  241.   def update_windows
  242.     @window_maplists.each do |window|
  243.       if window.id == @index
  244.         window.goto(THEO::TRAVEL::POSISI_X+20,window.y,THEO::TRAVEL::MOVE_DURATION)
  245.       else
  246.         window.goto(THEO::TRAVEL::POSISI_X,window.y,THEO::TRAVEL::MOVE_DURATION)
  247.       end
  248.     end
  249.   end
  250.  
  251.   def transfer_player
  252.     map = @maps[@index]
  253.     id = map[1]
  254.     x = map[2]
  255.     y = map[3]
  256.     $game_player.reserve_transfer(id,x,y)
  257.     return_scene
  258.   end
  259.  
  260.   def confirm?
  261.     Input.trigger?(:C)
  262.   end
  263.  
  264.   def return_scene
  265.     SceneManager.return
  266.   end
  267.  
  268.   def return?
  269.     Input.trigger?(:B)
  270.   end
  271.  
  272. end
  273.  
  274. class Game_Interpreter
  275.  
  276.   def travel(maplist,snapshot = nil)
  277.     SceneManager.call_travel(maplist,snapshot)
  278.   end
  279.  
  280. end
  281.  
  282. module SceneManager
  283.  
  284.   def self.call_travel(maplist,snapshot = nil)
  285.     @stack.push(@scene)
  286.     @scene = Scene_Traveling.new(maplist,snapshot)
  287.   end
  288.  
  289. end
  290.  
  291. end
Advertisement
Add Comment
Please, Sign In to add comment