Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: whitespirits on April 10, 2018, 03:48:24 pm

Title: Image Map Maker issue
Post by: whitespirits on April 10, 2018, 03:48:24 pm
Hey guys, im in really bad need of getting this working and it almost does. It will save most maps as PNG but some throw me an error causing me loads of problems

https://rpgmaker.net/engines/rmxp/utilities/82/

example of error,

https://imgur.com/0xDPVcc
Title: Re: Image Map Maker issue
Post by: KK20 on April 10, 2018, 04:10:38 pm
Line in question is pointed out below

  def initialize(x, y, tile_id, z = 4)
    @tile_id = tile_id
    @opacity = 255
    @x = x
    @y = y
    @z = z # Used for tie-breaker in comparison
    @sx = x * 32
    @sy = y * 32
    @sz = (y + $game_map.priorities[@tile_id]) * 32 + 33   #<============================
    # If tile ID value is valid
    if @tile_id >= 48
      @bitmap = RPG::Cache.tile!($game_map.tileset_name,
                                 $game_map.autotile_names, @tile_id)
      @rect = Rect.new(0, 0, 32, 32)
    else
      @bitmap = Default_Bitmap
      @rect = @bitmap.rect
    end


Since you mention this happens on some maps, I take it you have some invalid tile IDs drawn somewhere on them (i.e. a tile ID that is larger than the total number of tiles the tileset has).
Title: Re: Image Map Maker issue
Post by: whitespirits on April 10, 2018, 04:59:45 pm
Thanks man, I dont understand how I can fix it, its on a map using a slightly modified tileset, does it mean something is out of line on the actual tileset?

https://imgur.com/a/jfJkR
Title: Re: Image Map Maker issue
Post by: KK20 on April 10, 2018, 05:14:56 pm
It's not the tileset itself that's the problem. Like, let's say for example (note, this is not how it actually is,  but just to make it easier to explain) your tileset graphic has 80 tiles on it. The top left tile is tile ID 0. Immediately right of it is tile ID 1, then 2, then 3...and the tile immediately below 0 is tile ID 7. Using that logic, the bottom right tile on the tileset will be tile ID 79.

So you make your map, using all the tiles your tileset has. Then, at some later point in time, you go "do I really need 80 tiles?" and change the tileset graphic to something smaller in size (let's say 40 tiles in total). While your map no longer draws the tile IDs 40-79 anymore, they still exist in the map data. This is what your error most likely is--your map is using a tile ID that the tileset graphic does not support.

You can put this script above Main

class Game_Map
  alias check_invalid_tiles setup
  def setup(map_id)
    check_invalid_tiles(map_id)
   
    bitmap = RPG::Cache.tileset(@tileset_name)
    maxtileid = (bitmap.width / 32) * (bitmap.height / 32) - 1
   
    for x in 0...@map.data.xsize
      for y in 0...@map.data.ysize
        for z in 0...@map.data.zsize
          if @map.data[x,y,z] - 384 > maxtileid
            p("[#{x},#{y},#{z}] = " + @map.data[x,y,z].to_s)
          end
        end
      end
    end
  end
 
end

and put your character in the problem map. If there are invalid tile IDs, a message window will pop up showing the [x, y, layer] coordinates.
Title: Re: Image Map Maker issue
Post by: whitespirits on April 10, 2018, 05:26:06 pm
Thanks again for the details, I understand in the most part but am still trying to work out how I would fix this? simply delete spots on the actual map or on the tileset?

Here is pic of the flagged IDs

https://imgur.com/a/kxGzY
Title: Re: Image Map Maker issue
Post by: KK20 on April 10, 2018, 05:44:02 pm
You'll need to manually go to those places on your map and draw over them with the blank tile ID at the top left of the tileset.

I would make a script that just scans all your maps and replaces invalid ones but currently at work.
Title: Re: Image Map Maker issue
Post by: whitespirits on April 10, 2018, 06:55:52 pm
If you could do that for me that would be amazing! Your awesome man thanks
Title: Re: Image Map Maker issue
Post by: KK20 on April 10, 2018, 10:57:49 pm
Give this a shot.

tilesets = load_data('Data/Tilesets.rxdata')
changed_maps = []

Dir['Data/Map*.rxdata'].each do |f|
  Graphics.update
  next unless f[/Map\d+/]
  map = load_data(f)
  tileset = RPG::Cache.tileset(tilesets[map.tileset_id].tileset_name)
  max_id = tileset.height / 32 * 8 + 383
  overwrite_file = false
 
  for z in 0..2
    for y in 0...map.data.ysize
      for x in 0...map.data.xsize
        if map.data[x,y,z] > max_id
          map.data[x,y,z] = 0
          overwrite_file = true
          changed_maps << f unless changed_maps.include?(f)
        end
      end
    end
    Graphics.update
  end
 
  if overwrite_file
    save_data(map, f)
  end
end

changed = "Changed the following maps:\n"
changed_maps.each do |map|
  changed << "#{map}\n"
end
print changed

exit

Paste above main, testplay your project. It'll spit out a message box and close afterwards. Reopen your project and it should be fixed. Didn't test it for large maps nor scanning more than 2 maps in a project.