[RESOLVED] How do I make this script work with Blizz-ABS?

Started by Rymdpotatis, July 14, 2008, 07:45:23 am

Previous topic - Next topic

Rymdpotatis

July 14, 2008, 07:45:23 am Last Edit: July 25, 2008, 04:55:19 pm by Starrodkirby86
This is a script for a random dungeon generator, whenever I use it I get these two error messages from Blizz-ABS. Anyone know how to make them work together?

=begin

Random Map Script, by "tonbi", adapted by Peter O.

--------------------


Names of random maps have the following syntax:

[MapName],Random,[Type],[ObjCnt],[Connect]

MapName - Name of the map
Type - Map type:
0 - 2 layers, natural
1 - 2 layers, artificial
2 - 2 layers, natural, convex
3 - 2 layers, artificial, convex
4 - 2 layers, natural, hole/land/wall
5 - 2 layers, artificial, hole/land/wall
6 - 2 layers, natural, hole/land/wall
7 - 2 layers, artificial, hole/land/wall
ObjCnt - Density of objects on the map.  Generally a number divisible by 100.
Connect - If this is equal to "false", the parts of the generated map can be disjoint.
  This setting is optional.

------------------
In addition, the tiles used in the random map must be arranged in a certain way, depending
on the map type; please see the Random Map Sample for details:

http://www.mc.ccnw.ne.jp/sarada/toshi/down/RandomMapSample.exe

------------------

Events can be labeled with one of the following:


Each event on the map can be marked with these features.

Checkpoint - There will always be ground wherever this event is placed.
To Use:  Name the event "MyEvent,Checkpoint" or use a Comment event
command consisting of the text "Checkpoint". ("MyEvent" is arbitrary.)
Fixed - This event will appear at a ground tile next to where this event is located.
To Use:  Name the event "MyEvent,Fixed" or use a Comment event
command consisting of the text "Fixed". ("MyEvent" is arbitrary.)
TotallyFixed - This event will always remain at its position defined on the map.
To Use:  Name the event "MyEvent,TotallyFixed" or use a Comment event
command consisting of the text "TotallyFixed". ("MyEvent" is arbitrary.)
WallFixture - Appears attached to a wall.  May be followed by a comma and either
1 or 0 (0 means the object takes 1 tile space; 1 means 3 tiles).
To Use:  Use a Comment event command consisting of the text "WallFixture,1"
WallFixtureFixed - Appears attached to a wall next to where this event is located.
May be followed by a comma and either 1 or 0 (0 means the object takes 1 tile space;
1 means 3 tiles).
To Use:  Use a Comment event command consisting of the text "WallFixtureFixed,1"

Events without these features will be placed at a random spot on the generated map.

-------------------
=end

 
  USE_TRAIN_ACTOR = false
class Game_Character
 
  DRAWRANGEX = 1920     
  DRAWRANGEY = 1664     
end
class Game_Map
 
  AUTO_MAP_SAVE = true   
                         
                         
end

class Game_Temp
  alias initialize_tonbi1 initialize
  def initialize
    initialize_tonbi1
   
    $onscreen = []                       
  end
end

class Game_Character
  alias update_tonbi1 update
  def update
    sx = @real_x - $game_map.display_x - 1280
    sy = @real_y - $game_map.display_y - 960
    abs_sx = sx > 0 ? sx : -sx
    abs_sy = sy > 0 ? sy-3 : -sy
    if abs_sx > DRAWRANGEX or abs_sy > DRAWRANGEY
      $onscreen[@id]=false
    else
      $onscreen[@id]=true
    end
   
    update_tonbi1
  end
end

class Spriteset_Map
  attr_accessor :character_sprites
  def initialize
   
    $onscreen = []
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    @character_sprites = []
    @party_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites[i]=sprite
      $onscreen[i] = true
    end
    @party_sprites.push(Sprite_Character.new(@viewport1, $game_player))
   
    @weather = RPG::Weather.new(@viewport1)
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    @timer_sprite = Sprite_Timer.new
    update
  end
  def dispose
    @tilemap.tileset.dispose
    for i in 0..6
      @tilemap.autotiles[i].dispose
    end
    @tilemap.dispose
    @panorama.dispose
    @fog.dispose
    for i in @character_sprites
      if i != nil
        i.dispose
      end
    end
    for i in @party_sprites
      if i != nil
        i.dispose
      end
    end
    @weather.dispose
    for sprite in @picture_sprites
      sprite.dispose
    end
    @timer_sprite.dispose
    @viewport1.dispose
    @viewport2.dispose
    @viewport3.dispose
  end
  def update
    if @panorama_name != $game_map.panorama_name or
       @panorama_hue != $game_map.panorama_hue
      @panorama_name = $game_map.panorama_name
      @panorama_hue = $game_map.panorama_hue
      if @panorama.bitmap != nil
        @panorama.bitmap.dispose
        @panorama.bitmap = nil
      end
      if @panorama_name != ""
        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
      end
      Graphics.frame_reset
    end
    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
      @fog_name = $game_map.fog_name
      @fog_hue = $game_map.fog_hue
      if @fog.bitmap != nil
        @fog.bitmap.dispose
        @fog.bitmap = nil
      end
      if @fog_name != ""
        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
      end
      Graphics.frame_reset
    end
    @tilemap.ox = $game_map.display_x / 4
    @tilemap.oy = $game_map.display_y / 4
    @tilemap.update
    @panorama.ox = $game_map.display_x / 8
    @panorama.oy = $game_map.display_y / 8
    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone
    for i in $game_map.events.keys
      if $onscreen[i]
        @character_sprites[i].update
      end
    end
    for i in @party_sprites
      i.update
    end
 
    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update
    for sprite in @picture_sprites
      sprite.update
    end
    @timer_sprite.update
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    @viewport3.color = $game_screen.flash_color
    @viewport1.update
    @viewport3.update
  end
end

if USE_TRAIN_ACTOR == true
  module Train_Actor
    module Spriteset_Map_Module
      def setup_actor_character_sprites(characters)
        if !setup_actor_character_sprites?
          for character in characters.reverse
            @party_sprites.unshift(
              Sprite_Character.new(@viewport1, character)
            )
          end
          @setup_actor_character_sprites_flag = true
        end
      end
    end
  end
end
class Game_Map
  def setup(map_id)
    @map_id = map_id
    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
    tileset = $data_tilesets[@map.tileset_id]
    @tileset_name = tileset.tileset_name
    @autotile_names = tileset.autotile_names
    @panorama_name = tileset.panorama_name
    @panorama_hue = tileset.panorama_hue
    @fog_name = tileset.fog_name
    @fog_hue = tileset.fog_hue
    @fog_opacity = tileset.fog_opacity
    @fog_blend_type = tileset.fog_blend_type
    @fog_zoom = tileset.fog_zoom
    @fog_sx = tileset.fog_sx
    @fog_sy = tileset.fog_sy
    @battleback_name = tileset.battleback_name
    @passages = tileset.passages
    @priorities = tileset.priorities
    @terrain_tags = tileset.terrain_tags
    @display_x = 0
    @display_y = 0
   
    check_special_map
    @need_refresh = false
    @events = {}
    for i in @map.events.keys
      @events[i] = Game_Event.new(@map_id, @map.events[i])
    end
    @common_events = {}
    for i in 1...$data_common_events.size
      @common_events[i] = Game_CommonEvent.new(i)
    end
    @fog_ox = 0
    @fog_oy = 0
    @fog_tone = Tone.new(0, 0, 0, 0)
    @fog_tone_target = Tone.new(0, 0, 0, 0)
    @fog_tone_duration = 0
    @fog_opacity_duration = 0
    @fog_opacity_target = 0
    @scroll_direction = 2
    @scroll_rest = 0
    @scroll_speed = 4
  end
  def check_special_map
    mapinfo  = load_data("Data/MapInfos.rxdata")
    if mapinfo[@map_id].subname == "Random"
      if mapinfo[@map_id].subname(3)=="" or mapinfo[@map_id].subname(3) == nil
        p3 = 0
      else
        p3 = mapinfo[@map_id].subname(3).to_i
      end
      if mapinfo[@map_id].subname(4)=="false"
        p4 = false
      end
     
      make_random_map(2,mapinfo[@map_id].subname(2).to_i,p3,p4)
    end
  end
  def make_random_map(wall = 2, type = 0, objcnt = 0, connect = true)
    wall = 0 if wall == nil
    type = 0 if type == nil
    objcnt = 0 if objcnt == nil
    unless objcnt.is_a?(Numeric)
      objcnt = 0
    end
    if objcnt < 0
      objcnt = 0
    end
    connect = true if connect != false
    @heightdata = Table.new(@map.width,@map.height)
    @maskdata = Table.new(@map.width,@map.height)
    @oneventdata = Table.new(@map.width,@map.height)
    @masksetting = []
    @makedata = []
    @targettype=0
    @chgtype=0
   
    time = -1
    for i in 0...@map.width
      for j in 0...@map.height
        time += 1
        if time%2000 == 0
          Graphics.update
        end
        @heightdata[i,j] = 0
        @maskdata[i,j] = 0
      end
    end
    for i in 0...100
      @masksetting[i] = true
    end
    needposx = []
    needposy = []
    for i in @map.events.keys.sort
      time += 1
      if time%200 == 0
        Graphics.update
      end
      if event_settype(i) == 1
        if connect == true
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
        else
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
        end
      end
    end
    if connect == true
      needposx.shift
      needposy.shift
    end
    loop do
      if needposx.size <= 2
        needposx.push(rand(@map.width))
        needposy.push(rand(@map.height))
      else
        break
      end
    end
    case type
    when 0
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,0])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,1,1,1])
      @makedata.push([4,0,1,1,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,1])
    when 1
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-6,4,1,10])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,3,1])
      @makedata.push([4,1,2,2,1])
      @makedata.push([4,0,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,1])
    when 2
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,0])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,2,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,-1])
    when 3
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,1,10])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,2,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,-1])
    when 4
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,3,3,8,8])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-8,4,0,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
    when 5
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,3,3,8,8])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-8,4,1,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
     
     
    when 6
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,1,1,3,3])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([4,0,2,2,0])
      @makedata.push([4,0,1,2,1])
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-15,4,0,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
    when 7
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,1,1,3,3])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([4,0,2,2,0])
      @makedata.push([4,0,1,2,1])
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-15,4,1,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
    end
    for make_stat in @makedata
      time += 1
      if time%2 == 0
        Graphics.update
      end
      case make_stat[0]
      when 0   
        rndmap_chtarget(make_stat[1],make_stat[2])
      when 1   
        rndmap_setstat(make_stat[1],make_stat[2],make_stat[3],make_stat[4])
      when 2   
        rndmap_chmask(make_stat[1],make_stat[2])
      when 3   
        rndmap_mkroad(make_stat[1],make_stat[2],make_stat[3],make_stat[4],make_stat[5])
      when 4   
        rndmap_plus(make_stat[1],make_stat[2],make_stat[3],make_stat[4])
      when 5   
        rndmap_allchg(make_stat[1])
      when 6   
        rndmap_putpos(make_stat[1],make_stat[2],make_stat[3])
      when 7   
        rndmap_edge(make_stat[1])
      end
    end
    @tilesetting = Table.new(3,40,3)
    for i in [0,1,2]
      for k in 0...40
        for j in [0,1,2]
          @tilesetting[j,k,i] = @map.data[j,k,i]
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 1
          if @heightdata[j,k+1]==-1
            @heightdata[j,k+1] = 0
            if @heightdata[j,k+2]==-1 and
              @heightdata[j,k+3] == 0
              @heightdata[j,k+2] = 0
            end
          end
        end
       
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 0
          if @heightdata[j,k+1] == -1 or
            @heightdata[j,k-1] == -1 or
            @heightdata[j+1,k] == -1 or
            @heightdata[j-1,k] == -1
            set_mapdata2(j,k,0,8)
          else
            set_mapdata2(j,k,0,0)
          end
        elsif @heightdata[j,k] == 1
          if @heightdata[j,k+1] == -1 or
            @heightdata[j,k-1] == -1 or
            @heightdata[j+1,k] == -1 or
            @heightdata[j-1,k] == -1
            set_mapdata2(j,k,0,8)
          elsif @heightdata[j,k+1] == 0 or
            @heightdata[j,k-1] == 0 or
            @heightdata[j+1,k] == 0 or
            @heightdata[j-1,k] == 0
            set_mapdata2(j,k,0,0)
          else
            set_mapdata2(j,k,1,4)
          end
        else
          set_mapdata2(j,k,0,8)
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 0
          if @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == -1
              for i in [0,1,2]
                set_mapdata(j,k+i,0,13+i,1)
              end
            elsif @heightdata[j+1,k] == -1
              for i in [0,1,2]
                set_mapdata(j,k+i,2,13+i,1)
              end
            else
              for i in [0,1,2]
                set_mapdata(j,k+i,1,13+i,1)
              end
            end
          elsif @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == -1 or
            (@heightdata[j-1,k] == 1 and
            @heightdata[j-1,k-1] == -1)
              set_mapdata(j,k,0,11,2)
            elsif @heightdata[j+1,k] == -1 or
            (@heightdata[j+1,k] == 1 and
            @heightdata[j+1,k-1] == -1)
              set_mapdata(j,k,2,11,2)
            else
              set_mapdata(j,k,1,11,2)
            end
          elsif @heightdata[j-1,k] == -1 or
            (@heightdata[j-1,k] == 1 and
            @heightdata[j-1,k-1] == -1)
            set_mapdata(j,k,0,12,1)
          elsif @heightdata[j+1,k] == -1 or
            (@heightdata[j+1,k] == 1 and
            @heightdata[j+1,k-1] == -1)
            set_mapdata(j,k,2,12,1)
          elsif @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,9,1)
          elsif @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,10,1)
          elsif @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,9,1)
          elsif @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,10,1)
          end
        end
        if @heightdata[j,k] == 1 and
          @heightdata[j,k-1] != -1
         
          if @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == -1
              for i in [0,1,2]
              end
            elsif @heightdata[j+1,k] == -1
              for i in [0,1,2]
              end
            else
              for i in [0,1,2]
              end
            end
          elsif @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == -1
              set_mapdata(j,k,0,11,2)
            elsif @heightdata[j+1,k] == -1
              set_mapdata(j,k,2,11,2)
            else
              set_mapdata(j,k,1,11,2)
            end
          elsif @heightdata[j-1,k] == -1
            set_mapdata(j,k,0,12,1)
          elsif @heightdata[j+1,k] == -1
            set_mapdata(j,k,2,12,1)
          elsif @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,9,1)
          elsif @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,10,1)
          elsif @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,9,1)
          elsif @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,10,1)
          end
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 1
          if @heightdata[j,k+1] == 0 or
            @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
              set_mapdata(j,k+0,0,5+0,5)
              set_mapdata(j,k+1,0,5+1,5)
              set_mapdata(j,k+2,0,5+2,4)
              if @heightdata[j,k+3] != 0 and
                @heightdata[j,k+2] != 1 and
                (@heightdata[j,k+2] != 0 or @heightdata[j-1,k+2] != 0)
                set_mapdata(j,k+2,0,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,0,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
              set_mapdata(j,k+0,2,5+0,5)
              set_mapdata(j,k+1,2,5+1,5)
              set_mapdata(j,k+2,2,5+2,4)
              if @heightdata[j,k+3] != 0 and
                @heightdata[j,k+2] != 1 and
                (@heightdata[j,k+2] != 0 or @heightdata[j+1,k+2] != 0)
                set_mapdata(j,k+2,2,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,2,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            else
              set_mapdata(j,k+0,1,5+0,5)
              set_mapdata(j,k+1,1,5+1,5)
              set_mapdata(j,k+2,1,5+2,4)
              if @heightdata[j,k+3] != 0 and
                 @heightdata[j,k+2] != 1
                set_mapdata(j,k+2,1,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,1,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            end
          elsif @heightdata[j,k-1] == 0 or
              @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
              set_mapdata(j,k,0,3,4)
            elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
              set_mapdata(j,k,2,3,4)
            else
              set_mapdata(j,k,1,3,4)
            end
          elsif @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
            set_mapdata(j,k,0,4,4)
          elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
            set_mapdata(j,k,2,4,4)
          elsif @heightdata[j-1,k-1] == 0 or
              @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,1,4)
          elsif @heightdata[j-1,k+1] == 0 or
              @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,2,4)
          elsif @heightdata[j+1,k-1] == 0 or
              @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,1,4)
          elsif @heightdata[j+1,k+1] == 0 or
              @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,2,4)
          end
        end
      end
    end
    playerpos_reset($game_temp.player_new_x,$game_temp.player_new_y)
    @oneventdata[$game_temp.player_new_x,$game_temp.player_new_y] = 1
   
    time = 0
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      case event_settype(i)
      when 3
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      end
    end
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      case event_settype(i)
      when 1
        set_defeventpos(i,@map.events[i].x,@map.events[i].y)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      end
    end
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      j = event_settype(i)
      case j
      when 0 
        set_defeventpos(i,rand(@map.width-4)+2,rand(@map.width-4)+2)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      when 2 
        set_defeventpos(i,@map.events[i].x,@map.events[i].y)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      when 100..199 
        set_defeventpos_wall(i,rand(@map.width-4)+2,rand(@map.width-4)+2,j-100)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1
        for k in 1..(j-100)
          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1
        end
      when 200..299 
        set_defeventpos_wall(i,@map.events[i].x,@map.events[i].y,j-200)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1
        for k in 1..(j-200)
          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1
        end
      end
    end
    for i in 0...(rand(objcnt)+objcnt/2)
      time += 1
      if time%500 == 0
        Graphics.update
      end
      j = rand(@map.width)
      k = rand(@map.width)
      case rand(10)
      when 0..4
        if standable_newtile?(1,0)
          if standable?(j,k)
            set_mapdata(j,k,1,0,6)
          end
        else
          if standable2?(j,k)
            set_mapdata(j,k,1,0,6)
          end
        end
      when 5..7
        if standable_newtile?(2,0)
          if standable?(j,k)
            set_mapdata(j,k,2,0,6)
          end
        else
          if standable2?(j,k)
            set_mapdata(j,k,2,0,6)
          end
        end
      when 8..9
        if standable2?(j,k)
          if @map.data[j,k-1,2]==0 and
            (@map.data[j,k,1]==0 or @map.data[j,k,2]==0)
            set_mapdata(j,k,2,2,4)   
            set_mapdata(j,k-1,2,1,4) 
          end
        end
      end
    end
    @heightdata.resize(0,0)
    @maskdata.resize(0,0)
    @oneventdata.resize(0,0)
    @masksetting.clear
    @makedata.clear
    @tilesetting.resize(0,0,0)
   
    if AUTO_MAP_SAVE
      save_data(@map,sprintf("Data/Map%03d.rxdata", 999))
      maplist  = load_data("Data/MapInfos.rxdata")
     
      mapinfo = RPG::MapInfo.new
      mapinfo.name = sprintf("Auto-saved random map (%s)", maplist[@map_id].name)
      mapinfo.parent_id = 0
      mapinfo.order = 999
      mapinfo.expanded = true
      mapinfo.scroll_x = 0
      mapinfo.scroll_y = 0
     
      maplist[999]=mapinfo
      save_data(maplist,"Data/MapInfos.rxdata")
    end
  end
  def event_settype(i)
    if @map.events[i].subname == "Checkpoint"
      return 1
    end
    if @map.events[i].subname == "Fixed"
      return 2
    end
    if @map.events[i].subname == "TotallyFixed"
      return 3
    end
    for j in 0..1000
      if @map.events[i].pages[0].list[j].code != 108
        break
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Checkpoint"
        return 1
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "TotallyFixed"
        return 3
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Fixed"
        return 2
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "WallFixture"
        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil
          return 100
        else
          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]
          k = k.to_i
          return 100+k
        end
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "WallFixtureFixed"
        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil
          return 200
        else
          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]
          k = k.to_i
          return 200+k
        end
      end
    end
    return 0
  end
  def set_defeventpos(id,x,y)
    if standable2?(x,y)
      @map.events[id].x=x
      @map.events[id].y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable2?(x,y+i)
        @map.events[id].x=x
        @map.events[id].y=y+i
        return
      end
      for j in 1..i
        if standable2?(x-j,y+i)
          @map.events[id].x=x-j
          @map.events[id].y=y+i
          return
        end
        if standable2?(x+j,y+i)
          @map.events[id].x=x+j
          @map.events[id].y=y+i
          return
        end
        if standable2?(x-j,y-i)
          @map.events[id].x=x-j
          @map.events[id].y=y-i
          return
        end
        if standable2?(x+j,y-i)
          @map.events[id].x=x+j
          @map.events[id].y=y-i
          return
        end
      end
    end
  end
  def set_defeventpos_wall(id,x,y,p4)
    if standable3?(x,y,p4)
      @map.events[id].x=x
      @map.events[id].y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable3?(x,y+i,p4)
        @map.events[id].x=x
        @map.events[id].y=y+i
        return
      end
      for j in 1..i
        if standable3?(x-j,y+i,p4)
          @map.events[id].x=x-j
          @map.events[id].y=y+i
          return
        end
        if standable3?(x+j,y+i,p4)
          @map.events[id].x=x+j
          @map.events[id].y=y+i
          return
        end
        if standable3?(x-j,y-i,p4)
          @map.events[id].x=x-j
          @map.events[id].y=y-i
          return
        end
        if standable3?(x+j,y-i,p4)
          @map.events[id].x=x+j
          @map.events[id].y=y-i
          return
        end
      end
    end
  end
  def playerpos_reset(x,y)
    if standable?(x,y)
      $game_temp.player_new_x=x
      $game_temp.player_new_y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable?(x,y+i)
        $game_temp.player_new_x=x
        $game_temp.player_new_y=y+i
        return
      end
      for j in 0..i
        if standable?(x-j,y+i)
          $game_temp.player_new_x=x-j
          $game_temp.player_new_y=y+i
          return
        end
        if standable?(x+j,y+i)
          $game_temp.player_new_x=x+j
          $game_temp.player_new_y=y+i
          return
        end
        if standable?(x-j,y-i)
          $game_temp.player_new_x=x-j
          $game_temp.player_new_y=y-i
          return
        end
        if standable?(x+j,y-i)
          $game_temp.player_new_x=x+j
          $game_temp.player_new_y=y-i
          return
        end
      end
    end
  end
  def standable_newtile?(p1,p2)
    for i in [2, 1, 0]
      tile_id = @tilesetting[p1, p2, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
  def standable?(p1,p2)
    if @heightdata[p1,p2] != 0
      return false
    end
    if @oneventdata[p1,p2] ==1
      return false
    end
    for i in [2, 1, 0]
      tile_id = @map.data[p1, p2, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
  def standable2?(p1,p2)
    unless standable?(p1,p2)
      return false
    end
    if standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2) == false or
      standable?(p1+1,p2+1) == false
      if standable?(p1-1,p2-1) == false or
        standable?(p1-1,p2) == false or
        standable?(p1-1,p2+1) == false
        if standable?(p1,p2-1) == true and
          standable?(p1,p2+1) == true
          return false
        end
      end
    end
    if standable?(p1+1,p2+1) == false or
      standable?(p1,p2+1) == false or
      standable?(p1-1,p2+1) == false
      if standable?(p1+1,p2-1) == false or
        standable?(p1,p2-1) == false or
        standable?(p1-1,p2-1) == false
        if standable?(p1-1,p2) == true and
          standable?(p1+1,p2) == true
          return false
        end
      end
    end
    if standable?(p1,p2-1) == false and
      (standable?(p1-1,p2+1) == false or
      standable?(p1,p2+1) == false or
      standable?(p1+1,p2+1) == false)
      return false
    end
    if standable?(p1,p2+1) == false and
      (standable?(p1-1,p2-1) == false or
      standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2-1) == false)
      return false
    end
    if standable?(p1-1,p2) == false and
      (standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2) == false or
      standable?(p1+1,p2+1) == false)
      return false
    end
    if standable?(p1+1,p2) == false and
      (standable?(p1-1,p2-1) == false or
      standable?(p1-1,p2) == false or
      standable?(p1-1,p2+1) == false)
      return false
    end
     
    return true
  end
  def standable3?(p1,p2,p3)
    unless standable?(p1,p2+1)
      return false
    end
    if @oneventdata[p1,p2] == 1 or
      @oneventdata[p1,p2-1] == 1 or
   

