Loque

Salvare posizione evento

Jun 19th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.10 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: Copy into a new script slot in the Materials section
  15. #
  16. #--------------------------------------------------
  17. #
  18. # Use:
  19. #
  20. # To tell an event to move to its current position the next time
  21. # the map is loaded, execute the following in a script call:
  22. #   $game_map.events[event_id].save_pos()
  23. #
  24. # To tell an event to move to a particular position (not its
  25. # current position) the next time the map is loaded,
  26. # execute the following in a script call:
  27. #   $game_map.events[event_id].save_pos(1, 2, 8)
  28. # - the above will move the event to x=1, y=2, facing up
  29. #
  30. # To tell an event to forget its previously remembered position
  31. # and go back to its default position the next time time map
  32. # is loaded, execute the following in a script call:
  33. #   $game_map.events[event_id].forget_pos()
  34. #--------------------------------------------------
  35.  
  36. class Game_System
  37.   alias shaz_mem_position_gs_init initialize
  38.  
  39.   attr_accessor :event_positions
  40.  
  41.   def initialize
  42.     shaz_mem_position_gs_init
  43.     @event_positions = {}
  44.   end
  45. end
  46.  
  47. class Game_CharacterBase
  48.   attr_accessor
  49. end
  50.  
  51. class Game_Event
  52.   alias shaz_mem_position_gcb_init initialize
  53.  
  54.   def initialize(map_id, event)
  55.     shaz_mem_position_gcb_init(map_id, event)
  56.  
  57.     if $game_system.event_positions.has_key?([map_id, @id])
  58.       mvx, mvy, mvdir = $game_system.event_positions[[map_id, @id]]
  59.       moveto(mvx, mvy)
  60.       if mvdir != nil
  61.         set_direction(mvdir)
  62.       end
  63.       @stop_count = 0
  64.       refresh
  65.     end
  66.   end
  67.  
  68.   def save_pos(x = @x, y = @y, dir = @direction)
  69.     $game_system.event_positions[[@map_id, @id]] = [x, y, dir]
  70.   end
  71.  
  72.   def forget_pos
  73.     $game_system.event_positions.delete([@map_id, @id])
  74.   end
  75. end
Add Comment
Please, Sign In to add comment