CrowMakerVX

EventLocationSaver1.1

Aug 19th, 2013
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.26 KB | None | 0 0
  1. ################################################################################
  2. #                   Event Location Saver 1.1
  3. #                       By: Ixfuru
  4. #                      August 18, 2013
  5. ################################################################################
  6. #
  7. # This script saves the location of an event and holds this place even after
  8. # transfers to different maps.  To use the script, utilize the following
  9. # script calls:
  10. #  
  11. # To save the position of an event, use:
  12. #-------------------------------------------------------------------------------
  13. #  $game_map.save_ev_loc(event_id, x, y)
  14. #              
  15. #   event_id: the event you wish to lock into a position
  16. #   x: the x position where you want the event to stay
  17. #   y: the y position where you want the event to stay
  18. #-------------------------------------------------------------------------------
  19. #
  20. # To free a locked event, use:
  21. #-------------------------------------------------------------------------------
  22. # $game_map.free_ev_loc(event_id)
  23. #
  24. # event_id: the id of the event you wish to free from its saved position
  25. #-------------------------------------------------------------------------------
  26. #
  27. #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  28. #                         EXPANDED VERSION
  29. #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  30. # In the following hash, you can store map ids in an array.  If the hash has a
  31. # map_id, all it's events' locations will be saved.
  32. ################################################################################
  33.  
  34. module Ixfuru
  35.  
  36.   module EvLoc
  37.    
  38.     EVLOCMAPS = [2]
  39.  
  40. ################################################################################
  41. # Also, if you'd rather, you can set the below boolean to true in order to save
  42. # all the events from all the maps location.
  43. ################################################################################
  44.     EVLOCSAVEALL = false
  45.    
  46.     ################################################################################
  47.     # Finally, you can set the below switch to determine when to 'save all'.  If the
  48.     # switch is on, it will save ALL event locations.  If off, it will save only
  49.     # those you have stated.  If EVLOCSAVEALL is true, you can just leave the switch
  50.     # off.  This only takes effect if EVLOCSAVEALL is false.
  51.     ################################################################################
  52.     EVLOCSWITCH = 3 #switch_id used to save all
  53.    
  54.   end
  55.  
  56. end
  57.  
  58. ##*************************SCRIPT SUMMARY*************************************##
  59. # So to emphasize the way the script is set up:
  60. #
  61. # The EVLOCSAVEALL overrides everything, causing the locations of ALL events on
  62. # ALL maps to be saved.
  63. #
  64. # The EVLOCSWITCH overrides the EVLOCMAPS but NOT the EVLOCSAVEALL.
  65. #
  66. # The EVLOCMAPS overrides the individual calls of event location saves but NOT
  67. # the EVLOCSWICH.
  68. #
  69. # Save individual events by using the script call at the top of the script.  
  70. #*******************************************************************************
  71. # There are two other script calls you can make.  These involve the clearing of
  72. # saved locations.
  73. #
  74. # To clear ALL event location saves on ALL maps, use:
  75. #
  76. #                 $game_map.ev_loc_free_all
  77. #
  78. # To clear the event location saves on an individual map, use:
  79. #
  80. #                 $game_map[map_id].ev_loc_free_map
  81. #
  82. # Replace the map_id with the id of the map you wish to clear.
  83. #-------------------------------------------------------------------------------
  84.  
  85. # Don't edit anything beyond this point unless you know how to script!
  86. #
  87. ################################################################################
  88. ################################################################################
  89. ################################################################################
  90. #                       Give credit to Ixfuru
  91. ################################################################################
  92.  
  93. ################################################################################
  94. #  CLASS GAME EVENT
  95. ################################################################################
  96. class Game_Event < Game_Character
  97.  
  98.   #-----------------------------------------------------------------------------
  99.   # Move to Saved Location
  100.   #-----------------------------------------------------------------------------
  101.   def moveto_saved_location
  102.     return if $game_map.evlocsaves.empty? || !$game_map.evlocsaves.has_key?(@map_id) ||
  103.     !$game_map.evlocsaves[@map_id].has_key?(@id)
  104.     loc = $game_map.evlocsaves[@map_id][@id]
  105.     moveto(loc[0], loc[1])
  106.   end
  107.  
  108. end
  109.  
  110. ################################################################################
  111. # CLASS GAME MAP
  112. ################################################################################
  113. class Game_Map
  114.  
  115.   attr_accessor :evlocsaves
  116.  
  117.   #-----------------------------------------------------------------------------
  118.   # Initialize (Aliased)
  119.   #-----------------------------------------------------------------------------
  120.   alias ixgmapinit initialize unless $@
  121.   def initialize
  122.     ixgmapinit
  123.     @evlocsaves = {}
  124.   end
  125.  
  126.   #-----------------------------------------------------------------------------
  127.   # Setup (Aliased)
  128.   #-----------------------------------------------------------------------------
  129.   alias ixgmapsetup setup unless $@
  130.   def setup(map_id)
  131.     ixgmapsetup(map_id)
  132.     operate_evloc
  133.   end
  134.  
  135.   #-----------------------------------------------------------------------------
  136.   # Operate Evloc
  137.   # determines how event location saves should be handled and handles them
  138.   #-----------------------------------------------------------------------------
  139.   def operate_evloc
  140.     if Ixfuru::EvLoc::EVLOCSAVEALL || Ixfuru::EvLoc::EVLOCSWITCH ||
  141.       Ixfuru::EvLoc::EVLOCMAPS.has_key?($game_map.id)
  142.       @events.each_key { |event|
  143.       @events[event].moveto_saved_location
  144.       }
  145.     else
  146.       move_evloc_individual
  147.     end
  148.   end
  149.  
  150.   #-----------------------------------------------------------------------------
  151.   # Move Event Individual (sets event location on an individual basis)
  152.   #-----------------------------------------------------------------------------
  153.   def move_evloc_individual
  154.     @events.each_key { |event|
  155.     if @evlocsaves.has_key?(map_id) && @evlocsaves[map_id].has_key?(event)
  156.       @events[event].moveto_saved_location
  157.     end
  158.     }
  159.   end
  160.  
  161.   #-----------------------------------------------------------------------------
  162.   # Save Ev Loc (Save Event Location)
  163.   # event_id: id of the event you wish to save
  164.   # x: map x corresponding to where you want the event to be
  165.   # y: map y corresponding to where you want the event to be
  166.   #------------------------------------------------------------------------------
  167.   def save_ev_loc(event_id, x, y)
  168.     if @evlocsaves[@map_id] == nil
  169.       @evlocsaves[@map_id] = Hash[event_id, [x,  y]]
  170.     else
  171.       @evlocsaves[@map_id][event_id] = [x, y]
  172.     end
  173.   end
  174.  
  175.   #-----------------------------------------------------------------------------
  176.   # Free Ev Loc
  177.   # called to free the event from its saved location
  178.   # event_id: the id of the event you wish to free
  179.   #-----------------------------------------------------------------------------
  180.   def free_ev_loc(event_id)
  181.     if @evlocsaves[@map_id].has_key?(event_id)
  182.       @evlocsaves[@map_id].delete(event_id)
  183.     end
  184.   end
  185.  
  186.   #-----------------------------------------------------------------------------
  187.   # Ev Loc Free All
  188.   # erases all event location saves
  189.   #-----------------------------------------------------------------------------
  190.   def ev_loc_free_all
  191.     @evlocsaves.clear
  192.   end
  193.  
  194.   #-----------------------------------------------------------------------------
  195.   # Ev Loc Free Map
  196.   # frees all event saved locations for an individual map
  197.   #-----------------------------------------------------------------------------
  198.   def ev_loc_free_map
  199.     @evlocsaves.delete(@map_id)
  200.   end
  201.  
  202.   #-----------------------------------------------------------------------------
  203.   # Gather Saved Locations
  204.   # determines how saved locations should be handled when leaving map and
  205.   # handles them accordingly.
  206.   #-----------------------------------------------------------------------------
  207.   def gather_saved_locations
  208.     if Ixfuru::EvLoc::EVLOCSAVEALL || $game_switches[Ixfuru::EvLoc::EVLOCSWITCH] ||
  209.       Ixfuru::EvLoc::EVLOCMAPS.include?(@map_id)
  210.       @events.each_key { |event|
  211.       save_ev_loc(event, @events[event].x, @events[event].y)
  212.       }
  213.       p @evlocsaves
  214.     end
  215.   end
  216.  
  217. end
  218.  
  219. #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  220. #                              SCENE MAP
  221. #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  222. class Scene_Map < Scene_Base
  223.  
  224.   #--------------------------------------------------------------------------
  225.   # * Player Transfer  Processing (Aliased)
  226.   #--------------------------------------------------------------------------
  227.   alias ixscmapupdplytrnsfr update_transfer_player unless $@
  228.   def update_transfer_player
  229.     if $game_player.transfer?
  230.       $game_map.gather_saved_locations
  231.     end
  232.     ixscmapupdplytrnsfr
  233.   end
  234.  
  235. end
Advertisement
Add Comment
Please, Sign In to add comment