Advertisement
ezmash

Region Common Events (VX Ace)

Aug 9th, 2016
1,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.09 KB | None | 0 0
  1. #============================================================================
  2. # REGION COMMON EVENTS
  3. # v1.0 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This script allows you to paint regions on your map, and set up common
  6. # events to be run when the player walks onto or faces a tile with that
  7. # region id.
  8. #----------------------------------------------------------------------------
  9. # To Install:
  10. # Copy and paste into a new script slot in Materials.  This script aliases
  11. # existing methods, so can go below all other custom scripts.
  12. #----------------------------------------------------------------------------
  13. # To Use:
  14. # Paint regions on the map over the tiles you want to trigger events
  15. # Create a common event that will do whatever you want to happen when the
  16. #  player walks on or bumps into a tile with that region
  17. # Add one of the following lines to the map's note box
  18. #
  19. # regevt: reg_id on common_event_id
  20. #         This will trigger the common event when the player steps on the tile
  21. #         eg: regevt: 63 on 15
  22. #             will call common event 15 when the player steps on a region 63 tile
  23. # regevt: reg_id face common_event_id
  24. #         This will trigger the common event when the player is facing, but not
  25. #         standing on the tile
  26. #         eg: regevt: 62 face 12
  27. #             will call common event 12 when the player is facing a region 62 tile
  28. #             (you might use this if you want something to happen when the player
  29. #             bumps into a wall - paint the bottom of the wall with region 62)
  30. #----------------------------------------------------------------------------
  31. # Terms:
  32. # Use in free or commercial games
  33. # Credit Shaz
  34. #============================================================================
  35.  
  36. class Game_Map
  37.   #--------------------------------------------------------------------------
  38.   # * Setup
  39.   #--------------------------------------------------------------------------
  40.   alias shaz_re_game_map_setup setup
  41.   def setup(map_id)
  42.     shaz_re_game_map_setup(map_id)
  43.     setup_region_events
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # * Setup Common Events for Regions
  47.   #--------------------------------------------------------------------------
  48.   def setup_region_events
  49.     @reg_evt = {}
  50.     @req = []
  51.     @map.note.split(/[\r\n+]/).each do |line|
  52.       case line
  53.       when /regevt:\s*(\d+)\s*(\w+)\s*(\d+)/i
  54.         reg = $1.to_i
  55.         mode = $2
  56.         ce = $3.to_i
  57.         if !@reg_evt.has_key?(reg)
  58.           @reg_evt[reg] = {}
  59.         end
  60.         @reg_evt[reg][mode] = ce
  61.       end
  62.     end
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * Check Region Events
  66.   #--------------------------------------------------------------------------
  67.   def check_region_event(x, y, dir)
  68.     reg = region_id(x, y)
  69.     next_reg = region_id(x_with_direction(x, dir), y_with_direction(y, dir))
  70.     if @reg_evt[reg] && @reg_evt[reg]["on"]
  71.       @req.push(@reg_evt[reg]["on"])
  72.     end
  73.     if @reg_evt[next_reg] && @reg_evt[next_reg]["face"]
  74.       @req.push(@reg_evt[next_reg]["face"])
  75.     end
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * Frame Update
  79.   #     main:  Interpreter update flag
  80.   #--------------------------------------------------------------------------
  81.   alias shaz_re_game_map_update update
  82.   def update(main = false)
  83.     shaz_re_game_map_update(main)
  84.     $game_temp.reserve_common_event(@req.shift) if
  85.       !$game_temp.common_event_reserved? && @req.size > 0
  86.   end
  87. end
  88.  
  89. class Game_Player < Game_Character
  90.   #--------------------------------------------------------------------------
  91.   # * Frame Update
  92.   #--------------------------------------------------------------------------
  93.   alias shaz_re_game_player_update update
  94.   def update
  95.     old_x = @x
  96.     old_y = @y
  97.     old_dir = @direction
  98.     shaz_re_game_player_update
  99.     $game_map.check_region_event(@x, @y, @direction) if
  100.       @x != old_x || @y != old_y || @direction != old_dir
  101.   end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement