Advertisement
Raizen

Event Map Memorizer

Mar 10th, 2015
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.51 KB | None | 0 0
  1. #==================================================================
  2. # Event Map Memorizer
  3. # Autor: Raizen
  4. # Comunidade : centrorpg.com
  5. # Compatibilidade: RMVXAce
  6. #==================================================================
  7.  
  8. # Description: The script allows that the event positions are saved,
  9. # In the teleport, events on the map will be in the same position they were
  10. # when they left that place.
  11.  
  12. # The script is configured automatically to save and load those positions
  13. # In the moment of the teleport.
  14.  
  15. # To save manually
  16. # Script Call: $game_map.save_event_positions
  17.  
  18. # To load manually
  19. # Script Call: $game_map.load_event_positions
  20.  
  21. # To clear the save positions of a certain map
  22. # where map_id is the id of the map.
  23. # Script Call: $game_map.clear_event_positions(map_id)
  24.  
  25. module Lune_event_pos
  26. # Switch that when it is on, it deactivates the
  27. # automatic save, use it for rooms with puzzles
  28. # for example.
  29. Switch = 1
  30. end
  31.  
  32.  
  33. #==================================================================
  34. #==================================================================
  35. #==================== Here starts the script ======================#
  36.  
  37. #=================================================================#
  38. #====================  Alias methods =============================#
  39. # reserve_transfer     => Game_Player
  40. # initialize           => Game_Map
  41. # perform_transfer     => Game_Player
  42. #=================================================================#
  43. #========================  New methods ===========================#
  44. # save_event_positions    => Game_Map
  45. # load_event_positions    => Game_Map
  46. # clear_event_positions   => Game_Map
  47. #=================================================================#
  48. #=================================================================#
  49.  
  50. #==============================================================================
  51. # ** Game_Map
  52. #------------------------------------------------------------------------------
  53. #  Esta classe gerencia o mapa. Inclui funções de rolagem e definição de
  54. # passagens. A instância desta classe é referenciada por $game_map.
  55. #==============================================================================
  56. class Game_Map
  57. alias :lune_memorize_initialize :initialize
  58.   #--------------------------------------------------------------------------
  59.   # * Inicialização das variáveis
  60.   #--------------------------------------------------------------------------
  61.   def initialize
  62.     lune_memorize_initialize
  63.     @memorize_pos = []
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # * Memorização das posições
  67.   #--------------------------------------------------------------------------
  68.   def save_event_positions
  69.     @memorize_pos[@map_id] = []
  70.     $game_map.events.values.select {|event| @memorize_pos[@map_id][event.id] = [event.x, event.y]}
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Carregamento das posições
  74.   #--------------------------------------------------------------------------
  75.   def load_event_positions
  76.     return if @memorize_pos[@map_id] == nil
  77.     $game_map.events.values.select {|event| event.moveto(@memorize_pos[@map_id][event.id][0], @memorize_pos[@map_id][event.id][1])}
  78.   end
  79.   def clear_event_positions(map_id)
  80.     @memorize_pos[map_id] == nil
  81.   end
  82. end
  83.  
  84.  
  85. #==============================================================================
  86. # ** Game_Player
  87. #------------------------------------------------------------------------------
  88. #  Esta classe gerencia o jogador.
  89. # A instância desta classe é referenciada por $game_player.
  90. #==============================================================================
  91. class Game_Player < Game_Character
  92. alias lune_perform_transfer perform_transfer
  93. alias lune_perform_reserve reserve_transfer
  94.   #--------------------------------------------------------------------------
  95.   # * Carregando as posições
  96.   #--------------------------------------------------------------------------
  97.   def perform_transfer
  98.     lune_perform_transfer
  99.     $game_map.load_event_positions unless $game_switches[Lune_event_pos::Switch]
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # * Salvando as posições
  103.   #--------------------------------------------------------------------------
  104.   def reserve_transfer(map_id, x, y, d = 2)
  105.     lune_perform_reserve(map_id, x, y, d = 2)
  106.     $game_map.save_event_positions unless $game_switches[Lune_event_pos::Switch]
  107.   end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement