TheoAllen

TC:T - Fast Travel

Feb 15th, 2014
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.53 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Fast Travel (2nd Edition)
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # -----------------------------------------------------------------------------
  7. # Scripted for :
  8. # - The Contract : Truth
  9. # - The Trail of Horizon
  10. # =============================================================================
  11. ($imported ||= {})[:Theo_FastTravel2] = true
  12. # =============================================================================
  13. # Change Logs:
  14. # -----------------------------------------------------------------------------
  15. # 2014.02.15 - Finished script
  16. # =============================================================================
  17. =begin
  18.  
  19.   -----------------------------------------------------------------------------
  20.   Perkenalan :
  21.   Script ini nambahin fitur buat fast travel atau teleport dari peta satu ke
  22.   peta lain.
  23.  
  24.   -----------------------------------------------------------------------------
  25.   Cara penggunaan :
  26.   Pasang script ini di bawah material namun di atas main
  27.   Untuk nambahin peta pada list, gunakan script call
  28.  
  29.   add_travelmap(map_id, x, y, d, snapshot)
  30.  
  31.   Keterangan :
  32.   map_id    >> ID map yang akan dituju
  33.   x         >> Posisi X yang akan dituju di map baru
  34.   y         >> Posisi Y yang akan dituju di map baru
  35.   d         >> Posisi hadap player (2 = bawah, 8 = atas, 4 = kiri, 6 = kanan)
  36.   snapshot  >> Screenshot dari peta. Gambar harus ada pada Graphics/system.
  37.                Direkomendasikan dimensi gambar adalah 240 x 200
  38.                
  39.   Contoh script call :
  40.   add_travelmap(3,15,15,2,"map001")
  41.  
  42.   Untuk nambahin menu fast travel pada main menu, gunakan script call.
  43.   $game_system.travel_menu = true
  44.  
  45.   Dan untuk nge-disable akses fast travel pada beberapa map, gunakan notetag
  46.   <no travel> pada notebox map properties
  47.  
  48.   -----------------------------------------------------------------------------
  49.   Terms of use :
  50.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  51.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  52.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.      
  53.  
  54. =end
  55. # =============================================================================
  56. # Konfigurasi :
  57. # =============================================================================
  58. module Theo
  59.   module TravelMap
  60.    
  61.   # Text untuk header  
  62.     Header      = "Fast Travel"
  63.  
  64.   # Text untuk nunjukin map saat ini player berada di mana
  65.     CurrentMap  = "Current Map :"
  66.  
  67.   # Title untuk info map
  68.     MapInfo     = "Map Infos"
  69.  
  70.   # Vokab untuk map name
  71.     MapName     = "Name :"
  72.  
  73.   # Vokab untuk snapshot map
  74.     Snapshot    = "Snapshot :"
  75.    
  76.   # Nama command pada menu
  77.     MenuCommand = "Fast Travel"
  78.  
  79.   # Format angka peta. Contoh penulisan format angka
  80.   # >> %d:%s    ---> 1:nama, 2:nama, 20:nama
  81.   # >> %03d:%s  ---> 001:nama, 002:nama, 034:nama
  82.   # >> %02d:%s  ---> 01:nama, 02:nama, 34:nama
  83.     Format   = "%02d:%s"
  84.    
  85.   end
  86. end
  87. # =============================================================================
  88. # Akhir dari konfigurasi. Dilarang mengubah apapun di bawah ini kecuali ente
  89. # tanggung sendiri semua resikonye... :v
  90. # =============================================================================
  91. # =============================================================================
  92. # ▼ Game_Interpreter
  93. # =============================================================================
  94. class Game_Interpreter
  95.  
  96.   def add_travelmap(id, x, y, d = 2, snapshot = '')
  97.     new_map = MapList.new(id, x, y, d, snapshot)
  98.     return if $game_system.travel_maps.any? do |map|
  99.       map == new_map
  100.     end
  101.     $game_system.travel_maps.push(new_map)
  102.   end
  103.  
  104. end
  105. # =============================================================================
  106. # ▼ New Class : MapList
  107. # =============================================================================
  108. class MapList
  109.   attr_accessor :id
  110.   attr_accessor :x
  111.   attr_accessor :y
  112.   attr_accessor :d
  113.   attr_accessor :snapshot
  114.  
  115.   def initialize(id, x, y, d, snapshot)
  116.     @id = id
  117.     @x = x
  118.     @y = y
  119.     @d = d
  120.     @snapshot = snapshot
  121.   end
  122.  
  123.   def name
  124.     load_data(sprintf("Data/Map%03d.rvdata2", id)).display_name
  125.   end
  126.  
  127.   def transfer_player
  128.     $game_player.reserve_transfer(id, x, y, d)
  129.     SceneManager.clear
  130.     SceneManager.goto(Scene_Map)
  131.   end
  132.  
  133.   def ==(other)
  134.     self.id == other.id && self.x == other.x && self.y == other.y
  135.   end
  136.  
  137. end
  138. # =============================================================================
  139. # ▼ Game_System
  140. # =============================================================================
  141. class Game_System
  142.   attr_accessor :travel_menu
  143.   attr_reader :travel_maps
  144.  
  145.   alias theo_travelmap_init initialize
  146.   def initialize
  147.     theo_travelmap_init
  148.     @travel_maps = []
  149.     @travel_menu = true
  150.   end
  151.  
  152. end
  153. # =============================================================================
  154. # ▼ Game_Map
  155. # =============================================================================
  156. class Game_Map
  157.  
  158.   def can_travel?
  159.     @map.note[/<no[\s_]+travel>/].nil?
  160.   end
  161.  
  162. end
  163. # =============================================================================
  164. # ▼ Window_MenuCommand
  165. # =============================================================================
  166. class Window_MenuCommand < Window_Command
  167.  
  168.   alias theo_travelmap_ori_command add_original_commands
  169.   def add_original_commands
  170.     theo_travelmap_ori_command
  171.     add_command(Theo::TravelMap::MenuCommand, :travel,
  172.       $game_map.can_travel?) if $game_system.travel_menu
  173.   end
  174.  
  175. end
  176. # =============================================================================
  177. # ▼ Scene_Menu
  178. # =============================================================================
  179. class Scene_Menu < Scene_MenuBase
  180.  
  181.   alias theo_travelmap_cmn_window create_command_window
  182.   def create_command_window
  183.     theo_travelmap_cmn_window
  184.     @command_window.set_handler(:travel, method(:on_travel_ok))
  185.   end
  186.  
  187.   def on_travel_ok
  188.     SceneManager.call(Scene_Travel)
  189.   end
  190.  
  191. end
  192. # =============================================================================
  193. # ▼ New Class : Window_TravelHeader
  194. # =============================================================================
  195. class Window_TravelHeader < Window_Base
  196.  
  197.   def initialize
  198.     super(0,0,window_width, window_height)
  199.     refresh
  200.   end
  201.  
  202.   def window_width
  203.     Graphics.width
  204.   end
  205.  
  206.   def window_height
  207.     fitting_height(1)
  208.   end
  209.  
  210.   def refresh
  211.     contents.clear
  212.     draw_text(contents.rect, Theo::TravelMap::Header, 1)
  213.   end
  214.  
  215. end
  216. # =============================================================================
  217. # ▼ New Class : Window_TravelList
  218. # =============================================================================
  219. class Window_TravelList < Window_Selectable
  220.  
  221.   def col_max
  222.     return 1
  223.   end
  224.  
  225.   def item_max
  226.     @data ? @data.size : 1
  227.   end
  228.  
  229.   def item
  230.     @data && index >= 0 ? @data[index] : nil
  231.   end
  232.  
  233.   def refresh
  234.     make_item_list
  235.     create_contents
  236.     draw_all_items
  237.   end
  238.  
  239.   def make_item_list
  240.     @data = $game_system.travel_maps
  241.   end
  242.  
  243.   def draw_item(index)
  244.     map = @data[index]        
  245.     draw_map_name(map,index) if map                    
  246.   end
  247.  
  248.   def draw_map_name(map, index)
  249.     rect = item_rect(index)
  250.     rect.x += 4
  251.     name = map.name  
  252.     number = index + 1
  253.     text = sprintf(Theo::TravelMap::Format,number,name)
  254.     draw_text(rect,text)
  255.   end
  256.  
  257.   def update_help
  258.     @help_window.set_item(item) if @help_window
  259.   end
  260.  
  261.   def current_item_enabled?
  262.     enable?(item)
  263.   end
  264.  
  265.   def enable?(item)
  266.     !item.nil?
  267.   end
  268.  
  269. end
  270. # =============================================================================
  271. # ▼ New Class : Window_TravelInfo
  272. # =============================================================================
  273. class Window_TravelInfo < Window_Base
  274.  
  275.   def set_item(item)
  276.     @item = item
  277.     refresh
  278.   end
  279.  
  280.   def refresh
  281.     contents.clear
  282.     return unless @item
  283.     change_color(system_color)
  284.     draw_text(line_rect(0), Theo::TravelMap::MapInfo, 1)
  285.     draw_text(line_rect(1), Theo::TravelMap::MapName)
  286.     draw_text(line_rect(3), Theo::TravelMap::Snapshot)
  287.     change_color(normal_color)
  288.     draw_text(line_rect(2), @item.name)
  289.     bmp = Cache.system(@item.snapshot)
  290.     contents.blt(0,4 * line_height, bmp, bmp.rect)
  291.   end
  292.  
  293.   def line_rect(line)
  294.     Rect.new(0, line * line_height, contents.width, line_height)
  295.   end
  296.  
  297. end
  298. # =============================================================================
  299. # ▼ New Class : Window_CurrentMap
  300. # =============================================================================
  301. class Window_CurrentMap < Window_Base
  302.  
  303.   def initialize(y)
  304.     super(0,y,window_width, window_height)
  305.     refresh
  306.   end
  307.  
  308.   def window_width
  309.     Graphics.width
  310.   end
  311.  
  312.   def window_height
  313.     fitting_height(1)
  314.   end
  315.  
  316.   def refresh
  317.     contents.clear
  318.     rect = contents.rect
  319.     change_color(system_color)
  320.     draw_text(rect, Theo::TravelMap::CurrentMap)
  321.     change_color(normal_color)
  322.     draw_text(rect, $game_map.display_name, 2)
  323.   end
  324.  
  325. end
  326. # =============================================================================
  327. # ▼ New Class : Scene_Travel
  328. # =============================================================================
  329. class Scene_Travel < Scene_MenuBase
  330.  
  331.   def start
  332.     super
  333.     create_header
  334.     create_maplist
  335.     create_mapinfo
  336.     create_footer
  337.   end
  338.  
  339.   def create_header
  340.     @header = Window_TravelHeader.new
  341.   end
  342.  
  343.   def create_maplist
  344.     y = @header.height
  345.     w = Graphics.width/2
  346.     h = Graphics.height - @header.height*2
  347.     @maplist = Window_TravelList.new(0,y,w,h)
  348.     @maplist.set_handler(:ok,     method(:on_map_ok))
  349.     @maplist.set_handler(:cancel, method(:on_map_cancel))
  350.     @maplist.refresh
  351.     @maplist.activate
  352.     @maplist.select(0)
  353.   end
  354.  
  355.   def create_mapinfo
  356.     x = @maplist.width
  357.     y = @maplist.y
  358.     w = @maplist.width
  359.     h = @maplist.height
  360.     @mapinfo = Window_TravelInfo.new(x,y,w,h)
  361.     @maplist.help_window = @mapinfo
  362.   end
  363.  
  364.   def create_footer
  365.     y = @header.height + @maplist.height
  366.     @footer = Window_CurrentMap.new(y)
  367.   end
  368.  
  369.   def on_map_ok
  370.     @maplist.item.transfer_player
  371.   end
  372.  
  373.   def on_map_cancel
  374.     return_scene
  375.   end
  376.  
  377. end
Advertisement
Add Comment
Please, Sign In to add comment