Advertisement
Fomar0153

Fomar0153 - Regions Map Loader

May 6th, 2012
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.32 KB | None | 0 0
  1. =begin
  2. Region Map Loader
  3. by Fomar0153
  4. Version 1.0
  5. ----------------------
  6. Notes
  7. ----------------------
  8. Allows you to load parts of another map by using regions and switches
  9. ----------------------
  10. Instructions
  11. ----------------------
  12. See blog post for instructions.
  13. ----------------------
  14. Known bugs
  15. ----------------------
  16. None
  17. =end
  18. class Game_Map
  19.   #--------------------------------------------------------------------------
  20.   # * Aliases Setup
  21.   #--------------------------------------------------------------------------
  22.   alias regionmapsetup setup
  23.   def setup(map_id)
  24.     regionmapsetup(map_id)
  25.     @regionmapdata = nil
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # * Aliases Refresh
  29.   #--------------------------------------------------------------------------
  30.   alias regionmaprefresh refresh
  31.   def refresh
  32.     regionmaprefresh
  33.     @regionmapdata = nil
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # * Rewrites tile_id
  37.   #--------------------------------------------------------------------------
  38.   def tile_id(x, y, z)
  39.     self.data[x, y, z] || 0
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # * Rewrites data
  43.   #--------------------------------------------------------------------------
  44.   def data
  45.     return @regionmapdata if @regionmapdata
  46.     data = @map.data.clone
  47.     if @map.note =~ /<regionmap (.*)>/i
  48.       regions = $1.split(";")
  49.       for region in regions
  50.         regiondata = region.split(",")
  51.         if $game_switches[regiondata[2].to_i]
  52.           tmpdata = load_data(sprintf("Data/Map%03d.rvdata2", regiondata[1].to_i)).data
  53.           for x in 0..@map.width
  54.             for y in 0..@map.height
  55.               if region_id(x,y) == regiondata[0].to_i
  56.                 data[x,y,0] = tmpdata[x,y,0]
  57.                 data[x,y,1] = tmpdata[x,y,1]
  58.                 data[x,y,2] = tmpdata[x,y,2]
  59.                 # Shadows and regions are stored in the same variable
  60.                 # If you can't bring yourself to copy regions then add
  61.                 # % 256 to the end of the next line
  62.                 data[x,y,3] = tmpdata[x,y,3]
  63.               end
  64.             end
  65.           end
  66.         end
  67.       end
  68.     end
  69.     @regionmapdata = data
  70.     return @regionmapdata
  71.   end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement