TheoAllen

Theo - Fast Travel EX

Jun 14th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.21 KB | None | 0 0
  1. # ============================================================================
  2. # TheoAllen - Fast Travel
  3. # Author : TheoAllen
  4. # Version : 1.0-ex
  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.06.15 - Added switch command
  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",      3, 1, 1],
  67.        5 => ["Vandaria",     3, 1, 1],
  68.        6 => ["Nirbhumi",     3, 1, 1],
  69.        # Tambahin sendiri disini
  70.     }
  71.    
  72.     SWITCHLIST = {
  73. # :Symbol => ["Command ",id],
  74.        :A => ["Switch 1", 1],
  75.        :B => ["Switch 2", 2],
  76.        :C => ["Switch 3", 3],
  77.        :D => ["Switch 4", 4],
  78.          
  79.        } # <-- jangan diilangin
  80.    
  81.     # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  82.     # Settingan Window (kalo dirasa g perlu g usah diedit)
  83.     # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  84.     WINDOW_PIC    = "test2"
  85.     # picture pengganti window. tulis nil (tanpa petik) kalo g perlu
  86.     # ---------------------------------------------------------
  87.     TEXT_X        = 0       # pergeseran text ke kanan (kalo pake pic)
  88.     TEXT_Y        = 0       # pergeseran text ke bawah (kalo pake pic)
  89.     # ---------------------------------------------------------
  90.     LEBAR_WINDOW  = 200
  91.     # ---------------------------------------------------------
  92.     # Lebar window untuk nampilin nama petanya
  93.     # ---------------------------------------------------------
  94.     WINDOW_OFFSET = 4      
  95.     # ---------------------------------------------------------
  96.     # Jarak antar window
  97.     # ---------------------------------------------------------
  98.     MOVE_DURATION = 5
  99.     # ---------------------------------------------------------
  100.     # Kecepatan window ngegeser dalam satuan frame
  101.     # Misalnya kalo u nulis 60 maka window butuh waktu 1 detik
  102.     # buat sampe tujuan
  103.     # default : 5
  104.     # ---------------------------------------------------------
  105.     POSISI_X      = 4
  106.     POSISI_Y      = 4
  107.     # ---------------------------------------------------------
  108.     # Untuk ngatur posisi x ama y window
  109.     # ---------------------------------------------------------
  110.     UKURAN_FONT   = 24
  111.     # ---------------------------------------------------------
  112.     # Untuk ukuran font yg ditampilin di maplist ntar
  113.     # Default : 24
  114.     # ---------------------------------------------------------
  115.     TEXT_ALIGN    = 1
  116.     # ---------------------------------------------------------
  117.     # Untuk ngatur letak text
  118.     # 0 = ditulis dari kiri
  119.     # 1 = ditulis di tengah
  120.     # 2 = ditulis dari kanan
  121.     # ---------------------------------------------------------
  122.   end
  123. end
  124. # ============================================================================
  125. # Do not edit pass this line ~
  126. # ============================================================================
  127. class Window_TravelList < Window_Base
  128.   attr_accessor :id
  129.  
  130.   def initialize(x,y,text)
  131.     super(x,y,width,height)
  132.     contents.font.size = THEO::TRAVEL::UKURAN_FONT
  133.     @text = text
  134.     refresh
  135.   end
  136.  
  137.   def refresh
  138.     contents.clear
  139.     draw_text(0,0,contents.width,contents.font.size,@text,
  140.       THEO::TRAVEL::TEXT_ALIGN)
  141.   end
  142.  
  143.   def width
  144.     THEO::TRAVEL::LEBAR_WINDOW
  145.   end
  146.  
  147.   def height
  148.     24 + THEO::TRAVEL::UKURAN_FONT
  149.   end
  150.  
  151. end
  152.  
  153. class Sprite_Maplist < Sprite
  154.   attr_accessor :id
  155. end
  156.  
  157. class Scene_Traveling < Scene_MenuBase
  158.  
  159.   def initialize(maplists_id, snapshot = nil)
  160.     @maps = []
  161.     maplists_id.each do |key|
  162.       if key.is_a?(Numeric)
  163.         @maps.push(THEO::TRAVEL::MAPLIST[key])
  164.       else
  165.         @maps.push(THEO::TRAVEL::SWITCHLIST[key])
  166.       end
  167.     end
  168.     @snapshot = snapshot
  169.     @index = 0
  170.   end
  171.  
  172.   def start
  173.     super
  174.     create_maplist_window
  175.     update_windows
  176.   end
  177.  
  178.   def create_background
  179.     if @snapshot
  180.       @background_sprite = Sprite.new
  181.       @background_sprite.bitmap = Cache.system(@snapshot)
  182.     else
  183.       super
  184.     end
  185.   end
  186.  
  187.   def create_maplist_window
  188.     y_pos = THEO::TRAVEL::POSISI_Y
  189.     x_pos = THEO::TRAVEL::POSISI_X
  190.     @window_maplists = []
  191.     for i in 0..@maps.size-1
  192.       unless THEO::TRAVEL::WINDOW_PIC.is_a?(String)
  193.         make_window_maplists(x_pos,y_pos,i)
  194.         y_pos += THEO::TRAVEL::UKURAN_FONT + 24 + THEO::TRAVEL::WINDOW_OFFSET
  195.       else
  196.         window_sprite = Sprite_Maplist.new(@viewport)
  197.         window_sprite.y = y_pos
  198.         window_sprite.x = x_pos
  199.         window_sprite.bitmap = create_window_sprite_bitmap(i)
  200.         y_pos += window_sprite.bitmap.height + THEO::TRAVEL::WINDOW_OFFSET
  201.         make_sprite_maplist(window_sprite,i)
  202.       end
  203.     end
  204.   end
  205.  
  206.   def make_window_maplists(x,y,i)
  207.     @window_maplists.push(Window_TravelList.new(x,y,@maps[i][0]))
  208.     @window_maplists[i].id = i
  209.   end
  210.  
  211.   def create_window_sprite_bitmap(i)
  212.     bitmap = Bitmap.new("Graphics/System/" + THEO::TRAVEL::WINDOW_PIC)
  213.     x = THEO::TRAVEL::TEXT_X
  214.     y = THEO::TRAVEL::TEXT_Y
  215.     width = bitmap.width - x
  216.     bitmap.draw_text(x,y,width,THEO::TRAVEL::UKURAN_FONT,@maps[i][0],THEO::TRAVEL::TEXT_ALIGN)
  217.     return bitmap
  218.   end
  219.  
  220.   def make_sprite_maplist(window_sprite,i)
  221.     @window_maplists.push(window_sprite)
  222.     @window_maplists[i].id = i
  223.   end
  224.  
  225.   def update
  226.     super
  227.     update_cursor
  228.     @window_maplists.each {|window| window.update}
  229.     transfer_player if confirm?
  230.     return_scene if return?
  231.   end
  232.  
  233.   def update_cursor
  234.     if Input.repeat?(:DOWN)
  235.       @index += 1
  236.       correct_index
  237.       update_windows
  238.     elsif Input.repeat?(:UP)
  239.       @index -= 1
  240.       correct_index
  241.       update_windows
  242.     end
  243.   end
  244.  
  245.   def correct_index
  246.     @index = max_index if @index < 0
  247.     @index = 0 if @index > max_index
  248.   end
  249.  
  250.   def max_index
  251.     @maps.size - 1
  252.   end
  253.  
  254.   def update_windows
  255.     @window_maplists.each do |window|
  256.       if window.id == @index
  257.         window.goto(THEO::TRAVEL::POSISI_X+20,window.y,THEO::TRAVEL::MOVE_DURATION)
  258.       else
  259.         window.goto(THEO::TRAVEL::POSISI_X,window.y,THEO::TRAVEL::MOVE_DURATION)
  260.       end
  261.     end
  262.   end
  263.  
  264.   def transfer_player
  265.     if @maps[@index].size == 2
  266.       $game_switches[@maps[@index][1]] = true
  267.     else
  268.       map = @maps[@index]
  269.       id = map[1]
  270.       x = map[2]
  271.       y = map[3]
  272.       $game_player.reserve_transfer(id,x,y)
  273.     end
  274.     return_scene
  275.   end
  276.  
  277.   def confirm?
  278.     Input.trigger?(:C)
  279.   end
  280.  
  281.   def return_scene
  282.     SceneManager.return
  283.   end
  284.  
  285.   def return?
  286.     Input.trigger?(:B)
  287.   end
  288.  
  289. end
  290.  
  291. class Game_Interpreter
  292.  
  293.   def travel(maplist,snapshot = nil)
  294.     SceneManager.call_travel(maplist,snapshot)
  295.   end
  296.  
  297. end
  298.  
  299. module SceneManager
  300.  
  301.   def self.call_travel(maplist,snapshot = nil)
  302.     @stack.push(@scene)
  303.     @scene = Scene_Traveling.new(maplist,snapshot)
  304.   end
  305.  
  306. end
  307.  
  308. end
Advertisement
Add Comment
Please, Sign In to add comment