Blizzard

I increased the allowed number of characters for posts to 100000. Your script wasn't posted correctly, please repost it. And use code tags. And post the error messages you are getting. -_-
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

July 14, 2008, 09:17:31 am #2 Last Edit: July 14, 2008, 09:20:19 am by Blizzard
Truly sorry, I forgot about code tags, it will not happen again!

=begin

Random Map Script, by "tonbi", adapted by Peter O.

--------------------


Names of random maps have the following syntax:

[MapName],Random,[Type],[ObjCnt],[Connect]

MapName - Name of the map
Type - Map type:
0 - 2 layers, natural
1 - 2 layers, artificial
2 - 2 layers, natural, convex
3 - 2 layers, artificial, convex
4 - 2 layers, natural, hole/land/wall
5 - 2 layers, artificial, hole/land/wall
6 - 2 layers, natural, hole/land/wall
7 - 2 layers, artificial, hole/land/wall
ObjCnt - Density of objects on the map.  Generally a number divisible by 100.
Connect - If this is equal to "false", the parts of the generated map can be disjoint.
  This setting is optional.

------------------
In addition, the tiles used in the random map must be arranged in a certain way, depending
on the map type; please see the Random Map Sample for details:

http://www.mc.ccnw.ne.jp/sarada/toshi/down/RandomMapSample.exe

------------------

Events can be labeled with one of the following:


Each event on the map can be marked with these features.

Checkpoint - There will always be ground wherever this event is placed.
To Use:  Name the event "MyEvent,Checkpoint" or use a Comment event
command consisting of the text "Checkpoint". ("MyEvent" is arbitrary.)
Fixed - This event will appear at a ground tile next to where this event is located.
To Use:  Name the event "MyEvent,Fixed" or use a Comment event
command consisting of the text "Fixed". ("MyEvent" is arbitrary.)
TotallyFixed - This event will always remain at its position defined on the map.
To Use:  Name the event "MyEvent,TotallyFixed" or use a Comment event
command consisting of the text "TotallyFixed". ("MyEvent" is arbitrary.)
WallFixture - Appears attached to a wall.  May be followed by a comma and either
1 or 0 (0 means the object takes 1 tile space; 1 means 3 tiles).
To Use:  Use a Comment event command consisting of the text "WallFixture,1"
WallFixtureFixed - Appears attached to a wall next to where this event is located.
May be followed by a comma and either 1 or 0 (0 means the object takes 1 tile space;
1 means 3 tiles).
To Use:  Use a Comment event command consisting of the text "WallFixtureFixed,1"

Events without these features will be placed at a random spot on the generated map.

-------------------
=end

 
  USE_TRAIN_ACTOR = false
class Game_Character
 
  DRAWRANGEX = 1920     
  DRAWRANGEY = 1664     
end
class Game_Map
 
  AUTO_MAP_SAVE = true   
                         
                         
end

class Game_Temp
  alias initialize_tonbi1 initialize
  def initialize
    initialize_tonbi1
   
    $onscreen = []                       
  end
end

class Game_Character
  alias update_tonbi1 update
  def update
    sx = @real_x - $game_map.display_x - 1280
    sy = @real_y - $game_map.display_y - 960
    abs_sx = sx > 0 ? sx : -sx
    abs_sy = sy > 0 ? sy-3 : -sy
    if abs_sx > DRAWRANGEX or abs_sy > DRAWRANGEY
      $onscreen[@id]=false
    else
      $onscreen[@id]=true
    end
   
    update_tonbi1
  end
end

class Spriteset_Map
  attr_accessor :character_sprites
  def initialize
   
    $onscreen = []
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    @character_sprites = []
    @party_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites[i]=sprite
      $onscreen[i] = true
    end
    @party_sprites.push(Sprite_Character.new(@viewport1, $game_player))
   
    @weather = RPG::Weather.new(@viewport1)
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    @timer_sprite = Sprite_Timer.new
    update
  end
  def dispose
    @tilemap.tileset.dispose
    for i in 0..6
      @tilemap.autotiles[i].dispose
    end
    @tilemap.dispose
    @panorama.dispose
    @fog.dispose
    for i in @character_sprites
      if i != nil
        i.dispose
      end
    end
    for i in @party_sprites
      if i != nil
        i.dispose
      end
    end
    @weather.dispose
    for sprite in @picture_sprites
      sprite.dispose
    end
    @timer_sprite.dispose
    @viewport1.dispose
    @viewport2.dispose
    @viewport3.dispose
  end
  def update
    if @panorama_name != $game_map.panorama_name or
       @panorama_hue != $game_map.panorama_hue
      @panorama_name = $game_map.panorama_name
      @panorama_hue = $game_map.panorama_hue
      if @panorama.bitmap != nil
        @panorama.bitmap.dispose
        @panorama.bitmap = nil
      end
      if @panorama_name != ""
        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
      end
      Graphics.frame_reset
    end
    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
      @fog_name = $game_map.fog_name
      @fog_hue = $game_map.fog_hue
      if @fog.bitmap != nil
        @fog.bitmap.dispose
        @fog.bitmap = nil
      end
      if @fog_name != ""
        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
      end
      Graphics.frame_reset
    end
    @tilemap.ox = $game_map.display_x / 4
    @tilemap.oy = $game_map.display_y / 4
    @tilemap.update
    @panorama.ox = $game_map.display_x / 8
    @panorama.oy = $game_map.display_y / 8
    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone
    for i in $game_map.events.keys
      if $onscreen[i]
        @character_sprites[i].update
      end
    end
    for i in @party_sprites
      i.update
    end
 
    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update
    for sprite in @picture_sprites
      sprite.update
    end
    @timer_sprite.update
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    @viewport3.color = $game_screen.flash_color
    @viewport1.update
    @viewport3.update
  end
end

if USE_TRAIN_ACTOR == true
  module Train_Actor
    module Spriteset_Map_Module
      def setup_actor_character_sprites(characters)
        if !setup_actor_character_sprites?
          for character in characters.reverse
            @party_sprites.unshift(
              Sprite_Character.new(@viewport1, character)
            )
          end
          @setup_actor_character_sprites_flag = true
        end
      end
    end
  end
end
class Game_Map
  def setup(map_id)
    @map_id = map_id
    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
    tileset = $data_tilesets[@map.tileset_id]
    @tileset_name = tileset.tileset_name
    @autotile_names = tileset.autotile_names
    @panorama_name = tileset.panorama_name
    @panorama_hue = tileset.panorama_hue
    @fog_name = tileset.fog_name
    @fog_hue = tileset.fog_hue
    @fog_opacity = tileset.fog_opacity
    @fog_blend_type = tileset.fog_blend_type
    @fog_zoom = tileset.fog_zoom
    @fog_sx = tileset.fog_sx
    @fog_sy = tileset.fog_sy
    @battleback_name = tileset.battleback_name
    @passages = tileset.passages
    @priorities = tileset.priorities
    @terrain_tags = tileset.terrain_tags
    @display_x = 0
    @display_y = 0
   
    check_special_map
    @need_refresh = false
    @events = {}
    for i in @map.events.keys
      @events[i] = Game_Event.new(@map_id, @map.events[i])
    end
    @common_events = {}
    for i in 1...$data_common_events.size
      @common_events[i] = Game_CommonEvent.new(i)
    end
    @fog_ox = 0
    @fog_oy = 0
    @fog_tone = Tone.new(0, 0, 0, 0)
    @fog_tone_target = Tone.new(0, 0, 0, 0)
    @fog_tone_duration = 0
    @fog_opacity_duration = 0
    @fog_opacity_target = 0
    @scroll_direction = 2
    @scroll_rest = 0
    @scroll_speed = 4
  end
  def check_special_map
    mapinfo  = load_data("Data/MapInfos.rxdata")
    if mapinfo[@map_id].subname == "Random"
      if mapinfo[@map_id].subname(3)=="" or mapinfo[@map_id].subname(3) == nil
        p3 = 0
      else
        p3 = mapinfo[@map_id].subname(3).to_i
      end
      if mapinfo[@map_id].subname(4)=="false"
        p4 = false
      end
     
      make_random_map(2,mapinfo[@map_id].subname(2).to_i,p3,p4)
    end
  end
  def make_random_map(wall = 2, type = 0, objcnt = 0, connect = true)
    wall = 0 if wall == nil
    type = 0 if type == nil
    objcnt = 0 if objcnt == nil
    unless objcnt.is_a?(Numeric)
      objcnt = 0
    end
    if objcnt < 0
      objcnt = 0
    end
    connect = true if connect != false
    @heightdata = Table.new(@map.width,@map.height)
    @maskdata = Table.new(@map.width,@map.height)
    @oneventdata = Table.new(@map.width,@map.height)
    @masksetting = []
    @makedata = []
    @targettype=0
    @chgtype=0
   
    time = -1
    for i in 0...@map.width
      for j in 0...@map.height
        time += 1
        if time%2000 == 0
          Graphics.update
        end
        @heightdata[i,j] = 0
        @maskdata[i,j] = 0
      end
    end
    for i in 0...100
      @masksetting[i] = true
    end
    needposx = []
    needposy = []
    for i in @map.events.keys.sort
      time += 1
      if time%200 == 0
        Graphics.update
      end
      if event_settype(i) == 1
        if connect == true
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
        else
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
        end
      end
    end
    if connect == true
      needposx.shift
      needposy.shift
    end
    loop do
      if needposx.size <= 2
        needposx.push(rand(@map.width))
        needposy.push(rand(@map.height))
      else
        break
      end
    end
    case type
    when 0
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,0])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,1,1,1])
      @makedata.push([4,0,1,1,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,1])
    when 1
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-6,4,1,10])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,3,1])
      @makedata.push([4,1,2,2,1])
      @makedata.push([4,0,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,1])
    when 2
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,0])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,2,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,-1])
    when 3
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,1,10])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,2,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,-1])
    when 4
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,3,3,8,8])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-8,4,0,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
    when 5
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,3,3,8,8])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-8,4,1,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
     
     
    when 6
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,1,1,3,3])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([4,0,2,2,0])
      @makedata.push([4,0,1,2,1])
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-15,4,0,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
    when 7
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,1,1,3,3])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([4,0,2,2,0])
      @makedata.push([4,0,1,2,1])
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-15,4,1,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
    end
    for make_stat in @makedata
      time += 1
      if time%2 == 0
        Graphics.update
      end
      case make_stat[0]
      when 0   
        rndmap_chtarget(make_stat[1],make_stat[2])
      when 1   
        rndmap_setstat(make_stat[1],make_stat[2],make_stat[3],make_stat[4])
      when 2   
        rndmap_chmask(make_stat[1],make_stat[2])
      when 3   
        rndmap_mkroad(make_stat[1],make_stat[2],make_stat[3],make_stat[4],make_stat[5])
      when 4   
        rndmap_plus(make_stat[1],make_stat[2],make_stat[3],make_stat[4])
      when 5   
        rndmap_allchg(make_stat[1])
      when 6   
        rndmap_putpos(make_stat[1],make_stat[2],make_stat[3])
      when 7   
        rndmap_edge(make_stat[1])
      end
    end
    @tilesetting = Table.new(3,40,3)
    for i in [0,1,2]
      for k in 0...40
        for j in [0,1,2]
          @tilesetting[j,k,i] = @map.data[j,k,i]
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 1
          if @heightdata[j,k+1]==-1
            @heightdata[j,k+1] = 0
            if @heightdata[j,k+2]==-1 and
              @heightdata[j,k+3] == 0
              @heightdata[j,k+2] = 0
            end
          end
        end
       
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 0
          if @heightdata[j,k+1] == -1 or
            @heightdata[j,k-1] == -1 or
            @heightdata[j+1,k] == -1 or
            @heightdata[j-1,k] == -1
            set_mapdata2(j,k,0,8)
          else
            set_mapdata2(j,k,0,0)
          end
        elsif @heightdata[j,k] == 1
          if @heightdata[j,k+1] == -1 or
            @heightdata[j,k-1] == -1 or
            @heightdata[j+1,k] == -1 or
            @heightdata[j-1,k] == -1
            set_mapdata2(j,k,0,8)
          elsif @heightdata[j,k+1] == 0 or
            @heightdata[j,k-1] == 0 or
            @heightdata[j+1,k] == 0 or
            @heightdata[j-1,k] == 0
            set_mapdata2(j,k,0,0)
          else
            set_mapdata2(j,k,1,4)
          end
        else
          set_mapdata2(j,k,0,8)
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 0
          if @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == -1
              for i in [0,1,2]
                set_mapdata(j,k+i,0,13+i,1)
              end
            elsif @heightdata[j+1,k] == -1
              for i in [0,1,2]
                set_mapdata(j,k+i,2,13+i,1)
              end
            else
              for i in [0,1,2]
                set_mapdata(j,k+i,1,13+i,1)
              end
            end
          elsif @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == -1 or
            (@heightdata[j-1,k] == 1 and
            @heightdata[j-1,k-1] == -1)
              set_mapdata(j,k,0,11,2)
            elsif @heightdata[j+1,k] == -1 or
            (@heightdata[j+1,k] == 1 and
            @heightdata[j+1,k-1] == -1)
              set_mapdata(j,k,2,11,2)
            else
              set_mapdata(j,k,1,11,2)
            end
          elsif @heightdata[j-1,k] == -1 or
            (@heightdata[j-1,k] == 1 and
            @heightdata[j-1,k-1] == -1)
            set_mapdata(j,k,0,12,1)
          elsif @heightdata[j+1,k] == -1 or
            (@heightdata[j+1,k] == 1 and
            @heightdata[j+1,k-1] == -1)
            set_mapdata(j,k,2,12,1)
          elsif @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,9,1)
          elsif @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,10,1)
          elsif @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,9,1)
          elsif @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,10,1)
          end
        end
        if @heightdata[j,k] == 1 and
          @heightdata[j,k-1] != -1
         
          if @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == -1
              for i in [0,1,2]
              end
            elsif @heightdata[j+1,k] == -1
              for i in [0,1,2]
              end
            else
              for i in [0,1,2]
              end
            end
          elsif @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == -1
              set_mapdata(j,k,0,11,2)
            elsif @heightdata[j+1,k] == -1
              set_mapdata(j,k,2,11,2)
            else
              set_mapdata(j,k,1,11,2)
            end
          elsif @heightdata[j-1,k] == -1
            set_mapdata(j,k,0,12,1)
          elsif @heightdata[j+1,k] == -1
            set_mapdata(j,k,2,12,1)
          elsif @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,9,1)
          elsif @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,10,1)
          elsif @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,9,1)
          elsif @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,10,1)
          end
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 1
          if @heightdata[j,k+1] == 0 or
            @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
              set_mapdata(j,k+0,0,5+0,5)
              set_mapdata(j,k+1,0,5+1,5)
              set_mapdata(j,k+2,0,5+2,4)
              if @heightdata[j,k+3] != 0 and
                @heightdata[j,k+2] != 1 and
                (@heightdata[j,k+2] != 0 or @heightdata[j-1,k+2] != 0)
                set_mapdata(j,k+2,0,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,0,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
              set_mapdata(j,k+0,2,5+0,5)
              set_mapdata(j,k+1,2,5+1,5)
              set_mapdata(j,k+2,2,5+2,4)
              if @heightdata[j,k+3] != 0 and
                @heightdata[j,k+2] != 1 and
                (@heightdata[j,k+2] != 0 or @heightdata[j+1,k+2] != 0)
                set_mapdata(j,k+2,2,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,2,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            else
              set_mapdata(j,k+0,1,5+0,5)
              set_mapdata(j,k+1,1,5+1,5)
              set_mapdata(j,k+2,1,5+2,4)
              if @heightdata[j,k+3] != 0 and
                 @heightdata[j,k+2] != 1
                set_mapdata(j,k+2,1,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,1,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            end
          elsif @heightdata[j,k-1] == 0 or
              @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
              set_mapdata(j,k,0,3,4)
            elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
              set_mapdata(j,k,2,3,4)
            else
              set_mapdata(j,k,1,3,4)
            end
          elsif @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
            set_mapdata(j,k,0,4,4)
          elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
            set_mapdata(j,k,2,4,4)
          elsif @heightdata[j-1,k-1] == 0 or
              @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,1,4)
          elsif @heightdata[j-1,k+1] == 0 or
              @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,2,4)
          elsif @heightdata[j+1,k-1] == 0 or
              @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,1,4)
          elsif @heightdata[j+1,k+1] == 0 or
              @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,2,4)
          end
        end
      end
    end
    playerpos_reset($game_temp.player_new_x,$game_temp.player_new_y)
    @oneventdata[$game_temp.player_new_x,$game_temp.player_new_y] = 1
   
    time = 0
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      case event_settype(i)
      when 3
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      end
    end
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      case event_settype(i)
      when 1
        set_defeventpos(i,@map.events[i].x,@map.events[i].y)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      end
    end
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      j = event_settype(i)
      case j
      when 0 
        set_defeventpos(i,rand(@map.width-4)+2,rand(@map.width-4)+2)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      when 2 
        set_defeventpos(i,@map.events[i].x,@map.events[i].y)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      when 100..199 
        set_defeventpos_wall(i,rand(@map.width-4)+2,rand(@map.width-4)+2,j-100)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1
        for k in 1..(j-100)
          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1
        end
      when 200..299 
        set_defeventpos_wall(i,@map.events[i].x,@map.events[i].y,j-200)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1
        for k in 1..(j-200)
          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1
        end
      end
    end
    for i in 0...(rand(objcnt)+objcnt/2)
      time += 1
      if time%500 == 0
        Graphics.update
      end
      j = rand(@map.width)
      k = rand(@map.width)
      case rand(10)
      when 0..4
        if standable_newtile?(1,0)
          if standable?(j,k)
            set_mapdata(j,k,1,0,6)
          end
        else
          if standable2?(j,k)
            set_mapdata(j,k,1,0,6)
          end
        end
      when 5..7
        if standable_newtile?(2,0)
          if standable?(j,k)
            set_mapdata(j,k,2,0,6)
          end
        else
          if standable2?(j,k)
            set_mapdata(j,k,2,0,6)
          end
        end
      when 8..9
        if standable2?(j,k)
          if @map.data[j,k-1,2]==0 and
            (@map.data[j,k,1]==0 or @map.data[j,k,2]==0)
            set_mapdata(j,k,2,2,4)   
            set_mapdata(j,k-1,2,1,4) 
          end
        end
      end
    end
    @heightdata.resize(0,0)
    @maskdata.resize(0,0)
    @oneventdata.resize(0,0)
    @masksetting.clear
    @makedata.clear
    @tilesetting.resize(0,0,0)
   
    if AUTO_MAP_SAVE
      save_data(@map,sprintf("Data/Map%03d.rxdata", 999))
      maplist  = load_data("Data/MapInfos.rxdata")
     
      mapinfo = RPG::MapInfo.new
      mapinfo.name = sprintf("Auto-saved random map (%s)", maplist[@map_id].name)
      mapinfo.parent_id = 0
      mapinfo.order = 999
      mapinfo.expanded = true
      mapinfo.scroll_x = 0
      mapinfo.scroll_y = 0
     
      maplist[999]=mapinfo
      save_data(maplist,"Data/MapInfos.rxdata")
    end
  end
  def event_settype(i)
    if @map.events[i].subname == "Checkpoint"
      return 1
    end
    if @map.events[i].subname == "Fixed"
      return 2
    end
    if @map.events[i].subname == "TotallyFixed"
      return 3
    end
    for j in 0..1000
      if @map.events[i].pages[0].list[j].code != 108
        break
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Checkpoint"
        return 1
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "TotallyFixed"
        return 3
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Fixed"
        return 2
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "WallFixture"
        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil
          return 100
        else
          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]
          k = k.to_i
          return 100+k
        end
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "WallFixtureFixed"
        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil
          return 200
        else
          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]
          k = k.to_i
          return 200+k
        end
      end
    end
    return 0
  end
  def set_defeventpos(id,x,y)
    if standable2?(x,y)
      @map.events[id].x=x
      @map.events[id].y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable2?(x,y+i)
        @map.events[id].x=x
        @map.events[id].y=y+i
        return
      end
      for j in 1..i
        if standable2?(x-j,y+i)
          @map.events[id].x=x-j
          @map.events[id].y=y+i
          return
        end
        if standable2?(x+j,y+i)
          @map.events[id].x=x+j
          @map.events[id].y=y+i
          return
        end
        if standable2?(x-j,y-i)
          @map.events[id].x=x-j
          @map.events[id].y=y-i
          return
        end
        if standable2?(x+j,y-i)
          @map.events[id].x=x+j
          @map.events[id].y=y-i
          return
        end
      end
    end
  end
  def set_defeventpos_wall(id,x,y,p4)
    if standable3?(x,y,p4)
      @map.events[id].x=x
      @map.events[id].y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable3?(x,y+i,p4)
        @map.events[id].x=x
        @map.events[id].y=y+i
        return
      end
      for j in 1..i
        if standable3?(x-j,y+i,p4)
          @map.events[id].x=x-j
          @map.events[id].y=y+i
          return
        end
        if standable3?(x+j,y+i,p4)
          @map.events[id].x=x+j
          @map.events[id].y=y+i
          return
        end
        if standable3?(x-j,y-i,p4)
          @map.events[id].x=x-j
          @map.events[id].y=y-i
          return
        end
        if standable3?(x+j,y-i,p4)
          @map.events[id].x=x+j
          @map.events[id].y=y-i
          return
        end
      end
    end
  end
  def playerpos_reset(x,y)
    if standable?(x,y)
      $game_temp.player_new_x=x
      $game_temp.player_new_y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable?(x,y+i)
        $game_temp.player_new_x=x
        $game_temp.player_new_y=y+i
        return
      end
      for j in 0..i
        if standable?(x-j,y+i)
          $game_temp.player_new_x=x-j
          $game_temp.player_new_y=y+i
          return
        end
        if standable?(x+j,y+i)
          $game_temp.player_new_x=x+j
          $game_temp.player_new_y=y+i
          return
        end
        if standable?(x-j,y-i)
          $game_temp.player_new_x=x-j
          $game_temp.player_new_y=y-i
          return
        end
        if standable?(x+j,y-i)
          $game_temp.player_new_x=x+j
          $game_temp.player_new_y=y-i
          return
        end
      end
    end
  end
  def standable_newtile?(p1,p2)
    for i in [2, 1, 0]
      tile_id = @tilesetting[p1, p2, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
  def standable?(p1,p2)
    if @heightdata[p1,p2] != 0
      return false
    end
    if @oneventdata[p1,p2] ==1
      return false
    end
    for i in [2, 1, 0]
      tile_id = @map.data[p1, p2, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
  def standable2?(p1,p2)
    unless standable?(p1,p2)
      return false
    end
    if standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2) == false or
      standable?(p1+1,p2+1) == false
      if standable?(p1-1,p2-1) == false or
        standable?(p1-1,p2) == false or
        standable?(p1-1,p2+1) == false
        if standable?(p1,p2-1) == true and
          standable?(p1,p2+1) == true
          return false
        end
      end
    end
    if standable?(p1+1,p2+1) == false or
      standable?(p1,p2+1) == false or
      standable?(p1-1,p2+1) == false
      if standable?(p1+1,p2-1) == false or
        standable?(p1,p2-1) == false or
        standable?(p1-1,p2-1) == false
        if standable?(p1-1,p2) == true and
          standable?(p1+1,p2) == true
          return false
        end
      end
    end
    if standable?(p1,p2-1) == false and
      (standable?(p1-1,p2+1) == false or
      standable?(p1,p2+1) == false or
      standable?(p1+1,p2+1) == false)
      return false
    end
    if standable?(p1,p2+1) == false and
      (standable?(p1-1,p2-1) == false or
      standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2-1) == false)
      return false
    end
    if standable?(p1-1,p2) == false and
      (standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2) == false or
      standable?(p1+1,p2+1) == false)
      return false
    end
    if standable?(p1+1,p2) == false and
      (standable?(p1-1,p2-1) == false or
      standable?(p1-1,p2) == false or
      standable?(p1-1,p2+1) == false)
      return false
    end
     
    return true
  end
  def standable3?(p1,p2,p3)
    unless standable?(p1,p2+1)
      return false
    end
    if @oneventdata[p1,p2] == 1 or
      @oneventdata[p1,p2-1] == 1 or
      @heightdata[p1,p2-2] != 1 or
      @heightdata[p1,p2-1] == 1 or
   

