Advertisement
Guest User

Simple Teleport

a guest
Dec 29th, 2011
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.76 KB | None | 0 0
  1. #==============================================================================
  2. #   Simple Teleport
  3. #   Author: Nicke
  4. #   Created: 17/12/2011
  5. #   Edited: 23/12/2011
  6. #   Version: 1.1
  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 use this script simply use the script command in a event to add a
  14. # teleport id.
  15. #
  16. # To call this scene in a menu or on the map simply use the following code:
  17. # $scene = Scene_Teleport.new
  18. #
  19. # Note: It will show a text instead if no teleport id(s) is found.
  20. #
  21. # Examples:
  22. # tp_add(1)
  23. # tp_add(2)
  24. # tp_del(1)
  25. #
  26. # To get the player to be teleported to a specific x and y coordinates use an
  27. # event and inside it create a comment for it with the same text as TEXT_SPAWN.
  28. # This will make the event the place to be teleported to within the map.
  29. #
  30. # If no such event exists on the map it will use the previous x and y position of
  31. # the player when teleporting on to the new map.
  32. #
  33. # You should always have a spawn event so you know where the player will be
  34. # teleported to. (Don't add more then one spawn event on each teleport maps.)
  35. #
  36. #==============================================================================
  37. ($imported ||= {})["NICKE-SIMPLE-TELEPORT"] = true
  38.  
  39. module NICKE
  40.   module TELEPORT
  41.   #--------------------------------------------------------------------------#
  42.   # * Settings
  43.   #--------------------------------------------------------------------------#
  44.   # Teleport Window [ Columns, x, y, z, opacity ]  
  45.     WINDOW = [3, 0, 0, 200, 255]
  46.    
  47.   # Should a animation be used when teleporting to a new map.
  48.   # Set it to nil to disable it.
  49.     ANIM_ID = 88
  50.    
  51.   # Texts.
  52.     TEXT_SPAWN = "TeleporterSpawn"
  53.     TEXT_NO_TELEPORTS = "You haven't found a location to teleport to."
  54.    
  55.   # Use a image as background instead.
  56.   # Set to nil to disable.
  57.     BACK = nil
  58.    
  59.   # Transition when opening the scene.  
  60.   # Set to nil to use default.  
  61.   # TRANSITION [ SPEED, TRANSITION, OPACITY ]
  62.   # TRANSITION =    [40, "Graphics/Transitions/1", 50]
  63.     TRANSITION = nil
  64.  
  65.   # Fade out time when teleporting to a new map.
  66.     FADE_TIME = 80
  67.    
  68.   # Return scene
  69.   # Set to nil to return to map instead.
  70.   # RETURN_SCENE = Index to return to in the menu.
  71.     RETURN_SCENE = 5
  72.    
  73.   # TELEPORT_LIST [ MAP_ID, Teleport name ]  
  74.     TELEPORT_LIST = [] # Don't remove!
  75.     TELEPORT_LIST[0] = [4, 'Fine Village']
  76.     TELEPORT_LIST[1] = [18, 'A Town']
  77.     TELEPORT_LIST[2] = [13, 'Townhold']
  78.     TELEPORT_LIST[3] = [17, 'Cave']
  79.   end
  80. end
  81. # *** Don't edit below unless you know what you are doing. ***
  82. #==============================================================================#
  83. # ** Game_Map
  84. #------------------------------------------------------------------------------
  85. #  Method for getting the teleport spawn.
  86. #==============================================================================#
  87. class Game_Map
  88.  
  89.   def teleport_spawn
  90.     for event in @events.values
  91.       next if event.nil?
  92.       next if event.list.nil?
  93.       for e in event.list
  94.         # // Check every event to see if the teleport spawn text exist in a event.
  95.         if e.code == 108 && e.parameters[0].include?(NICKE::TELEPORT::TEXT_SPAWN)
  96.           # // Move the player to the spawn event.
  97.           $game_player.moveto(event.x, event.y)
  98.         else
  99.           # // If none found use the player's x/y position instead.
  100.           # // * Not recommended to use. *
  101.           $game_player.moveto($game_player.x, $game_player.y)
  102.         end
  103.       end
  104.     end
  105.   end
  106.  
  107. end
  108. #==============================================================================#
  109. # ** Game_System
  110. #------------------------------------------------------------------------------
  111. #  Method for checking the teleport list.
  112. #==============================================================================#
  113. class Game_System
  114.  
  115.   attr_accessor :teleport_list
  116.   alias nicke_teleport_sys_initialize initialize unless $@
  117.   def initialize(*args, &block)
  118.     nicke_teleport_sys_initialize(*args, &block)
  119.     @teleport_list = []
  120.   end
  121.  
  122. end
  123. #==============================================================================#
  124. # ** Game_Interpreter
  125. #------------------------------------------------------------------------------
  126. #  Method for adding and deleting a teleport.
  127. #==============================================================================#
  128. class Game_Interpreter
  129.  
  130.   def tp_add(id)
  131.     # // Method to add a teleport from the list.  
  132.     unless $game_system.teleport_list.include?(NICKE::TELEPORT::TELEPORT_LIST[id])
  133.       $game_system.teleport_list.push(NICKE::TELEPORT::TELEPORT_LIST[id])
  134.     end unless NICKE::TELEPORT::TELEPORT_LIST[id].nil?
  135.   end
  136.  
  137.   def tp_del(id)
  138.     # // Method to delete a teleport from the list.  
  139.     unless NICKE::TELEPORT::TELEPORT_LIST[id].nil?
  140.         $game_system.teleport_list.delete(NICKE::TELEPORT::TELEPORT_LIST[id])
  141.     end
  142.   end
  143.  
  144. end
  145. #==============================================================================#
  146. # ** Scene_Teleport
  147. #------------------------------------------------------------------------------
  148. #  New Scene :: Scene_Teleport
  149. #==============================================================================#
  150. class Scene_Teleport < Scene_Base
  151.  
  152.   def initialize(index = 0)
  153.     @teleport_index = index
  154.   end
  155.  
  156.   def start
  157.     super
  158.     create_menu_background
  159.     create_command_window
  160.   end
  161.  
  162.   def create_command_window
  163.     teleport_menu = []
  164.     @teleport_list = $game_system.teleport_list
  165.     @message_window = Window_Message.new
  166.     if @teleport_list.empty?
  167.       Sound.play_buzzer
  168.       $game_message.texts << NICKE::TELEPORT::TEXT_NO_TELEPORTS
  169.       $scene = Scene_Map.new
  170.     else
  171.       for i in @teleport_list
  172.         teleport_menu << i[1]
  173.       end
  174.       @teleport_window = Window_Command.new(Graphics.width, teleport_menu, NICKE::TELEPORT::WINDOW[0])
  175.       @teleport_window.x = NICKE::TELEPORT::WINDOW[1]
  176.       @teleport_window.y = NICKE::TELEPORT::WINDOW[2]
  177.       @teleport_window.z = NICKE::TELEPORT::WINDOW[3]
  178.       @teleport_window.opacity = NICKE::TELEPORT::WINDOW[4]
  179.       @teleport_window.open
  180.     end
  181.   end
  182.  
  183.   def teleport_player(index)
  184.     # // Method for teleporting the player to the spawn event. (if exists)
  185.     $game_map.setup(@teleport_list[index][0])
  186.     $game_map.teleport_spawn
  187.     Graphics.fadeout(NICKE::TELEPORT::FADE_TIME)
  188.     $game_map.autoplay
  189.     $game_map.refresh
  190.     $game_player.animation_id = NICKE::TELEPORT::ANIM_ID unless NICKE::TELEPORT::ANIM_ID.nil?
  191.     $scene = Scene_Map.new
  192.   end
  193.  
  194.   def update
  195.     super
  196.     @message_window.update
  197.     unless @teleport_list.empty?
  198.       @teleport_window.update
  199.       if Input.trigger?(Input::B)
  200.         Sound.play_cancel
  201.         return_scene
  202.       elsif Input.trigger?(Input::C)
  203.         case @teleport_window.index
  204.         when 0...@teleport_list.size
  205.           Sound.play_decision
  206.           teleport_player(@teleport_window.index)
  207.         end
  208.       end
  209.     end
  210.   end
  211.  
  212.   def create_menu_background
  213.     @menuback_sprite = Sprite.new
  214.     if NICKE::TELEPORT::BACK.nil?
  215.       @menuback_sprite.bitmap = $game_temp.background_bitmap
  216.       @menuback_sprite.color.set(16, 16, 16, 128)
  217.     else
  218.       @menuback_sprite.bitmap = Cache.picture(NICKE::TELEPORT::BACK)
  219.     end
  220.     update_menu_background
  221.   end
  222.  
  223.   def dispose_menu_background
  224.     @menuback_sprite.dispose unless @menuback_sprite.nil?
  225.     @menuback_sprite = nil
  226.   end
  227.  
  228.  
  229.   def dispose_teleport
  230.     dispose_menu_background
  231.     unless @teleport_list.empty?
  232.       @teleport_window.dispose unless @teleport_window.nil?
  233.       @teleport_window = nil
  234.     end
  235.     @message_window.dispose unless @message_window.nil?
  236.     @message_window = nil
  237.   end
  238.  
  239.   alias nicke_teleport_terminate terminate unless $@
  240.   def terminate(*args,&block)
  241.     nicke_teleport_terminate(*args,&block)
  242.     dispose_teleport
  243.   end
  244.  
  245.   def perform_transition
  246.     if NICKE::TELEPORT::TRANSITION.nil?
  247.       Graphics.transition(30)
  248.     else
  249.       Graphics.transition(NICKE::TELEPORT::TRANSITION[0],NICKE::TELEPORT::TRANSITION[1],NICKE::TELEPORT::TRANSITION[2]) unless @teleport_list.empty?
  250.     end
  251.   end
  252.  
  253.   def return_scene
  254.     if NICKE::TELEPORT::RETURN_SCENE.nil?
  255.       $scene = Scene_Map.new
  256.     else
  257.       $scene = Scene_Menu.new(NICKE::TELEPORT::RETURN_SCENE)
  258.     end
  259.   end
  260.  
  261. end # END OF FILE
  262.  
  263. #=*==========================================================================*=#
  264. # ** END OF FILE
  265. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement