CrowMakerVX

EventLocationSaver

Aug 18th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.58 KB | None | 0 0
  1. ###############################################################################
  2. #                   Event Location Saver
  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. #                       Give credit to Ixfuru
  28. ################################################################################
  29.  
  30. ################################################################################
  31. #  CLASS GAME EVENT
  32. ################################################################################
  33. class Game_Event < Game_Character
  34.  
  35.   #-----------------------------------------------------------------------------
  36.   # Move to Saved Location
  37.   #-----------------------------------------------------------------------------
  38.   def moveto_saved_location
  39.     loc = $game_map.evlocsaves[@map_id][@id]
  40.     moveto(loc[0], loc[1])
  41.   end
  42.  
  43. end
  44.  
  45. ################################################################################
  46. # CLASS GAME MAP
  47. ################################################################################
  48. class Game_Map
  49.  
  50.   attr_accessor :evlocsaves
  51.  
  52.   #-----------------------------------------------------------------------------
  53.   # Initialize (Aliased)
  54.   #-----------------------------------------------------------------------------
  55.   alias ixgmapinit initialize unless $@
  56.   def initialize
  57.     ixgmapinit
  58.     @evlocsaves = {}
  59.   end
  60.  
  61.   alias ixgmapsetup setup unless $@
  62.   def setup(map_id)
  63.     ixgmapsetup(map_id)
  64.     @events.each_key { |event|
  65.     if @evlocsaves.has_key?(map_id) && @evlocsaves[map_id].has_key?(event)
  66.       $game_map.events[event].moveto_saved_location
  67.     end
  68.     }
  69.   end
  70.  
  71.   #-----------------------------------------------------------------------------
  72.   # Save Ev Loc (Save Event Location)
  73.   # event_id: id of the event you wish to save
  74.   # x: map x corresponding to where you want the event to be
  75.   # y: map y corresponding to where you want the event to be
  76.   #------------------------------------------------------------------------------
  77.   def save_ev_loc(event_id, x, y)
  78.     @evlocsaves[@map_id] = Hash[event_id, [x,  y]]
  79.   end
  80.  
  81.   #-----------------------------------------------------------------------------
  82.   # Free Ev Loc
  83.   # called to free the event from its saved location
  84.   # event_id: the id of the event you wish to free
  85.   #-----------------------------------------------------------------------------
  86.   def free_ev_loc(event_id)
  87.     if @evlocsaves[@map_id].has_key?(event_id)
  88.       @evlocsaves[@map_id].delete(event_id)
  89.     end
  90.   end
  91.  
  92. end
Advertisement
Add Comment
Please, Sign In to add comment