Blizzard

You still didn't post the whole script and you didn't post the error messages.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

July 14, 2008, 10:15:02 am #4 Last Edit: July 14, 2008, 10:20:27 am by Rymdpotatis
Strange, I posted the whole script before. I'll post it again and hope for the best.
And about the error message:
Line5383:NoMethodError occured. Undefined method `[]' for nil:nilClass happens whenever I try to move the character.


=begin

Random Map Script, by "tonbi", adapted by Peter O.

--------------------


Names of random maps have the following syntax:

[MapName],Random,[Type],[ObjCnt],[Connect]

MapName - Name of the map
Type - Map type:
0 - 2 layers, natural
1 - 2 layers, artificial
2 - 2 layers, natural, convex
3 - 2 layers, artificial, convex
4 - 2 layers, natural, hole/land/wall
5 - 2 layers, artificial, hole/land/wall
6 - 2 layers, natural, hole/land/wall
7 - 2 layers, artificial, hole/land/wall
ObjCnt - Density of objects on the map.  Generally a number divisible by 100.
Connect - If this is equal to "false", the parts of the generated map can be disjoint.
  This setting is optional.

------------------
In addition, the tiles used in the random map must be arranged in a certain way, depending
on the map type; please see the Random Map Sample for details:

http://www.mc.ccnw.ne.jp/sarada/toshi/down/RandomMapSample.exe

------------------

Events can be labeled with one of the following:


Each event on the map can be marked with these features.

Checkpoint - There will always be ground wherever this event is placed.
To Use:  Name the event "MyEvent,Checkpoint" or use a Comment event
command consisting of the text "Checkpoint". ("MyEvent" is arbitrary.)
Fixed - This event will appear at a ground tile next to where this event is located.
To Use:  Name the event "MyEvent,Fixed" or use a Comment event
command consisting of the text "Fixed". ("MyEvent" is arbitrary.)
TotallyFixed - This event will always remain at its position defined on the map.
To Use:  Name the event "MyEvent,TotallyFixed" or use a Comment event
command consisting of the text "TotallyFixed". ("MyEvent" is arbitrary.)
WallFixture - Appears attached to a wall.  May be followed by a comma and either
1 or 0 (0 means the object takes 1 tile space; 1 means 3 tiles).
To Use:  Use a Comment event command consisting of the text "WallFixture,1"
WallFixtureFixed - Appears attached to a wall next to where this event is located.
May be followed by a comma and either 1 or 0 (0 means the object takes 1 tile space;
1 means 3 tiles).
To Use:  Use a Comment event command consisting of the text "WallFixtureFixed,1"

Events without these features will be placed at a random spot on the generated map.

-------------------
=end

 
  USE_TRAIN_ACTOR = false
class Game_Character
 
  DRAWRANGEX = 1920     
  DRAWRANGEY = 1664     
end
class Game_Map
 
  AUTO_MAP_SAVE = true   
                         
                         
end

class Game_Temp
  alias initialize_tonbi1 initialize
  def initialize
    initialize_tonbi1
   
    $onscreen = []                       
  end
end

class Game_Character
  alias update_tonbi1 update
  def update
    sx = @real_x - $game_map.display_x - 1280
    sy = @real_y - $game_map.display_y - 960
    abs_sx = sx > 0 ? sx : -sx
    abs_sy = sy > 0 ? sy-3 : -sy
    if abs_sx > DRAWRANGEX or abs_sy > DRAWRANGEY
      $onscreen[@id]=false
    else
      $onscreen[@id]=true
    end
   
    update_tonbi1
  end
end

class Spriteset_Map
  attr_accessor :character_sprites
  def initialize
   
    $onscreen = []
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    @character_sprites = []
    @party_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites[i]=sprite
      $onscreen[i] = true
    end
    @party_sprites.push(Sprite_Character.new(@viewport1, $game_player))
   
    @weather = RPG::Weather.new(@viewport1)
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    @timer_sprite = Sprite_Timer.new
    update
  end
  def dispose
    @tilemap.tileset.dispose
    for i in 0..6
      @tilemap.autotiles[i].dispose
    end
    @tilemap.dispose
    @panorama.dispose
    @fog.dispose
    for i in @character_sprites
      if i != nil
        i.dispose
      end
    end
    for i in @party_sprites
      if i != nil
        i.dispose
      end
    end
    @weather.dispose
    for sprite in @picture_sprites
      sprite.dispose
    end
    @timer_sprite.dispose
    @viewport1.dispose
    @viewport2.dispose
    @viewport3.dispose
  end
  def update
    if @panorama_name != $game_map.panorama_name or
       @panorama_hue != $game_map.panorama_hue
      @panorama_name = $game_map.panorama_name
      @panorama_hue = $game_map.panorama_hue
      if @panorama.bitmap != nil
        @panorama.bitmap.dispose
        @panorama.bitmap = nil
      end
      if @panorama_name != ""
        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
      end
      Graphics.frame_reset
    end
    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
      @fog_name = $game_map.fog_name
      @fog_hue = $game_map.fog_hue
      if @fog.bitmap != nil
        @fog.bitmap.dispose
        @fog.bitmap = nil
      end
      if @fog_name != ""
        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
      end
      Graphics.frame_reset
    end
    @tilemap.ox = $game_map.display_x / 4
    @tilemap.oy = $game_map.display_y / 4
    @tilemap.update
    @panorama.ox = $game_map.display_x / 8
    @panorama.oy = $game_map.display_y / 8
    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone
    for i in $game_map.events.keys
      if $onscreen[i]
        @character_sprites[i].update
      end
    end
    for i in @party_sprites
      i.update
    end
 
    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update
    for sprite in @picture_sprites
      sprite.update
    end
    @timer_sprite.update
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    @viewport3.color = $game_screen.flash_color
    @viewport1.update
    @viewport3.update
  end
end

if USE_TRAIN_ACTOR == true
  module Train_Actor
    module Spriteset_Map_Module
      def setup_actor_character_sprites(characters)
        if !setup_actor_character_sprites?
          for character in characters.reverse
            @party_sprites.unshift(
              Sprite_Character.new(@viewport1, character)
            )
          end
          @setup_actor_character_sprites_flag = true
        end
      end
    end
  end
end
class Game_Map
  def setup(map_id)
    @map_id = map_id
    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
    tileset = $data_tilesets[@map.tileset_id]
    @tileset_name = tileset.tileset_name
    @autotile_names = tileset.autotile_names
    @panorama_name = tileset.panorama_name
    @panorama_hue = tileset.panorama_hue
    @fog_name = tileset.fog_name
    @fog_hue = tileset.fog_hue
    @fog_opacity = tileset.fog_opacity
    @fog_blend_type = tileset.fog_blend_type
    @fog_zoom = tileset.fog_zoom
    @fog_sx = tileset.fog_sx
    @fog_sy = tileset.fog_sy
    @battleback_name = tileset.battleback_name
    @passages = tileset.passages
    @priorities = tileset.priorities
    @terrain_tags = tileset.terrain_tags
    @display_x = 0
    @display_y = 0
   
    check_special_map
    @need_refresh = false
    @events = {}
    for i in @map.events.keys
      @events[i] = Game_Event.new(@map_id, @map.events[i])
    end
    @common_events = {}
    for i in 1...$data_common_events.size
      @common_events[i] = Game_CommonEvent.new(i)
    end
    @fog_ox = 0
    @fog_oy = 0
    @fog_tone = Tone.new(0, 0, 0, 0)
    @fog_tone_target = Tone.new(0, 0, 0, 0)
    @fog_tone_duration = 0
    @fog_opacity_duration = 0
    @fog_opacity_target = 0
    @scroll_direction = 2
    @scroll_rest = 0
    @scroll_speed = 4
  end
  def check_special_map
    mapinfo  = load_data("Data/MapInfos.rxdata")
    if mapinfo[@map_id].subname == "Random"
      if mapinfo[@map_id].subname(3)=="" or mapinfo[@map_id].subname(3) == nil
        p3 = 0
      else
        p3 = mapinfo[@map_id].subname(3).to_i
      end
      if mapinfo[@map_id].subname(4)=="false"
        p4 = false
      end
     
      make_random_map(2,mapinfo[@map_id].subname(2).to_i,p3,p4)
    end
  end
  def make_random_map(wall = 2, type = 0, objcnt = 0, connect = true)
    wall = 0 if wall == nil
    type = 0 if type == nil
    objcnt = 0 if objcnt == nil
    unless objcnt.is_a?(Numeric)
      objcnt = 0
    end
    if objcnt < 0
      objcnt = 0
    end
    connect = true if connect != false
    @heightdata = Table.new(@map.width,@map.height)
    @maskdata = Table.new(@map.width,@map.height)
    @oneventdata = Table.new(@map.width,@map.height)
    @masksetting = []
    @makedata = []
    @targettype=0
    @chgtype=0
   
    time = -1
    for i in 0...@map.width
      for j in 0...@map.height
        time += 1
        if time%2000 == 0
          Graphics.update
        end
        @heightdata[i,j] = 0
        @maskdata[i,j] = 0
      end
    end
    for i in 0...100
      @masksetting[i] = true
    end
    needposx = []
    needposy = []
    for i in @map.events.keys.sort
      time += 1
      if time%200 == 0
        Graphics.update
      end
      if event_settype(i) == 1
        if connect == true
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
        else
          needposx.push(@map.events[i].x)
          needposy.push(@map.events[i].y)
        end
      end
    end
    if connect == true
      needposx.shift
      needposy.shift
    end
    loop do
      if needposx.size <= 2
        needposx.push(rand(@map.width))
        needposy.push(rand(@map.height))
      else
        break
      end
    end
    case type
    when 0
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,0])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,1,1,1])
      @makedata.push([4,0,1,1,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,1])
    when 1
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-6,4,1,10])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,3,1])
      @makedata.push([4,1,2,2,1])
      @makedata.push([4,0,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,1])
    when 2
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,0])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,2,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,-1])
    when 3
      @makedata.push([0,1,0])
      @makedata.push([5,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,0,-15,4,1,10])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,0,needposx[i*2],needposy[i*2]])
        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])
      end
     
      @makedata.push([4,0,2,2,1])
      @makedata.push([4,1,1,1,1])
     
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,0])
      @makedata.push([2,1,2])
      @makedata.push([5,-1])
    when 4
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,3,3,8,8])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-8,4,0,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
    when 5
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,3,3,8,8])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-8,4,1,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
     
     
    when 6
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,1,1,3,3])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([4,0,2,2,0])
      @makedata.push([4,0,1,2,1])
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-15,4,0,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
     
    when 7
      @makedata.push([0,1,0])
      @makedata.push([5,0])
      @makedata.push([1,0,0,-1,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,0,-1,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,-1,-1,0,-1])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([1,0,-1,0,0])
      @makedata.push([3,2,-6,1,0])
      @makedata.push([4,2,2,2,1])
      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))
        @makedata.push([1,1,1,3,3])
        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])
      end
      @makedata.push([4,0,2,2,0])
      @makedata.push([4,0,1,2,1])
      @makedata.push([7,2])
      @makedata.push([4,2,1,1,1])
      for i in 0...(needposx.size/2)
        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])
        @makedata.push([3,1,-15,4,1,5])
        @makedata.push([1,1,1,1,1])
        @makedata.push([6,1,needposx[i*2],needposy[i*2]])
        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])
      end
      @makedata.push([4,1,1,1,1])
      @makedata.push([4,1,0,1,1])
      @makedata.push([2,0,0])
      @makedata.push([4,1,1,0,1])
      @makedata.push([2,-1,1])
      @makedata.push([4,2,1,1,1])
      @makedata.push([0,0,0])
      @makedata.push([2,0,2])
      @makedata.push([5,-1])
      @makedata.push([2,1,2])
      @makedata.push([5,0])
      @makedata.push([2,2,2])
      @makedata.push([5,1])
    end
    for make_stat in @makedata
      time += 1
      if time%2 == 0
        Graphics.update
      end
      case make_stat[0]
      when 0   
        rndmap_chtarget(make_stat[1],make_stat[2])
      when 1   
        rndmap_setstat(make_stat[1],make_stat[2],make_stat[3],make_stat[4])
      when 2   
        rndmap_chmask(make_stat[1],make_stat[2])
      when 3   
        rndmap_mkroad(make_stat[1],make_stat[2],make_stat[3],make_stat[4],make_stat[5])
      when 4   
        rndmap_plus(make_stat[1],make_stat[2],make_stat[3],make_stat[4])
      when 5   
        rndmap_allchg(make_stat[1])
      when 6   
        rndmap_putpos(make_stat[1],make_stat[2],make_stat[3])
      when 7   
        rndmap_edge(make_stat[1])
      end
    end
    @tilesetting = Table.new(3,40,3)
    for i in [0,1,2]
      for k in 0...40
        for j in [0,1,2]
          @tilesetting[j,k,i] = @map.data[j,k,i]
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 1
          if @heightdata[j,k+1]==-1
            @heightdata[j,k+1] = 0
            if @heightdata[j,k+2]==-1 and
              @heightdata[j,k+3] == 0
              @heightdata[j,k+2] = 0
            end
          end
        end
       
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 0
          if @heightdata[j,k+1] == -1 or
            @heightdata[j,k-1] == -1 or
            @heightdata[j+1,k] == -1 or
            @heightdata[j-1,k] == -1
            set_mapdata2(j,k,0,8)
          else
            set_mapdata2(j,k,0,0)
          end
        elsif @heightdata[j,k] == 1
          if @heightdata[j,k+1] == -1 or
            @heightdata[j,k-1] == -1 or
            @heightdata[j+1,k] == -1 or
            @heightdata[j-1,k] == -1
            set_mapdata2(j,k,0,8)
          elsif @heightdata[j,k+1] == 0 or
            @heightdata[j,k-1] == 0 or
            @heightdata[j+1,k] == 0 or
            @heightdata[j-1,k] == 0
            set_mapdata2(j,k,0,0)
          else
            set_mapdata2(j,k,1,4)
          end
        else
          set_mapdata2(j,k,0,8)
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 0
          if @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == -1
              for i in [0,1,2]
                set_mapdata(j,k+i,0,13+i,1)
              end
            elsif @heightdata[j+1,k] == -1
              for i in [0,1,2]
                set_mapdata(j,k+i,2,13+i,1)
              end
            else
              for i in [0,1,2]
                set_mapdata(j,k+i,1,13+i,1)
              end
            end
          elsif @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == -1 or
            (@heightdata[j-1,k] == 1 and
            @heightdata[j-1,k-1] == -1)
              set_mapdata(j,k,0,11,2)
            elsif @heightdata[j+1,k] == -1 or
            (@heightdata[j+1,k] == 1 and
            @heightdata[j+1,k-1] == -1)
              set_mapdata(j,k,2,11,2)
            else
              set_mapdata(j,k,1,11,2)
            end
          elsif @heightdata[j-1,k] == -1 or
            (@heightdata[j-1,k] == 1 and
            @heightdata[j-1,k-1] == -1)
            set_mapdata(j,k,0,12,1)
          elsif @heightdata[j+1,k] == -1 or
            (@heightdata[j+1,k] == 1 and
            @heightdata[j+1,k-1] == -1)
            set_mapdata(j,k,2,12,1)
          elsif @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,9,1)
          elsif @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,10,1)
          elsif @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,9,1)
          elsif @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,10,1)
          end
        end
        if @heightdata[j,k] == 1 and
          @heightdata[j,k-1] != -1
         
          if @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == -1
              for i in [0,1,2]
              end
            elsif @heightdata[j+1,k] == -1
              for i in [0,1,2]
              end
            else
              for i in [0,1,2]
              end
            end
          elsif @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == -1
              set_mapdata(j,k,0,11,2)
            elsif @heightdata[j+1,k] == -1
              set_mapdata(j,k,2,11,2)
            else
              set_mapdata(j,k,1,11,2)
            end
          elsif @heightdata[j-1,k] == -1
            set_mapdata(j,k,0,12,1)
          elsif @heightdata[j+1,k] == -1
            set_mapdata(j,k,2,12,1)
          elsif @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,9,1)
          elsif @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,10,1)
          elsif @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,9,1)
          elsif @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,10,1)
          end
        end
      end
    end
    time = 0
    for k in 0...@map.height
      for j in 0...@map.width
        time += 1
        if time%500 == 0
          Graphics.update
        end
        if @heightdata[j,k] == 1
          if @heightdata[j,k+1] == 0 or
            @heightdata[j,k+1] == -1
            if @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
              set_mapdata(j,k+0,0,5+0,5)
              set_mapdata(j,k+1,0,5+1,5)
              set_mapdata(j,k+2,0,5+2,4)
              if @heightdata[j,k+3] != 0 and
                @heightdata[j,k+2] != 1 and
                (@heightdata[j,k+2] != 0 or @heightdata[j-1,k+2] != 0)
                set_mapdata(j,k+2,0,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,0,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
              set_mapdata(j,k+0,2,5+0,5)
              set_mapdata(j,k+1,2,5+1,5)
              set_mapdata(j,k+2,2,5+2,4)
              if @heightdata[j,k+3] != 0 and
                @heightdata[j,k+2] != 1 and
                (@heightdata[j,k+2] != 0 or @heightdata[j+1,k+2] != 0)
                set_mapdata(j,k+2,2,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,2,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            else
              set_mapdata(j,k+0,1,5+0,5)
              set_mapdata(j,k+1,1,5+1,5)
              set_mapdata(j,k+2,1,5+2,4)
              if @heightdata[j,k+3] != 0 and
                 @heightdata[j,k+2] != 1
                set_mapdata(j,k+2,1,16,5)
                for i in [0,1]
                  set_mapdata(j,k+3+i,1,14+i,1)
                  if @heightdata[j,k+3+i] != -1
                    break
                  end
                end
              end
            end
          elsif @heightdata[j,k-1] == 0 or
              @heightdata[j,k-1] == -1
            if @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
              set_mapdata(j,k,0,3,4)
            elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
              set_mapdata(j,k,2,3,4)
            else
              set_mapdata(j,k,1,3,4)
            end
          elsif @heightdata[j-1,k] == 0 or
              @heightdata[j-1,k] == -1
            set_mapdata(j,k,0,4,4)
          elsif @heightdata[j+1,k] == 0 or
              @heightdata[j+1,k] == -1
            set_mapdata(j,k,2,4,4)
          elsif @heightdata[j-1,k-1] == 0 or
              @heightdata[j-1,k-1] == -1
            set_mapdata(j,k,0,1,4)
          elsif @heightdata[j-1,k+1] == 0 or
              @heightdata[j-1,k+1] == -1
            set_mapdata(j,k,0,2,4)
          elsif @heightdata[j+1,k-1] == 0 or
              @heightdata[j+1,k-1] == -1
            set_mapdata(j,k,1,1,4)
          elsif @heightdata[j+1,k+1] == 0 or
              @heightdata[j+1,k+1] == -1
            set_mapdata(j,k,1,2,4)
          end
        end
      end
    end
    playerpos_reset($game_temp.player_new_x,$game_temp.player_new_y)
    @oneventdata[$game_temp.player_new_x,$game_temp.player_new_y] = 1
   
    time = 0
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      case event_settype(i)
      when 3
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      end
    end
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      case event_settype(i)
      when 1
        set_defeventpos(i,@map.events[i].x,@map.events[i].y)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      end
    end
    for i in @map.events.keys.sort
      time += 1
      if time%100 == 0
        Graphics.update
      end
      j = event_settype(i)
      case j
      when 0 
        set_defeventpos(i,rand(@map.width-4)+2,rand(@map.width-4)+2)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      when 2 
        set_defeventpos(i,@map.events[i].x,@map.events[i].y)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
      when 100..199 
        set_defeventpos_wall(i,rand(@map.width-4)+2,rand(@map.width-4)+2,j-100)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1
        for k in 1..(j-100)
          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1
        end
      when 200..299 
        set_defeventpos_wall(i,@map.events[i].x,@map.events[i].y,j-200)
        @oneventdata[@map.events[i].x,@map.events[i].y] = 1
        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1
        for k in 1..(j-200)
          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1
          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1
        end
      end
    end
    for i in 0...(rand(objcnt)+objcnt/2)
      time += 1
      if time%500 == 0
        Graphics.update
      end
      j = rand(@map.width)
      k = rand(@map.width)
      case rand(10)
      when 0..4
        if standable_newtile?(1,0)
          if standable?(j,k)
            set_mapdata(j,k,1,0,6)
          end
        else
          if standable2?(j,k)
            set_mapdata(j,k,1,0,6)
          end
        end
      when 5..7
        if standable_newtile?(2,0)
          if standable?(j,k)
            set_mapdata(j,k,2,0,6)
          end
        else
          if standable2?(j,k)
            set_mapdata(j,k,2,0,6)
          end
        end
      when 8..9
        if standable2?(j,k)
          if @map.data[j,k-1,2]==0 and
            (@map.data[j,k,1]==0 or @map.data[j,k,2]==0)
            set_mapdata(j,k,2,2,4)   
            set_mapdata(j,k-1,2,1,4) 
          end
        end
      end
    end
    @heightdata.resize(0,0)
    @maskdata.resize(0,0)
    @oneventdata.resize(0,0)
    @masksetting.clear
    @makedata.clear
    @tilesetting.resize(0,0,0)
   
    if AUTO_MAP_SAVE
      save_data(@map,sprintf("Data/Map%03d.rxdata", 999))
      maplist  = load_data("Data/MapInfos.rxdata")
     
      mapinfo = RPG::MapInfo.new
      mapinfo.name = sprintf("Auto-saved random map (%s)", maplist[@map_id].name)
      mapinfo.parent_id = 0
      mapinfo.order = 999
      mapinfo.expanded = true
      mapinfo.scroll_x = 0
      mapinfo.scroll_y = 0
     
      maplist[999]=mapinfo
      save_data(maplist,"Data/MapInfos.rxdata")
    end
  end
  def event_settype(i)
    if @map.events[i].subname == "Checkpoint"
      return 1
    end
    if @map.events[i].subname == "Fixed"
      return 2
    end
    if @map.events[i].subname == "TotallyFixed"
      return 3
    end
    for j in 0..1000
      if @map.events[i].pages[0].list[j].code != 108
        break
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Checkpoint"
        return 1
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "TotallyFixed"
        return 3
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Fixed"
        return 2
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "WallFixture"
        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil
          return 100
        else
          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]
          k = k.to_i
          return 100+k
        end
      end
      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "WallFixtureFixed"
        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil
          return 200
        else
          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]
          k = k.to_i
          return 200+k
        end
      end
    end
    return 0
  end
  def set_defeventpos(id,x,y)
    if standable2?(x,y)
      @map.events[id].x=x
      @map.events[id].y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable2?(x,y+i)
        @map.events[id].x=x
        @map.events[id].y=y+i
        return
      end
      for j in 1..i
        if standable2?(x-j,y+i)
          @map.events[id].x=x-j
          @map.events[id].y=y+i
          return
        end
        if standable2?(x+j,y+i)
          @map.events[id].x=x+j
          @map.events[id].y=y+i
          return
        end
        if standable2?(x-j,y-i)
          @map.events[id].x=x-j
          @map.events[id].y=y-i
          return
        end
        if standable2?(x+j,y-i)
          @map.events[id].x=x+j
          @map.events[id].y=y-i
          return
        end
      end
    end
  end
  def set_defeventpos_wall(id,x,y,p4)
    if standable3?(x,y,p4)
      @map.events[id].x=x
      @map.events[id].y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable3?(x,y+i,p4)
        @map.events[id].x=x
        @map.events[id].y=y+i
        return
      end
      for j in 1..i
        if standable3?(x-j,y+i,p4)
          @map.events[id].x=x-j
          @map.events[id].y=y+i
          return
        end
        if standable3?(x+j,y+i,p4)
          @map.events[id].x=x+j
          @map.events[id].y=y+i
          return
        end
        if standable3?(x-j,y-i,p4)
          @map.events[id].x=x-j
          @map.events[id].y=y-i
          return
        end
        if standable3?(x+j,y-i,p4)
          @map.events[id].x=x+j
          @map.events[id].y=y-i
          return
        end
      end
    end
  end
  def playerpos_reset(x,y)
    if standable?(x,y)
      $game_temp.player_new_x=x
      $game_temp.player_new_y=y
      return
    end
    for i in 1..([@map.width,@map.height].max)
      if standable?(x,y+i)
        $game_temp.player_new_x=x
        $game_temp.player_new_y=y+i
        return
      end
      for j in 0..i
        if standable?(x-j,y+i)
          $game_temp.player_new_x=x-j
          $game_temp.player_new_y=y+i
          return
        end
        if standable?(x+j,y+i)
          $game_temp.player_new_x=x+j
          $game_temp.player_new_y=y+i
          return
        end
        if standable?(x-j,y-i)
          $game_temp.player_new_x=x-j
          $game_temp.player_new_y=y-i
          return
        end
        if standable?(x+j,y-i)
          $game_temp.player_new_x=x+j
          $game_temp.player_new_y=y-i
          return
        end
      end
    end
  end
  def standable_newtile?(p1,p2)
    for i in [2, 1, 0]
      tile_id = @tilesetting[p1, p2, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
  def standable?(p1,p2)
    if @heightdata[p1,p2] != 0
      return false
    end
    if @oneventdata[p1,p2] ==1
      return false
    end
    for i in [2, 1, 0]
      tile_id = @map.data[p1, p2, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
  def standable2?(p1,p2)
    unless standable?(p1,p2)
      return false
    end
    if standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2) == false or
      standable?(p1+1,p2+1) == false
      if standable?(p1-1,p2-1) == false or
        standable?(p1-1,p2) == false or
        standable?(p1-1,p2+1) == false
        if standable?(p1,p2-1) == true and
          standable?(p1,p2+1) == true
          return false
        end
      end
    end
    if standable?(p1+1,p2+1) == false or
      standable?(p1,p2+1) == false or
      standable?(p1-1,p2+1) == false
      if standable?(p1+1,p2-1) == false or
        standable?(p1,p2-1) == false or
        standable?(p1-1,p2-1) == false
        if standable?(p1-1,p2) == true and
          standable?(p1+1,p2) == true
          return false
        end
      end
    end
    if standable?(p1,p2-1) == false and
      (standable?(p1-1,p2+1) == false or
      standable?(p1,p2+1) == false or
      standable?(p1+1,p2+1) == false)
      return false
    end
    if standable?(p1,p2+1) == false and
      (standable?(p1-1,p2-1) == false or
      standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2-1) == false)
      return false
    end
    if standable?(p1-1,p2) == false and
      (standable?(p1+1,p2-1) == false or
      standable?(p1+1,p2) == false or
      standable?(p1+1,p2+1) == false)
      return false
    end
    if standable?(p1+1,p2) == false and
      (standable?(p1-1,p2-1) == false or
      standable?(p1-1,p2) == false or
      standable?(p1-1,p2+1) == false)
      return false
    end
     
    return true
  end
  def standable3?(p1,p2,p3)
    unless standable?(p1,p2+1)
      return false
    end
    if @oneventdata[p1,p2] == 1 or
      @oneventdata[p1,p2-1] == 1 or
      @heightdata[p1,p2-2] != 1 or
      @heightdata[p1,p2-1] == 1 or
      @heightdata[p1,p2+1] != 0
      return false
    end
    for i in 1...p3+1
      if@heightdata[p1+i,p2-2] != 1 or
        @heightdata[p1+i,p2-1] == 1 or
        @heightdata[p1+i,p2+1] != 0
        return false
      end
      if@heightdata[p1-i,p2-2] != 1 or
        @heightdata[p1-i,p2-1] == 1 or
        @heightdata[p1-i,p2+1] != 0
        return false
      end
    end
    for i in 1...p3+1
      if @oneventdata[p1+i,p2] == 1 or
        @oneventdata[p1+i,p2-1] == 1
        return false
      end
      if @oneventdata[p1-i,p2] == 1 or
        @oneventdata[p1-i,p2-1] == 1
        return false
      end
    end
    return true
  end
  def set_mapdata(p1,p2,p3,p4,p5 = 0)
    unless self.valid?(p1, p2)
      return
    end
    if @tilesetting[p3,p4,0] != 0
      @map.data[p1,p2,0] = @tilesetting[p3,p4,0]
    end
    case p5
    when 0
      if @tilesetting[p3,p4,1] != 0
        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]
      end
      if @tilesetting[p3,p4,2] != 0
        @map.data[p1,p2,2] = @tilesetting[p3,p4,2]
      end
    when 1
      if @tilesetting[p3,p4,1] != 0
        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]
      end
    when 2
      if @tilesetting[p3,p4,1] != 0
        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]
      end
    when 3
      if @tilesetting[p3,p4,1] != 0
        if @map.data[p1,p2,1] != 0
          @map.data[p1,p2,2] = @map.data[p1,p2,1]
        end
        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]
      end
    when 4
      if @tilesetting[p3,p4,1] != 0
        if @map.data[p1,p2,2] != 0
          @map.data[p1,p2,1] = @map.data[p1,p2,2]
        end
        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]
      end
    when 5
      if @tilesetting[p3,p4,1] != 0
        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]
      end
      if @tilesetting[p3,p4,1] != 0
        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]
      end
    when 6
      if @map.data[p1,p2,1] == 0
        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]
      elsif @map.data[p1,p2,2] == 0
        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]
      end
    end
  end
  def set_mapdata2(p1,p2,p3,p4)
    @map.data[p1,p2,0] = @tilesetting[p3,p4,0]
    @map.data[p1,p2,1] = @tilesetting[p3,p4,1]
    @map.data[p1,p2,2] = @tilesetting[p3,p4,2]
  end
  def set_height(p1,p2,p3)
    return if p1<0
    return if p1>=@map.width
    return if p2<0
    return if p2>=@map.height
    @heightdata[p1,p2]=p3
  end
  def set_grounddata(p1,p2,p3)
    return if p1<0
    return if p1>=@map.width
    return if p2<0
    return if p2>=@map.height
    if @masksetting[@maskdata[p1,p2]] == true
      if @targettype==0
        if @chgtype==0
          @heightdata[p1,p2]=p3
        elsif @chgtype==1
          @heightdata[p1,p2]+=p3
        end
      elsif @targettype==1
        if @chgtype==0
          @maskdata[p1,p2]=p3
        elsif @chgtype==1
          @maskdata[p1,p2]+=p3
        end
      end
    end
  end
  def rndmap_chtarget(p1,p2)
    @targettype=p1
    @chgtype=p2
  end
  def rndmap_setstat(p1,p2,p3,p4)
    @minx=p1
    @miny=p2
    @maxx=p3
    @maxy=p4
  end
  def rndmap_chmask(p1,p2)
    if p1>=0
      if p2==0
        @masksetting[p1]=false
      elsif p2 == 1
        @masksetting[p1]=true
      elsif p2 == 2
        for i in 0...100
          @masksetting[i]=false
        end
        @masksetting[p1]=true
      end
    end
    if p1==-1
      if p2==0
        for i in 0...100
          @masksetting[i]=false
        end
      else   
        for i in 0...100
          @masksetting[i]=true
        end
      end
    end
  end
  def rndmap_mkroad(p1,p2,p3,p4,p5 = 5)
    p5 = 5 if p5 == nil
   
    localdata = Table.new(@map.width,@map.height)
    aposx = []
    aposy = []
    aflag = []
    for i in 0...@map.width
      for j in 0...@map.height
        localdata[i,j] = 0
      end
    end
   
    if p2<0
      p2=(p2*-1)*@map.width*@map.height/40/40
    end
    aposx[0]=@minx
    aposy[0]=@miny
    aposx[1]=@maxx
    aposy[1]=@maxy

    if aposx[0]<0
      aposx[0]=@map.width+aposx[0]
    end
    if (aposx[0]>=1000) and (aposx[0]<=1100)
      aposx[0]=@map.width*(aposx[0]-1000)/100
    end

    if aposy[0]<0
      aposy[0]=@map.height+aposy[0]
    end
    if (aposy[0]>=1000) and (aposy[0]<=1100)
      aposy[0]=@map.height*(aposy[0]-1000)/100
    end


    if aposx[1]<0
      aposx[1]=@map.width+aposx[1]
    end
    if (aposx[1]>=1000) and (aposx[1]<=1100)
      aposx[1]=@map.width*(aposx[1]-1000)/100
    end


    if aposy[1]<0
      aposy[1]=@map.height+aposy[1]
    end
    if (aposy[1]>=1000) and (aposy[1]<=1100)
      aposy[1]=@map.height*(aposy[1]-1000)/100
    end

    if p4==0 or p4==1 or p4==2
      if p4 == 2
        i4 = rand(2)
      end
      aflag[0] = true
      aflag[1] = false
      for i in 2...(p2+2)
        aposx[i] = rand(@map.width-p3*2) + p3
        aposy[i] = rand(@map.height-p3*2) + p3
        aflag[i] = false
      end
      i3=0
      i1=aposx[i3]
      i2=aposy[i3]
     
      localdata[i1,i2] = 1
     
      for i in 0...p2+2
        i7=5000000
        for j in 0...p2+2
          if aflag[j] == false
            i4 = aposx[j]-i1
            i4=i4*-1 if i4 < 0
            i5 = aposy[j]-i2
            i5=i5*-1 if i5 < 0
            if (i4**2+i5**2) <=(p5**2) and j != 1
              aflag[j] = true
            elsif i7 > (i4**2+i5**2)
              i7=(i4**2+i5**2)
              i6=j
            end
          end
        end
        if p4==0
          if aposx[i3] > aposx[i6]
            i8 = aposx[i3]
            i9 = aposy[i3]
            i10 = aposx[i6]
            i11 = aposy[i6]
          else
            i8 = aposx[i6]
            i9 = aposy[i6]
            i10 = aposx[i3]
            i11 = aposy[i3]
          end
          if i8!=i10
            for i in 0..(i8-i10)
              localdata[i+i10,(i9-i11)*i/(i8-i10)+i11] = 1
            end
          end
          if aposy[i3] > aposy[i6]
            i8 = aposx[i3]
            i9 = aposy[i3]
            i10 = aposx[i6]
            i11 = aposy[i6]
          else
            i8 = aposx[i6]
            i9 = aposy[i6]
            i10 = aposx[i3]
            i11 = aposy[i3]
          end
          if i9!=i11
            for i in 0..(i9-i11)
              localdata[(i8-i10)*i/(i9-i11)+i10,i+i11] = 1
            end
          end
        end
        if p4==1
          i4 = rand(2)
          if i4==0
            for i in 0..([aposx[i3]-aposx[i6],aposx[i6]-aposx[i3]].max)
              localdata[i+[aposx[i3],aposx[i6]].min,aposy[i3]] = 1
            end
            for i in 0..([aposy[i3]-aposy[i6],aposy[i6]-aposy[i3]].max)
              localdata[aposx[i6],i+[aposy[i3],aposy[i6]].min] = 1
            end
          else
            for i in 0..([aposx[i3]-aposx[i6],aposx[i6]-aposx[i3]].max)
              localdata[i+[aposx[i3],aposx[i6]].min,aposy[i6]] = 1
            end
            for i in 0..([aposy[i3]-aposy[i6],aposy[i6]-aposy[i3]].max)
              localdata[aposx[i3],i+[aposy[i3],aposy[i6]].min] = 1
            end
          end
        end
        i3=i6
        i1=aposx[i3]
        i2=aposy[i3]
        aflag[i3]=true
        if i3==1
          break
        end
      end
    end
    for i in 0...@map.width
      for j in 0...@map.height
        if localdata[i,j] == 1
          set_grounddata(i,j,p1)
        end
      end
    end
  end
  def rndmap_plus(p1,p2,p3,p4)
    localdata = Table.new(@map.width,@map.height)
    for i in 0...@map.width
      for j in 0...@map.height
        if @targettype==0
          localdata[i,j] = @heightdata[i,j]
        elsif @targettype==1
          localdata[i,j] = @maskdata[i,j]
        end
      end
    end
    if p4 == 0
      for i in 0...@map.width
        for j in 0...@map.height
          if p1==localdata[i,j]
            for k in 1..p2
              set_grounddata(i+k,j,p1)
              set_grounddata(i-k,j,p1)
            end
            for k in 1..p3
              set_grounddata(i,j+k,p1)
              set_grounddata(i,j-k,p1)
            end
          end
        end
      end
    elsif p4 == 1
      for i in 0...@map.width
        for j in 0...@map.height
          if p1==localdata[i,j]
            for k in (i-p2)..(i+p2)
              for l in (j-p3)..(j+p3)
                set_grounddata(k,l,p1)
              end
            end
          end
        end
      end
    end
  end
  def rndmap_allchg(p1)
    for i in 0...@map.width
      for j in 0...@map.height
        set_grounddata(i,j,p1)
      end
    end
  end
  def rndmap_putpos(p1,p2,p3)
    i = rand(@maxx-@minx+1)+@minx
    j = rand(@maxy-@miny+1)+@miny
    for k in (p2-i)..(p2+i)
      for l in (p3-j)..(p3+j)
        set_grounddata(k,l,p1)
      end
    end
  end
  def rndmap_edge(p1)
    for i in 0...@map.width
      set_grounddata(i,0,p1)
      set_grounddata(i,@map.height-1,p1)
    end
    for i in 0...@map.height
      set_grounddata(0,i,p1)
      set_grounddata(@map.width-1,i,p1)
    end
  end
end
module RPG
  class MapInfo
    def name
      name = @name.split(/,/)[0]
      return name != nil ? name : ''
    end
    def name=(str)
      str2 = @name[/^[^,]*(,.*)/, 1]
      @name = str2 != nil ? str + str2 : str
    end
    def subname(i = 1)
      name = @name.split(/,/)[i]
      return name != nil ? name : ""
    end
  end
end
module RPG
  class Event
    def name
      name = @name.split(/,/)[0]
      return name != nil ? name : ''
    end
    def name=(str)
      str2 = @name[/^[^,]*(,.*)/, 1]
      @name = str2 != nil ? str + str2 : str
    end
    def subname(i = 1)
      name = @name.split(/,/)[i]
      return name != nil ? name : ""
    end
  end
end

Blizzard

July 14, 2008, 10:44:02 am #5 Last Edit: July 14, 2008, 11:08:57 am by Blizzard
Which version of Blizz-ABS is it and which part? I can't find anything on line 5383 in any part of v1.98.

And has that scripter ever heard of functionial cohersion in programming?! I mean JESUS CHRIST! He has a method that is 692 lines long! You can't script any worse than that, you simply can't. =/
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

Dont blame this guy though he trying to USE the horrid scripters work! lol 692 lines thats insane
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

The part "You can't script any worse than that, you simply can't." refers to the scripter, not to Rymdpotatis. xD And Rymdpotatis is a she. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

July 14, 2008, 01:27:26 pm #8 Last Edit: July 14, 2008, 01:30:11 pm by Rymdpotatis
Yeah, I admit it's not the best made script out there, but it's the only one I know of that can generate dungeons^^

And the version I'm using is 1.98 and the error came up in part 1.

Blizzard

Part 1?! O_O Something must be wrong with your configuration then. Part 1 is for the configuration only. Post the whole method and the line that is giving the error.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

July 14, 2008, 03:10:11 pm #10 Last Edit: July 14, 2008, 03:26:56 pm by Rymdpotatis
Quote from: Blizzard on July 14, 2008, 01:58:16 pm
Part 1?! O_O Something must be wrong with your configuration then. Part 1 is for the configuration only. Post the whole method and the line that is giving the error.



You got it, boss.
Here is the line that's giving me trouble:
    return (x/pix == nx && y/pix == ny || v_map[x/pix, y/pix] & bit != 0x00)



Wasn't sure what you meant by the whole method. (I blame the language barrier on me being Swedish)
Would that be a specific part of the script, the the whole script?


P.S: I checked wrong, the error is in the second part, not the first.

Blizzard

Hm... If I'm not wrong this should be happening if you are using an old savegame. Try using Blizz-ABS with a new game. Other than that try deleting the file Map_Data.abs in the Data folder (if it is there) and changing the option INTELLIGENT_PASSABILITY.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

Quote from: Blizzard on July 14, 2008, 04:28:12 pm
Hm... If I'm not wrong this should be happening if you are using an old savegame. Try using Blizz-ABS with a new game. Other than that try deleting the file Map_Data.abs in the Data folder (if it is there) and changing the option INTELLIGENT_PASSABILITY.


Blizz-ABS works fine if I delete the Dungeon script. It only acts up when I put the dungeon script in witch is strange since they shouldn't be affecting eachother. =/
Tested making a new project to try out the scripts and I get the same error.

Blizzard

July 15, 2008, 07:44:36 am #13 Last Edit: July 15, 2008, 07:45:27 am by Blizzard
I just went a little bit more detailed through that script... Wow, that's all I have to say. No wonder it doesn't work, that guy changed important stuff related to RMXP which is used by Blizz-ABS as well. He renamed variables, didn't alias anything that he should have. I would make this compatible but I can't get rid of the feeling that actually making a completely new script that does the same would take less time than making his script compatible. =/ I guess you'll have to ask him to make his script work with Blizz-ABS. I really don't have the time to go through his code and fix it. -_-
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Rymdpotatis

Quote from: Blizzard on July 15, 2008, 07:44:36 am
I just went a little bit more detailed through that script... Wow, that's all I have to say. No wonder it doesn't work, that guy changed important stuff related to RMXP which is used by Blizz-ABS as well. He renamed variables, didn't alias anything that he should have. I would make this compatible but I can't get rid of the feeling that actually making a completely new script that does the same would take less time than making his script compatible. =/ I guess you'll have to ask him to make his script work with Blizz-ABS. I really don't have the time to go through his code and fix it. -_-



Alright, thanks for your effort to help. I appreciate it. Not many people out there are willing to help others out with scripts. =)