pigu_6

XS| Teleport fast travel

Dec 14th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.92 KB | None | 0 0
  1. #==============================================================================
  2. # XaiL System - Teleport
  3. # Author: Nicke
  4. # Created: 10/01/2012
  5. # Edited: 03/04/2012
  6. # Version: 1.0a
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ? Materials but above ? Main. Remember to save.
  12. #
  13. # To call this scene in a menu or on the map simply use the following code:
  14. # SceneManager.call(Scene_Teleport)
  15. #
  16. # To add/del a teleport, do this in a script call:
  17. # tp(id, type, enabled = true)
  18. # Examples:
  19. # tp(2, :add) # This will add id 2.
  20. # tp(2, :del) # This will delete id 2.
  21. #
  22. # To check if id is added or enabled/disabled do the following, preferably in a
  23. # conditional branch:
  24. # tp_added?(id)
  25. # tp_enable?(id)
  26. # Examples:
  27. # tp_added?(2) # Is id 2 added?
  28. # tp_enabled?(1) # Is id 1 enabled?
  29. # !tp_enabled?(3) # Same method used but returns true if it is disabled.
  30. #
  31. # To enable/disabling a id do like this:
  32. # tp_enable(1, true) # Enable id 1.
  33. # tp_enable(2, false) # Disable id 2.
  34. #
  35. # If you want to add/delete all the id's in the list use this method:
  36. # Note: This method uses the normal way of adding a tp. I created this method
  37. # to save some space in the event page when adding a large amount of id's.
  38. # tp_all(:add) # Add all id's.
  39. # tp_all(:del) # Remove all id's.
  40. #
  41. # Read the settings carefully when setting up new teleport location as well as
  42. # how to change certain settings. Make sure you change the settings as you
  43. # want them and hopefully you will be pleased. Enjoy!
  44. #
  45. # *** Only for RPG Maker VX Ace. ***
  46. #==============================================================================
  47. ($imported ||= {})["XAIL-XS-TELEPORT-SCENE"] = true
  48.  
  49. module XAIL
  50. module TELEPORT
  51. #--------------------------------------------------------------------------#
  52. # * Settings
  53. #--------------------------------------------------------------------------#
  54. # TP_FONT = [ name, size, color, bold, italic, shadow ]
  55. TP_CMD_FONT = [["Verdana"], 16, Color.new(255,255,255), true, false, false]
  56. TP_INFO_FONT = [["Verdana"], 14, Color.new(155,205,205), true, false, true]
  57.  
  58. # The windowskin to use for the windows. Set to nil to disable.
  59. # SKIN = string
  60. SKIN = nil
  61.  
  62. # Use this template when adding a long string to the map details.
  63. # Use \n to get to a new line.
  64. # TP_INFO_ID = long string
  65. TP_INFO_1 = "This is a very long string so that you can see how it may\nwork when using a super long string. :-)"
  66. TP_INFO_2 = "This is just a text explaining the map info."
  67. TP_INFO_3 = "Since this map is disabled i.e no teleporting allowed the\ncommand is disabled as well as the text."
  68.  
  69. # How many lines the info window should display.
  70. # If you do have long strings in the info I suggest changing this.
  71. # TP_INFO_LINES = number
  72. TP_INFO_LINES = 3
  73.  
  74. # Sets the padding of the text in the info window.
  75. TP_INFO_PADDING = 10 # Default: 12.
  76.  
  77. # TELEPORT_LIST:
  78. # ID = ['Title', :symbol, map_id, x & y, map_image(nil), map_info(nil),
  79. # enabled, icon_index]
  80. TP_LIST = [] # Don't remove!
  81. TP_LIST[0] = ['Weird Lake', :weird_map, 1, [15,11], "map_test", TP_INFO_1, true, 321]
  82. TP_LIST[1] = ['World Map', :world_map, 2, [12,3],"map_test2", TP_INFO_2, true, nil]
  83. TP_LIST[2] = ['Disabled Map', :disabled, 2, [1,1],"map_test2", TP_INFO_3, false, 327]
  84.  
  85. # Empty icon index. Which icon should be in use if TP_LIST icon_index is nil.
  86. # EMPTY_ICON_INDEX = icon_index
  87. EMPTY_ICON_INDEX = 0
  88.  
  89. # Display texts. Should be easy enough to understand what they are for.
  90. TEXT_NO_TELEPORTS = "You haven't found a location to teleport to."
  91. OK_NAME = "Teleport" # Dialog box ok.
  92. OK_CANCEL = "Cancel" # Dialog box cancel.
  93.  
  94. # Transition, nil to use default.
  95. # TRANSITION [ SPEED, TRANSITION, OPACITY ]
  96. # TRANSITION = [40, "Graphics/Transitions/1", 50]
  97. TRANSITION = nil
  98.  
  99. # Background image (System folder)
  100. # Note: You might want to decrease the opacity as well as arrange
  101. # the windows so that you can properly see the background.
  102. # Set to nil to use default.
  103. BACK = nil
  104.  
  105. # Should a animation be used when teleporting to a new map.
  106. # Set it to nil to disable it.
  107. ANIM_ID = 81
  108.  
  109. # Fade out time when teleporting to a new map.
  110. # 1000 (1 second)
  111. # ANIM_SCENE_FADE/ANIM_AUDIO_FADE = number
  112. ANIM_SCENE_FADE = 500 # Fade out time for scene.
  113. ANIM_AUDIO_FADE = 500 # Fade out time for audio.
  114.  
  115. end
  116. end
  117. # *** Don't edit below unless you know what you are doing. ***
  118. #==============================================================================#
  119. # ** Game_System
  120. #------------------------------------------------------------------------------
  121. # Method for checking the teleport list.
  122. #==============================================================================#
  123. class Game_System
  124.  
  125. attr_accessor :tp_list
  126.  
  127. alias xail_teleport_sys_initialize initialize
  128. def initialize(*args, &block)
  129. xail_teleport_sys_initialize(*args, &block)
  130. @tp_list = []
  131. end
  132.  
  133. end
  134. #==============================================================================#
  135. # ** Game_Interpreter
  136. #------------------------------------------------------------------------------
  137. # Method for adding and deleting a teleport.
  138. #==============================================================================#
  139. class Game_Interpreter
  140.  
  141. def tp(id, type)
  142. # // Method to add a item to the list.
  143. case type
  144. when :add # // Add teleport id.
  145. unless $game_system.tp_list.include?(XAIL::TELEPORT::TP_LIST[id])
  146. $game_system.tp_list.push(XAIL::TELEPORT::TP_LIST[id])
  147. end unless XAIL::TELEPORT::TP_LIST[id].nil?
  148. when :del # // Remove teleport id.
  149. unless XAIL::TELEPORT::TP_LIST[id].nil?
  150. $game_system.tp_list.delete(XAIL::MENU::TP_LIST[id])
  151. end
  152. end
  153. end
  154.  
  155. def tp_enabled?(id)
  156. # // Method to check if id is enabled.
  157. # (Must be added in the list or else it returns nil).
  158. return if $game_system.tp_list[id].nil?
  159. return $game_system.tp_list[id][6]
  160. end
  161.  
  162. def tp_added?(id)
  163. # // Method to check if id is added.
  164. return $game_system.tp_list[id]
  165. end
  166.  
  167. def tp_enable(id, enabled)
  168. # // Method to enable id.
  169. $game_system.tp_list[id][6] = enabled
  170. end
  171.  
  172. def tp_all(type = :add)
  173. # // Method to add/delete all teleport id's.
  174. id = 0
  175. while id < XAIL::TELEPORT::TP_LIST.size
  176. case type
  177. when :add
  178. tp(id, :add)
  179. else
  180. tp(id, :del)
  181. end
  182. id += 1
  183. end
  184. end
  185.  
  186. end
  187. #==============================================================================#
  188. # ** Window_TeleportCommand
  189. #------------------------------------------------------------------------------
  190. # New Window :: Window_TeleportCommand - A window for creating the commands.
  191. #==============================================================================#
  192. class Window_TeleportCommand < Window_Command
  193.  
  194. def window_width
  195. # // Method to return the width.
  196. return 160
  197. end
  198.  
  199. def window_height
  200. # // Method to return the height.
  201. return Graphics.height
  202. end
  203.  
  204. def menu_color(color, enabled = true)
  205. # // Method to set the color and alpha if not enabled.
  206. contents.font.color.set(color)
  207. contents.font.color.alpha = 100 unless enabled
  208. end
  209.  
  210. def draw_item(index)
  211. # // Method to draw the command item.
  212. contents.font.name = XAIL::TELEPORT::TP_CMD_FONT[0]
  213. contents.font.size = XAIL::TELEPORT::TP_CMD_FONT[1]
  214. menu_color(XAIL::TELEPORT::TP_CMD_FONT[2], menu_enabled?(index))
  215. contents.font.bold = XAIL::TELEPORT::TP_CMD_FONT[3]
  216. contents.font.italic = XAIL::TELEPORT::TP_CMD_FONT[4]
  217. contents.font.shadow = XAIL::TELEPORT::TP_CMD_FONT[5]
  218. draw_text(item_rect_for_icons(index), command_name(index), alignment)
  219. draw_tp_icons(index)
  220. reset_font_settings
  221. end
  222.  
  223. def draw_tp_icons(index)
  224. # // Method to draw the icons.
  225. # If there is no icon as in nil return a empty
  226. # icon index
  227. y = 0
  228. for i in @tp_list
  229. icon = i[7].nil? ? XAIL::TELEPORT::EMPTY_ICON_INDEX : i[7]
  230. draw_icon(icon, 0, y, menu_enabled?(index))
  231. y += 24
  232. end
  233. end
  234.  
  235. def item_rect_for_icons(index)
  236. # // Method to draw the text with icons.
  237. rect = item_rect(index)
  238. rect.x += 24
  239. rect.width -= 8
  240. rect
  241. end
  242.  
  243. def menu_enabled?(index)
  244. # // Method to check if item is enabled.
  245. return @tp_list[index][6]
  246. end
  247.  
  248. alias xail_mk_cmd_list_tp make_command_list
  249. def make_command_list(*args, &block)
  250. # // Method to add the commands.
  251. xail_mk_cmd_list_tp(*args, &block)
  252. @tp_list = $game_system.tp_list
  253. for i in @tp_list
  254. add_command(i[0], i[1], i[6])
  255. end
  256. end
  257.  
  258. end
  259. #==============================================================================#
  260. # ** Window_OK_Command
  261. #==============================================================================#
  262. class Window_OK_Command < Window_Command
  263.  
  264. def window_width
  265. # // Method to return the width.
  266. return 120
  267. end
  268.  
  269. def alignment
  270. # // Method to return the alignment.
  271. return 1
  272. end
  273.  
  274. alias xail_mk_cmd_list_ok make_command_list
  275. def make_command_list(*args, &block)
  276. # // Method to add the commands.
  277. xail_mk_cmd_list_ok(*args, &block)
  278. add_command(XAIL::TELEPORT::OK_NAME, :ok)
  279. add_command(XAIL::TELEPORT::OK_CANCEL, :cancel)
  280. end
  281.  
  282. end
  283. #==============================================================================#
  284. # ** Window_tpInfo
  285. #==============================================================================#
  286. class Window_tpInfo < Window_Base
  287.  
  288. def initialize(x, y, width, height)
  289. # // Method to initialize the window.
  290. super(0, 0, width, window_height)
  291. @tp_list = $game_system.tp_list
  292. refresh
  293. end
  294.  
  295. def set_text(text, enabled)
  296. # // Method to set a new the tp text to the window.
  297. if text != @text
  298. @text = text
  299. menu_color(XAIL::TELEPORT::TP_INFO_FONT[2], enabled)
  300. refresh
  301. end
  302. end
  303.  
  304. def window_height
  305. # // Method to return the height.
  306. return fitting_height(XAIL::TELEPORT::TP_INFO_LINES)
  307. end
  308.  
  309. def standard_padding
  310. # // Method to set the padding for text.
  311. return XAIL::TELEPORT::TP_INFO_PADDING
  312. end
  313.  
  314. def refresh
  315. # // Method to refresh the window.
  316. contents.clear
  317. draw_tp_text
  318. end
  319.  
  320. def menu_color(color, enabled = true)
  321. # // Method to set the color and alpha if not enabled.
  322. contents.font.color.set(color)
  323. contents.font.color.alpha = 150 unless enabled
  324. end
  325.  
  326. def draw_tp_ex(x, y, text)
  327. # // Special method to draw a text.
  328. text = convert_escape_characters(text)
  329. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  330. process_character(text.slice!(0, 1), text, pos) until text.empty?
  331. end
  332.  
  333. def draw_tp_text
  334. # // Method to draw the tp text to the window.
  335. contents.font.name = XAIL::TELEPORT::TP_INFO_FONT[0]
  336. contents.font.size = XAIL::TELEPORT::TP_INFO_FONT[1]
  337. contents.font.bold = XAIL::TELEPORT::TP_INFO_FONT[3]
  338. contents.font.italic = XAIL::TELEPORT::TP_INFO_FONT[4]
  339. contents.font.shadow = XAIL::TELEPORT::TP_INFO_FONT[5]
  340. draw_tp_ex(0, 0, @text)
  341. reset_font_settings
  342. end
  343.  
  344. end
  345. #==============================================================================#
  346. # ** Window_tpImage
  347. #==============================================================================#
  348. class Window_tpImage < Window_Base
  349.  
  350. def initialize(x, y, width, height)
  351. # // Method to initialize the window.
  352. super(0, 0, width, height)
  353. refresh
  354. end
  355.  
  356. def refresh
  357. # // Method to refresh the window.
  358. contents.clear
  359. end
  360.  
  361. def draw_tp_map(x, y, source, enabled = true)
  362. # // Method to draw the teleport map.
  363. rect = Rect.new(0, 0, Graphics.width, Graphics.height)
  364. return clear_tp_map(rect) if source.nil?
  365. clear_tp_map(rect)
  366. tp_map = Cache.picture(source)
  367. contents.blt(x, y, tp_map, rect, enabled ? 255 : 150)
  368. end
  369.  
  370. def clear_tp_map(rect)
  371. # // Method to clear tp_map rect.
  372. contents.clear_rect(rect)
  373. end
  374.  
  375. end
  376. #==============================================================================#
  377. # ** Scene_TeleportBase
  378. #------------------------------------------------------------------------------
  379. # New Scene :: Scene_TeleportBase - The teleport scene.
  380. #==============================================================================#
  381. class Scene_TeleportBase < Scene_Base
  382.  
  383. alias xail_tpbase_start start
  384. def start(*args, &block)
  385. # // Method to start the scene
  386. xail_tpbase_start(*args, &block)
  387. @tp_list = $game_system.tp_list
  388. create_background
  389. end
  390.  
  391. def post_start
  392. # // Method to post_start the scene.
  393. perform_transition unless @tp_list.empty?
  394. end
  395.  
  396. alias xail_tpbase_terminate terminate
  397. def terminate(*args, &block)
  398. # // Method to terminate the scene.
  399. xail_tpbase_terminate(*args, &block)
  400. end
  401.  
  402. def create_background
  403. # // Method to create the background.
  404. @background_sprite = Sprite.new
  405. if XAIL::TELEPORT::BACK.nil?
  406. @background_sprite.bitmap = SceneManager.background_bitmap
  407. @background_sprite.color.set(16, 16, 16, 128)
  408. else
  409. @background_sprite.bitmap = Cache.system(XAIL::TELEPORT::BACK)
  410. end
  411. end
  412.  
  413. alias xail_tpbase_transition perform_transition
  414. def perform_transition(*args, &block)
  415. # // Method to create the transition.´
  416. if XAIL::TELEPORT::TRANSITION.nil?
  417. Graphics.transition(15)
  418. else
  419. Graphics.transition(XAIL::TELEPORT::TRANSITION[0],XAIL::TELEPORT::TRANSITION[1],XAIL::TELEPORT::TRANSITION[2])
  420. end
  421. xail_tpbase_transition(*args, &block)
  422. end
  423.  
  424. end
  425. #==============================================================================#
  426. # ** Scene_Teleport
  427. #------------------------------------------------------------------------------
  428. # New Scene :: Scene_Teleport - The teleport scene.
  429. #==============================================================================#
  430. class Scene_Teleport < Scene_TeleportBase
  431.  
  432. alias xail_tpbase_init initialize
  433. def initialize(*args, &block)
  434. # // Method to initialize scene teleport.
  435. xail_tpbase_init(*args, &block)
  436. @tp_list = $game_system.tp_list
  437. end
  438.  
  439. def start
  440. # // Method to start scene teleport.
  441. super
  442. return command_map if @tp_list.empty?
  443. create_tp_command_window
  444. create_tp_info
  445. create_tp_image
  446. on_index_change(0) # // Draw id 0 when scene is loaded.
  447. end
  448.  
  449. def create_tp_command_window
  450. # // Method to create command list window.
  451. @command_window = Window_TeleportCommand.new(0, 0)
  452. @command_window.windowskin = Cache.system(XAIL::TELEPORT::SKIN) unless XAIL::TELEPORT::SKIN.nil?
  453. for i in @tp_list
  454. @command_window.set_handler(i[1], method(:command_ok_dialog))
  455. end
  456. @command_window.set_handler(:cancel, method(:return_scene))
  457. end
  458.  
  459. def create_ok_window
  460. # // Method to create ok command window.
  461. @ok_window = Window_OK_Command.new(0, 0)
  462. @ok_window.windowskin = Cache.system(XAIL::TELEPORT::SKIN) unless XAIL::TELEPORT::SKIN.nil?
  463. @ok_window.x = (Graphics.width - @ok_window.width) / 2
  464. @ok_window.y = (Graphics.height - @ok_window.height) / 2
  465. @ok_window.set_handler(:ok, method(:command_teleport))
  466. @ok_window.set_handler(:cancel, method(:command_cancel_dialog))
  467. end
  468.  
  469. def create_tp_info
  470. # // Method to create teleport info window.
  471. width = Graphics.width - @command_window.width
  472. height = 80
  473. @tp_info = Window_tpInfo.new(0, 0, width, height)
  474. @tp_info.windowskin = Cache.system(XAIL::TELEPORT::SKIN) unless XAIL::TELEPORT::SKIN.nil?
  475. @tp_info.x = @command_window.width
  476. @tp_info.y = 0
  477. end
  478.  
  479. def create_tp_image
  480. # // Method to create teleport image window.
  481. width = Graphics.width - @command_window.width
  482. height = Graphics.height - @tp_info.height
  483. @tp_image_window = Window_tpImage.new(0, 0, width, height)
  484. @tp_image_window.windowskin = Cache.system(XAIL::TELEPORT::SKIN) unless XAIL::TELEPORT::SKIN.nil?
  485. @tp_image_window.x = @command_window.width
  486. @tp_image_window.y = @tp_info.height
  487. end
  488.  
  489. def create_tp_message_window
  490. # // Method to create the message window.
  491. @message_window = Window_Message.new
  492. end
  493.  
  494. def command_ok_dialog
  495. # // Method to open ok dialog.
  496. create_ok_window
  497. end
  498.  
  499. def command_cancel_dialog
  500. # // Method to close ok dialog.
  501. @ok_window.close
  502. @command_window.active = true
  503. end
  504.  
  505. def command_teleport
  506. # // Method to teleport the player.
  507. teleport_player(@command_window.index)
  508. end
  509.  
  510. def command_map
  511. # // command_map (Don't remove)
  512. create_tp_message_window
  513. $game_message.texts << XAIL::TELEPORT::TEXT_NO_TELEPORTS
  514. SceneManager.call(Scene_Map)
  515. end
  516.  
  517. def teleport_player(index)
  518. # // Method for teleporting the player to the spawn event. (if exists)
  519. $game_map.setup(@tp_list[index][2])
  520. $game_player.moveto(@tp_list[index][3][0], @tp_list[index][3][1])
  521. fadeout_scene
  522. $game_map.autoplay
  523. $game_map.refresh
  524. $game_player.animation_id = XAIL::TELEPORT::ANIM_ID unless XAIL::TELEPORT::ANIM_ID.nil?
  525. SceneManager.call(Scene_Map)
  526. end
  527.  
  528. def fadeout_scene
  529. time = XAIL::TELEPORT::ANIM_AUDIO_FADE
  530. # // Method to fade out the scene.
  531. RPG::BGM.fade(time)
  532. RPG::BGS.fade(time)
  533. RPG::ME.fade(time)
  534. Graphics.fadeout(XAIL::TELEPORT::ANIM_SCENE_FADE * Graphics.frame_rate / 1000)
  535. RPG::BGM.stop
  536. RPG::BGS.stop
  537. RPG::ME.stop
  538. end
  539.  
  540. def draw_tp_image(index)
  541. # // Draw teleport image.
  542. image = @tp_list[index][4]
  543. enabled = @tp_list[index][6]
  544. @tp_image_window.draw_tp_map(0, 0, image, enabled)
  545. end
  546.  
  547. def draw_tp_info(index)
  548. # // Draw teleport details.
  549. title = @tp_list[index][0]
  550. info = @tp_list[index][5]
  551. enabled = @tp_list[index][6]
  552. text = "#{title}\n#{info}" unless @tp_list[index][5].nil?
  553. @tp_info.set_text(text, enabled)
  554. end
  555.  
  556. alias xail_upd_tp_index_change update
  557. def update(*args, &block)
  558. # // Method for updating the scene.
  559. old_index = @command_window.index
  560. xail_upd_tp_index_change(*args, &block)
  561. on_index_change(@command_window.index) if old_index != @command_window.index
  562. end
  563.  
  564. def on_index_change(index)
  565. # // If index changes redraw the image and info.
  566. draw_tp_image(index)
  567. draw_tp_info(index)
  568. end
  569.  
  570. end # END OF FILE
  571.  
  572. #=*==========================================================================*=#
  573. # ** END OF FILE
  574. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment