SYDONAY

remember event pos

Nov 6th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.77 KB | None | 0 0
  1. #--------------------------------------------------
  2. # Remember Event Position 1.0
  3. #--------------------------------------------------
  4. #
  5. # Author: Shaz
  6. #
  7. # Description: This script lets you set the position and direction
  8. #              where an event will appear next time the map is
  9. #              loaded.  Events will appear in this new position
  10. #              rather than the place they were put during design.
  11. #
  12. #--------------------------------------------------
  13. #
  14. # Installation:
  15. #
  16. # Copy into a new script slot in the Materials section
  17. #
  18. #--------------------------------------------------
  19. #
  20. # Use:
  21. #
  22. # Examples below show syntax for an Event Command on an Event Tab.
  23. #   You can use @event_id for the current event, or specify an event number.
  24. # To execute from within a Set Move Route command, omit the
  25. #   $game_map.events[@event_id]. part, and just use save_pos() and forget_pos().
  26. #
  27. # To tell an event to move to its current position the next time
  28. # the map is loaded, execute the following in a script call:
  29. #   $game_map.events[@event_id].save_pos()
  30. #
  31. # To tell an event to move to a particular position (not its
  32. # current position) the next time the map is loaded,
  33. # execute the following in a script call:
  34. #   $game_map.events[@event_id].save_pos(1, 2, 8)
  35. # - the above will move the event to x=1, y=2, facing up
  36. #
  37. # To tell an event to forget its previously remembered position
  38. # and go back to its default position the next time time map
  39. # is loaded, execute the following in a script call:
  40. #   $game_map.events[@event_id].forget_pos()
  41. #--------------------------------------------------
  42.  
  43. class Game_System
  44.   alias shaz_mem_position_gs_init initialize
  45.  
  46.   attr_accessor :event_positions
  47.  
  48.   def initialize
  49.     shaz_mem_position_gs_init
  50.     @event_positions = {}
  51.   end
  52. end
  53.  
  54. # Check to ensure $game_system.event_positions exists (save files created
  55. # prior to this script being added would not have it initialized)
  56. class Game_Map
  57.   alias shaz_mem_positions_gm_init initialize
  58.  
  59.   def initialize
  60.     shaz_mem_positions_gm_init
  61.     $game_system.event_positions = {} if !$game_system.event_positions
  62.   end
  63. end
  64.  
  65. class Game_CharacterBase
  66.   attr_accessor
  67. end
  68.  
  69. class Game_Event
  70.   alias shaz_mem_position_gcb_init initialize
  71.  
  72.   def initialize(map_id, event)
  73.     shaz_mem_position_gcb_init(map_id, event)
  74.  
  75.     if $game_system.event_positions.has_key?([map_id, @id])
  76.       mvx, mvy, mvdir = $game_system.event_positions[[map_id, @id]]
  77.       moveto(mvx, mvy)
  78.       set_direction(mvdir) if mvdir
  79.       @stop_count = 0
  80.       refresh
  81.     end
  82.   end
  83.  
  84.   def save_pos(x = @x, y = @y, dir = @direction)
  85.     $game_system.event_positions[[@map_id, @id]] = [x, y, dir]
  86.   end
  87.  
  88.   def forget_pos
  89.     $game_system.event_positions.delete([@map_id, @id])
  90.   end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment