Jump to content
Animebryan

Script for Random Generating Dungeons

Recommended Posts

I need a script that generates random dungeons each time you enter. There's one that does this but it uses a mini-map that's an eyesore & a feature where only the room or corridor you're in is highlighted & all the other rooms & corridors are slightly darkened & all the events in those places are hidden until you enter them. I just want a stand alone script that generates random dungeon floors & randomly places you in the room when you enter (regardless of where the transfer coordinates are), and randomly places all events in the room (without putting them inside walls & such). Here is the link to the script I was refering to: http://www.rpgmakerv...geon +generator

 

I noticed it has a few flaws as well, like not spacing out the chests & such away from each other (clusters up to 6 or 7 events together in the same room). I've also noticed flaws with walls or ceiling tiles are missing & let you walk through some areas. It also throws a hissyfit if you leave any of the designated tilespots blank (which I need for certain dungeons). It also has a feature where you can put a * at the end of an enemy event name & the script will multiply those enemies by the number of steps needed between battles (in the lower right corner of the map properties window). However, it sets it up to where the enemies chase you by default instead of acting or moving the way you set them up. Having that enemy duplication ability is nice, just not the forced chase behavior.

 

I just need a script that randomly generates dungeon floors, randomly places you on the map regardless of transfer position, randomly places events such as chests, enemies & staircases without putting them in the walls. I've asked for help in the Help & Support & RGSS3 Script Language Support sections but no one responded. I need this script for a dungeon in my current project & for another project. I can't move on with this until I have one & if I can't get any help on this then I have no other choice but to give up on my project & that's the last thing I want to do. I've heard of too many people who had really good ideas for games & motivation to go through with them but quit due to inability to make the game work the way they want it to. I thank anyone in advance who could either modify the linked script or create one from scratch.

Share this post


Link to post
Share on other sites

Noticed tomoaky had one...http://hikimoki.sakura.ne.jp/html/randmap.html

except it's for VX

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Noticed tomoaky had one...http://hikimoki.sakura.ne.jp/html/randmap.html

except it's for VX

 

Which means it needs to be modified to be used in VX Ace. Do you think you could modify it for Ace? I can't move on with my project until I resolve this issue.

Share this post


Link to post
Share on other sites

So is there anyone else who could help me with a random dungeon generator script?

Share this post


Link to post
Share on other sites

the random generator is not an easy script (it will have lots of lines so converting is a bit hard too i guess). so i guess it's better waiting for tomiaky to convert his script to ace (he already convert some of his script to ace just pray he will convert random generator too)

Share this post


Link to post
Share on other sites

Does anyone know how long it will take tomiaky to convert it or if he's even working on it at all? What about Saba Kan's script? Could anyone just remove the mini-map function & just have the dungeon generator not rely on the mini-map script at all? I understand that making a script from scratch is a bit much, so it's better to work off of a pre-existing script.

Share this post


Link to post
Share on other sites

I have been working with Saba Kan's script a lot my self, and I think I might be able to help you get rid of the parts you don't want. Actually removing the mini map script is fairly simple if I remember correctly... there are just a few things that are inexplicably defined in the mini map script that should be done in the main script. I also got rid of the light script and turn-based movement script so I could replace it with my own (one that uses "Khas Awesome Light Effects" no less). Anyway, try these scripts:

 

Dungeon generation part:

 

#==============================================================================

# - Dungeon Creation 6 KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# To many changes to really list, lots of little things.

#==============================================================================

module Saba

module Dungeon

# Minumum block size (Hard to explain, try it out yourself)

# Default: 7

MINIMUM_RECT_SIZE = 5

 

# Minimum room size.

# Default: 3

MINIMUM_ROOM_SIZE = 3

 

# Margin between rooms and 'blocks'.

# Default: 2

MARGIN_BETWEEN_RECT_ROOM = 2

 

# The percentage of corridors made. (1/n)

# Works best with lower values.

# Default: 35

MORE_COUPLE_RATE = 35

 

# Variable that stores enemy amount.

ENEMY_COUNT_VARIABLE = 3

end

end

 

#=========================================================================

# Do not edit anything under this line unless you know what you're doing!

#=========================================================================

 

#==============================================================================

# â–  Dungeon_Rect

#------------------------------------------------------------------------------

#  ダンジョンを区切ã£ãŸé ˜åŸŸã‚’表ã—ã¾ã™ã€‚

#ã€€å„ Dungeon_Rect ã«ä¸€ã¤ã¥ã¤ Room ãŒå­˜åœ¨ã—ã¾ã™ã€‚

#==============================================================================

class Dungeon_Rect

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :room

attr_accessor :done_split_v

attr_accessor :done_split_h

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

self.done_split_v = false

self.done_split_h = false

end

end

 

#==============================================================================

# â–  Room

#------------------------------------------------------------------------------

#  部屋ã§ã™ã€‚

#==============================================================================

class Room

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :mapping

attr_reader :width

attr_reader :height

attr_reader :couple_areas # 通路ã«é¢ã—ã¦ã„ã‚‹[x, y]ã®ãƒªã‚¹ãƒˆ

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

@width = hx - lx

@height = hy - ly

@events = {}

@couple_areas = []

@mapping = false

end

 

#--------------------------------------------------------------------------

# ◠イベントé…ç½®å¯èƒ½æ•°æ®‹ã‚Šã‚’å–å¾—

#--------------------------------------------------------------------------

def remain

return (hx - lx) * (hy - ly) - @events.size - @couple_areas.size

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’å«ã‚“ã§ã„ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def contains(x, y)

return lx <= x && x < hx && ly <= y && y < hy

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’明るãã™ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def right_area?(x, y)

return lx-1 <= x && x < hx+1 && ly-1 <= y && y < hy+1

end

end

 

#==============================================================================

# â–  Couple

#------------------------------------------------------------------------------

#  通路ã§ã™ã€‚

#==============================================================================

class Couple

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :rect0

attr_accessor :rect1

attr_accessor :direction

end

 

class Game_Map

attr_reader :map

attr_reader :dungeon_base_level

attr_reader :floor_level_rate

#--------------------------------------------------------------------------

# ◠定数

#--------------------------------------------------------------------------

COUPLE_VERTICAL = 0

COUPLE_HORIZONAL = 1

#--------------------------------------------------------------------------

# ◠セットアップ

# map_id : マップ ID

#--------------------------------------------------------------------------

alias saba_setup setup

def setup(map_id)

saba_setup(map_id)

@random_dungeon = nil

make_random_dungeon if dungeon?

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンを作æˆ

#--------------------------------------------------------------------------

def make_random_dungeon

@rect_list = []

@room_list = []

@couple_list = []

@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))

@floor_chip_id = @map.data[0, 0, 0]

@floor_chip_id1 = @map.data[1, 0, 0]

@edge_chip_id = @map.data[0, 1, 0]

@wall_chip_id = @map.data[0, 2, 0]

@blank_chip_id = @map.data[0, 4, 0]

@object_chip_id0 = @map.data[0, 3, 0]

@object_chip_id1 = @map.data[0, 3, 1]

@object_chip_id2 = @map.data[0, 3, 2]

make_rect

make_room

make_couple_more

 

@init_phase = true

 

put_blank_tiles

put_couple_tiles

put_room_tiles

put_shadow

put_wall_tiles

put_edge_tiles

 

if @map_infos[@map_id].name =~ /.*\(([0-9\.+]*),\s*([0-9\.+]*)\)/

@dungeon_base_level = $1.to_i

@floor_level_rate = Float ($2)

puts("Dungeon level set to "+$1+" with a floor multiplier of "+$2+".")

else

@dungeon_base_level = $game_party.average_level

@floor_level_rate = 0.1

end

setup_dungeon_events

@random_data = @map.data

@last_moving = false

 

end

#--------------------------------------------------------------------------

# ◠区切りを作æˆ

#--------------------------------------------------------------------------

def make_rect

split_rect(add_rect(0, 1, @map.width, @map.height))

end

#--------------------------------------------------------------------------

# ◠指定㮠DungeonRect を区切る

#--------------------------------------------------------------------------

def split_rect(parent)

if (parent.hy - parent.ly <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_v = true

end

if (parent.hx - parent.lx <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_h = true;

end

if ((parent.done_split_v) && (parent.done_split_h))

return

end

child = add_rect(parent.lx, parent.ly, parent.hx, parent.hy)

unless parent.done_split_v

split_coord_y = random_range(parent.ly + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hy - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hy = split_coord_y

child.ly = split_coord_y

parent.done_split_v = true

child.done_split_v = true

add_couple(COUPLE_VERTICAL, parent, child)

split_rect(parent)

split_rect(child)

else

split_coord_x = random_range(parent.lx + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hx - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hx = split_coord_x

child.lx = split_coord_x

parent.done_split_h = true

child.done_split_h = true

add_couple(COUPLE_HORIZONAL, parent, child)

split_rect(parent)

split_rect(child)

end

end

#--------------------------------------------------------------------------

# â— ã•ã‚‰ã«é“を作æˆ

#--------------------------------------------------------------------------

def make_couple_more

rectmap = {}

for rect in @rect_list

for i in rect.lx...rect.hx

for j in rect.ly...rect.hy

rectmap[[i, j]] = rect

end

end

end

 

for i in 0..(@map.width-2)

for j in 1..(@map.height-2)

if rectmap[[i, j]] != rectmap[[i, j + 1]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_VERTICAL, rectmap[[i,j]], rectmap[[i, j + 1]])

end

end

if rectmap[[i, j]] != rectmap[[i + 1, j]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_HORIZONAL, rectmap[[i, j]], rectmap[[i + 1, j]])

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンã‹ï¼Ÿ

#--------------------------------------------------------------------------

def dungeon?

if @random_dungeon != nil

return @random_dungeon

end

unless @map_infos

@map_infos = load_data("Data/MapInfos.rvdata2")

end

@random_dungeon = @map_infos[@map_id].name.include?("@")

return @random_dungeon

end

#--------------------------------------------------------------------------

# ◠指定ã®åŒºé–“ã®ä¸­ã§ãƒ©ãƒ³ãƒ€ãƒ ãªå€¤ã‚’å–å¾—

#--------------------------------------------------------------------------

def random_range(b, e)

return (rand(e - B) + B).to_i

end

#--------------------------------------------------------------------------

# â— DungeonRect を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_rect(lx, ly, hx, hy)

rect = Dungeon_Rect.new(lx, ly, hx, hy)

@rect_list.push(rect)

return rect

end

#--------------------------------------------------------------------------

# â— Room を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_room(lx, ly, hx, hy)

room = Room.new(lx, ly, hx, hy)

@room_list.push(room)

return room

end

#--------------------------------------------------------------------------

# ◠部屋を作æˆ

#--------------------------------------------------------------------------

def make_room

for rect in @rect_list

w = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hx - rect.lx - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

h = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hy - rect.ly - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

x = random_range(rect.lx + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hx - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - w + 1);

y = random_range(rect.ly + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hy - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - h + 1);

rect.room = add_room(x, y, x + w, y + h);

end

end

#--------------------------------------------------------------------------

# ◠通路 を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_couple(direction, rect0, rect1)

@couple_list.each {|c|

if (c.rect0 == rect0 && c.rect1 == rect1) ||

(c.rect0 == rect1 && c.rect1 == rect0)

# é‡è¤‡ã¯ã¤ãらãªã„

return

end

}

couple = Couple.new

couple.direction = direction

couple.rect0 = rect0

couple.rect1 = rect1

@couple_list.push(couple)

return couple

end

#--------------------------------------------------------------------------

# ◠空ããƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_blank_tiles

for x in 0..@map.width

for y in 0..@map.height

@map.data[x, y, 0] = @blank_chip_id

@map.data[x, y, 1] = 0

@map.data[x, y, 2] = 0

end

end

end

#--------------------------------------------------------------------------

# ◠床ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_room_tiles

for rect in @rect_list

room = rect.room

(room.hx - room.lx).times do |x|

(room.hy - room.ly).times do |y|

put_floor_tile(x + room.lx, y + room.ly)

end

end

end

end

def put_floor_tile(x, y)

if @floor_chip_id1 > 0 && rand(10) == 0

@map.data[x, y, 0] = @floor_chip_id1

else

@map.data[x, y, 0] = @floor_chip_id

end

end

#--------------------------------------------------------------------------

# ◠通路ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_couple_tiles

for couple in @couple_list

case couple.direction

when COUPLE_HORIZONAL then

unless couple.rect0.hx == couple.rect1.lx

p "Errorx:" + couple.rect0.hx.to_s + couple.rect1.lx .to_s

next

end

c0x = couple.rect0.hx

c0y = random_range(couple.rect0.room.ly + 1, couple.rect0.room.hy)

c1x = couple.rect1.lx

c1y = random_range(couple.rect1.room.ly + 1, couple.rect1.room.hy)

line(c0x, c0y, c1x, c1y);

line(couple.rect0.room.hx, c0y, c0x, c0y)

line(couple.rect1.room.lx, c1y, c1x, c1y)

couple.rect0.room.couple_areas.push([couple.rect0.room.hx-1, c0y])

couple.rect1.room.couple_areas.push([couple.rect1.room.lx, c1y])

when COUPLE_VERTICAL then

unless couple.rect0.hy == couple.rect1.ly

p "Errory:" + couple.rect0.hy.to_s + " " + couple.rect1.ly .to_s

next

end

c0x = random_range(couple.rect0.room.lx + 1, couple.rect0.room.hx)

c0y = couple.rect0.hy

c1x = random_range(couple.rect1.room.lx + 1, couple.rect1.room.hx)

c1y = couple.rect1.ly

line(c0x, c0y, c1x, c1y)

line(c0x, couple.rect0.room.hy, c0x, c0y)

line(c1x, couple.rect1.room.ly, c1x, c1y)

couple.rect0.room.couple_areas.push([c0x, couple.rect0.room.hy-1])

couple.rect1.room.couple_areas.push([c1x, couple.rect1.room.ly])

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™é–“ã§åºŠã‚’é…ç½®

#--------------------------------------------------------------------------

def line(x0, y0, x1, y1)

min_x = [x0, x1].min

max_x = [x0, x1].max

min_y = [y0, y1].min

max_y = [y0, y1].max

if ((x0 <= x1) && (y0 >= y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 > y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 <= y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 <= x1) && (y0 < y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(min_x, j)

end

end

end

#--------------------------------------------------------------------------

# â— å£ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_wall_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x, y-1)

@map.data[x, y-1, 0] = @wall_chip_id + 15

end

end

 

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next unless tile == @wall_chip_id + 15

if floor?(x, y-1)

put_object_tile(x, y)

next

end

if floor?(x-1, y) || blank?(x-1, y)

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 15

else

@map.data[x, y, 0] = @wall_chip_id + 11

end

else

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 14

else

@map.data[x, y, 0] = @wall_chip_id + 10

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠障害物ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_object_tile(x, y)

@map.data[x, y, 0] = @object_chip_id0

@map.data[x, y, 1] = @object_chip_id1

@map.data[x, y, 2] = @object_chip_id2

end

#--------------------------------------------------------------------------

# ◠境界ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_edge_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next if inner?(x, y)

if inner?(x, y-1)

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 46

else

@map.data[x, y, 0] = @edge_chip_id + 43

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 45

else

@map.data[x, y, 0] = @edge_chip_id + 33

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 42

else

@map.data[x, y, 0] = @edge_chip_id + 34

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 36

else

@map.data[x, y, 0] = @edge_chip_id + 20

end

end

end

else

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 44

else

@map.data[x, y, 0] = @edge_chip_id + 40

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 38

else

@map.data[x, y, 0] = @edge_chip_id + 28

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 32

else

@map.data[x, y, 0] = @edge_chip_id + 16

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 24

else

if inner?(x+1, y+1) || inner?(x+1, y-1) ||

inner?(x-1, y-1) || inner?(x-1, y+1)

@map.data[x, y, 0] = @edge_chip_id

else

@map.data[x, y, 0] = @blank_chip_id

end

end

end

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠影タイルを置ãã¾ã™

#--------------------------------------------------------------------------

def put_shadow

for y in 0..@map.height

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x-1, y-1)

next unless blank?(x-1, y)

@map.data[x, y, 3] = 5

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå¢ƒç•Œã®å†…å´ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def inner?(x, y)

return floor?(x, y) || wall?(x, y) || object?(x, y)

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒåºŠã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def floor?(x, y)

return false if @map.data[x, y, 2] == @object_chip_id2

return true if @floor_chip_id1 && @map.data[x, y, 0] == @floor_chip_id1

return @map.data[x, y, 0] == @floor_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒã‚«ãƒ©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def blank?(x, y)

return @map.data[x, y, 0] == @blank_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒéšœå®³ç‰©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def object?(x, y)

return @map.data[x, y, 0] == @object_chip_id0

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå£ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def wall?(x, y)

tile = @map.data[x, y, 0]

return false if tile == nil || tile == 0

return tile >= @wall_chip_id && tile <= @wall_chip_id + 15

end

 

end

 

 

Entity placement part:

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

Edited by KilloZapit

Share this post


Link to post
Share on other sites

I have been working with Saba Kan's script a lot my self, and I think I might be able to help you get rid of the parts you don't want. Actually removing the mini map script is fairly simple if I remember correctly... there are just a few things that are inexplicably defined in the mini map script that should be done in the main script. I also got rid of the light script and turn-based movement script so I could replace it with my own (one that uses "Khas Awesome Light Effects" no less). Anyway, try these scripts:

 

Dungeon generation part:

 

#==============================================================================

# - Dungeon Creation 6 KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# To many changes to really list, lots of little things.

#==============================================================================

module Saba

module Dungeon

# Minumum block size (Hard to explain, try it out yourself)

# Default: 7

MINIMUM_RECT_SIZE = 5

 

# Minimum room size.

# Default: 3

MINIMUM_ROOM_SIZE = 3

 

# Margin between rooms and 'blocks'.

# Default: 2

MARGIN_BETWEEN_RECT_ROOM = 2

 

# The percentage of corridors made. (1/n)

# Works best with lower values.

# Default: 35

MORE_COUPLE_RATE = 35

 

# Variable that stores enemy amount.

ENEMY_COUNT_VARIABLE = 3

end

end

 

#=========================================================================

# Do not edit anything under this line unless you know what you're doing!

#=========================================================================

 

#==============================================================================

# â–  Dungeon_Rect

#------------------------------------------------------------------------------

#  ダンジョンを区切ã£ãŸé ˜åŸŸã‚’表ã—ã¾ã™ã€‚

#ã€€å„ Dungeon_Rect ã«ä¸€ã¤ã¥ã¤ Room ãŒå­˜åœ¨ã—ã¾ã™ã€‚

#==============================================================================

class Dungeon_Rect

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :room

attr_accessor :done_split_v

attr_accessor :done_split_h

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

self.done_split_v = false

self.done_split_h = false

end

end

 

#==============================================================================

# â–  Room

#------------------------------------------------------------------------------

#  部屋ã§ã™ã€‚

#==============================================================================

class Room

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :mapping

attr_reader :width

attr_reader :height

attr_reader :couple_areas # 通路ã«é¢ã—ã¦ã„ã‚‹[x, y]ã®ãƒªã‚¹ãƒˆ

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

@width = hx - lx

@height = hy - ly

@events = {}

@couple_areas = []

@mapping = false

end

 

#--------------------------------------------------------------------------

# ◠イベントé…ç½®å¯èƒ½æ•°æ®‹ã‚Šã‚’å–å¾—

#--------------------------------------------------------------------------

def remain

return (hx - lx) * (hy - ly) - @events.size - @couple_areas.size

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’å«ã‚“ã§ã„ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def contains(x, y)

return lx <= x && x < hx && ly <= y && y < hy

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’明るãã™ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def right_area?(x, y)

return lx-1 <= x && x < hx+1 && ly-1 <= y && y < hy+1

end

end

 

#==============================================================================

# â–  Couple

#------------------------------------------------------------------------------

#  通路ã§ã™ã€‚

#==============================================================================

class Couple

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :rect0

attr_accessor :rect1

attr_accessor :direction

end

 

class Game_Map

attr_reader :map

attr_reader :dungeon_base_level

attr_reader :floor_level_rate

#--------------------------------------------------------------------------

# ◠定数

#--------------------------------------------------------------------------

COUPLE_VERTICAL = 0

COUPLE_HORIZONAL = 1

#--------------------------------------------------------------------------

# ◠セットアップ

# map_id : マップ ID

#--------------------------------------------------------------------------

alias saba_setup setup

def setup(map_id)

saba_setup(map_id)

@random_dungeon = nil

make_random_dungeon if dungeon?

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンを作æˆ

#--------------------------------------------------------------------------

def make_random_dungeon

@rect_list = []

@room_list = []

@couple_list = []

@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))

@floor_chip_id = @map.data[0, 0, 0]

@floor_chip_id1 = @map.data[1, 0, 0]

@edge_chip_id = @map.data[0, 1, 0]

@wall_chip_id = @map.data[0, 2, 0]

@blank_chip_id = @map.data[0, 4, 0]

@object_chip_id0 = @map.data[0, 3, 0]

@object_chip_id1 = @map.data[0, 3, 1]

@object_chip_id2 = @map.data[0, 3, 2]

make_rect

make_room

make_couple_more

 

@init_phase = true

 

put_blank_tiles

put_couple_tiles

put_room_tiles

put_shadow

put_wall_tiles

put_edge_tiles

 

if @map_infos[@map_id].name =~ /.*\(([0-9\.+]*),\s*([0-9\.+]*)\)/

@dungeon_base_level = $1.to_i

@floor_level_rate = Float ($2)

puts("Dungeon level set to "+$1+" with a floor multiplier of "+$2+".")

else

@dungeon_base_level = $game_party.average_level

@floor_level_rate = 0.1

end

setup_dungeon_events

@random_data = @map.data

@last_moving = false

 

end

#--------------------------------------------------------------------------

# ◠区切りを作æˆ

#--------------------------------------------------------------------------

def make_rect

split_rect(add_rect(0, 1, @map.width, @map.height))

end

#--------------------------------------------------------------------------

# ◠指定㮠DungeonRect を区切る

#--------------------------------------------------------------------------

def split_rect(parent)

if (parent.hy - parent.ly <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_v = true

end

if (parent.hx - parent.lx <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_h = true;

end

if ((parent.done_split_v) && (parent.done_split_h))

return

end

child = add_rect(parent.lx, parent.ly, parent.hx, parent.hy)

unless parent.done_split_v

split_coord_y = random_range(parent.ly + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hy - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hy = split_coord_y

child.ly = split_coord_y

parent.done_split_v = true

child.done_split_v = true

add_couple(COUPLE_VERTICAL, parent, child)

split_rect(parent)

split_rect(child)

else

split_coord_x = random_range(parent.lx + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hx - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hx = split_coord_x

child.lx = split_coord_x

parent.done_split_h = true

child.done_split_h = true

add_couple(COUPLE_HORIZONAL, parent, child)

split_rect(parent)

split_rect(child)

end

end

#--------------------------------------------------------------------------

# â— ã•ã‚‰ã«é“を作æˆ

#--------------------------------------------------------------------------

def make_couple_more

rectmap = {}

for rect in @rect_list

for i in rect.lx...rect.hx

for j in rect.ly...rect.hy

rectmap[[i, j]] = rect

end

end

end

 

for i in 0..(@map.width-2)

for j in 1..(@map.height-2)

if rectmap[[i, j]] != rectmap[[i, j + 1]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_VERTICAL, rectmap[[i,j]], rectmap[[i, j + 1]])

end

end

if rectmap[[i, j]] != rectmap[[i + 1, j]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_HORIZONAL, rectmap[[i, j]], rectmap[[i + 1, j]])

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンã‹ï¼Ÿ

#--------------------------------------------------------------------------

def dungeon?

if @random_dungeon != nil

return @random_dungeon

end

unless @map_infos

@map_infos = load_data("Data/MapInfos.rvdata2")

end

@random_dungeon = @map_infos[@map_id].name.include?("@")

return @random_dungeon

end

#--------------------------------------------------------------------------

# ◠指定ã®åŒºé–“ã®ä¸­ã§ãƒ©ãƒ³ãƒ€ãƒ ãªå€¤ã‚’å–å¾—

#--------------------------------------------------------------------------

def random_range(b, e)

return (rand(e - B) + B).to_i

end

#--------------------------------------------------------------------------

# â— DungeonRect を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_rect(lx, ly, hx, hy)

rect = Dungeon_Rect.new(lx, ly, hx, hy)

@rect_list.push(rect)

return rect

end

#--------------------------------------------------------------------------

# â— Room を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_room(lx, ly, hx, hy)

room = Room.new(lx, ly, hx, hy)

@room_list.push(room)

return room

end

#--------------------------------------------------------------------------

# ◠部屋を作æˆ

#--------------------------------------------------------------------------

def make_room

for rect in @rect_list

w = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hx - rect.lx - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

h = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hy - rect.ly - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

x = random_range(rect.lx + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hx - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - w + 1);

y = random_range(rect.ly + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hy - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - h + 1);

rect.room = add_room(x, y, x + w, y + h);

end

end

#--------------------------------------------------------------------------

# ◠通路 を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_couple(direction, rect0, rect1)

@couple_list.each {|c|

if (c.rect0 == rect0 && c.rect1 == rect1) ||

(c.rect0 == rect1 && c.rect1 == rect0)

# é‡è¤‡ã¯ã¤ãらãªã„

return

end

}

couple = Couple.new

couple.direction = direction

couple.rect0 = rect0

couple.rect1 = rect1

@couple_list.push(couple)

return couple

end

#--------------------------------------------------------------------------

# ◠空ããƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_blank_tiles

for x in 0..@map.width

for y in 0..@map.height

@map.data[x, y, 0] = @blank_chip_id

@map.data[x, y, 1] = 0

@map.data[x, y, 2] = 0

end

end

end

#--------------------------------------------------------------------------

# ◠床ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_room_tiles

for rect in @rect_list

room = rect.room

(room.hx - room.lx).times do |x|

(room.hy - room.ly).times do |y|

put_floor_tile(x + room.lx, y + room.ly)

end

end

end

end

def put_floor_tile(x, y)

if @floor_chip_id1 > 0 && rand(10) == 0

@map.data[x, y, 0] = @floor_chip_id1

else

@map.data[x, y, 0] = @floor_chip_id

end

end

#--------------------------------------------------------------------------

# ◠通路ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_couple_tiles

for couple in @couple_list

case couple.direction

when COUPLE_HORIZONAL then

unless couple.rect0.hx == couple.rect1.lx

p "Errorx:" + couple.rect0.hx.to_s + couple.rect1.lx .to_s

next

end

c0x = couple.rect0.hx

c0y = random_range(couple.rect0.room.ly + 1, couple.rect0.room.hy)

c1x = couple.rect1.lx

c1y = random_range(couple.rect1.room.ly + 1, couple.rect1.room.hy)

line(c0x, c0y, c1x, c1y);

line(couple.rect0.room.hx, c0y, c0x, c0y)

line(couple.rect1.room.lx, c1y, c1x, c1y)

couple.rect0.room.couple_areas.push([couple.rect0.room.hx-1, c0y])

couple.rect1.room.couple_areas.push([couple.rect1.room.lx, c1y])

when COUPLE_VERTICAL then

unless couple.rect0.hy == couple.rect1.ly

p "Errory:" + couple.rect0.hy.to_s + " " + couple.rect1.ly .to_s

next

end

c0x = random_range(couple.rect0.room.lx + 1, couple.rect0.room.hx)

c0y = couple.rect0.hy

c1x = random_range(couple.rect1.room.lx + 1, couple.rect1.room.hx)

c1y = couple.rect1.ly

line(c0x, c0y, c1x, c1y)

line(c0x, couple.rect0.room.hy, c0x, c0y)

line(c1x, couple.rect1.room.ly, c1x, c1y)

couple.rect0.room.couple_areas.push([c0x, couple.rect0.room.hy-1])

couple.rect1.room.couple_areas.push([c1x, couple.rect1.room.ly])

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™é–“ã§åºŠã‚’é…ç½®

#--------------------------------------------------------------------------

def line(x0, y0, x1, y1)

min_x = [x0, x1].min

max_x = [x0, x1].max

min_y = [y0, y1].min

max_y = [y0, y1].max

if ((x0 <= x1) && (y0 >= y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 > y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 <= y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 <= x1) && (y0 < y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(min_x, j)

end

end

end

#--------------------------------------------------------------------------

# â— å£ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_wall_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x, y-1)

@map.data[x, y-1, 0] = @wall_chip_id + 15

end

end

 

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next unless tile == @wall_chip_id + 15

if floor?(x, y-1)

put_object_tile(x, y)

next

end

if floor?(x-1, y) || blank?(x-1, y)

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 15

else

@map.data[x, y, 0] = @wall_chip_id + 11

end

else

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 14

else

@map.data[x, y, 0] = @wall_chip_id + 10

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠障害物ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_object_tile(x, y)

@map.data[x, y, 0] = @object_chip_id0

@map.data[x, y, 1] = @object_chip_id1

@map.data[x, y, 2] = @object_chip_id2

end

#--------------------------------------------------------------------------

# ◠境界ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_edge_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next if inner?(x, y)

if inner?(x, y-1)

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 46

else

@map.data[x, y, 0] = @edge_chip_id + 43

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 45

else

@map.data[x, y, 0] = @edge_chip_id + 33

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 42

else

@map.data[x, y, 0] = @edge_chip_id + 34

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 36

else

@map.data[x, y, 0] = @edge_chip_id + 20

end

end

end

else

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 44

else

@map.data[x, y, 0] = @edge_chip_id + 40

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 38

else

@map.data[x, y, 0] = @edge_chip_id + 28

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 32

else

@map.data[x, y, 0] = @edge_chip_id + 16

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 24

else

if inner?(x+1, y+1) || inner?(x+1, y-1) ||

inner?(x-1, y-1) || inner?(x-1, y+1)

@map.data[x, y, 0] = @edge_chip_id

else

@map.data[x, y, 0] = @blank_chip_id

end

end

end

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠影タイルを置ãã¾ã™

#--------------------------------------------------------------------------

def put_shadow

for y in 0..@map.height

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x-1, y-1)

next unless blank?(x-1, y)

@map.data[x, y, 3] = 5

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå¢ƒç•Œã®å†…å´ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def inner?(x, y)

return floor?(x, y) || wall?(x, y) || object?(x, y)

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒåºŠã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def floor?(x, y)

return false if @map.data[x, y, 2] == @object_chip_id2

return true if @floor_chip_id1 && @map.data[x, y, 0] == @floor_chip_id1

return @map.data[x, y, 0] == @floor_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒã‚«ãƒ©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def blank?(x, y)

return @map.data[x, y, 0] == @blank_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒéšœå®³ç‰©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def object?(x, y)

return @map.data[x, y, 0] == @object_chip_id0

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå£ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def wall?(x, y)

tile = @map.data[x, y, 0]

return false if tile == nil || tile == 0

return tile >= @wall_chip_id && tile <= @wall_chip_id + 15

end

 

end

 

 

Entity placement part:

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

I tried them but got this error;

Share this post


Link to post
Share on other sites

The heck? I think it might have auto-converted some emoticon bugs when I posted it. It surly isn't that way in my version. I had that happen before too. Just need to add another space.

 

try this:

 

Dungeon generation part:

 

#==============================================================================

# - Dungeon Creation 6 KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# To many changes to really list, lots of little things.

#==============================================================================

module Saba

module Dungeon

# Minumum block size (Hard to explain, try it out yourself)

# Default: 7

MINIMUM_RECT_SIZE = 5

 

# Minimum room size.

# Default: 3

MINIMUM_ROOM_SIZE = 3

 

# Margin between rooms and 'blocks'.

# Default: 2

MARGIN_BETWEEN_RECT_ROOM = 2

 

# The percentage of corridors made. (1/n)

# Works best with lower values.

# Default: 35

MORE_COUPLE_RATE = 35

 

# Variable that stores enemy amount.

ENEMY_COUNT_VARIABLE = 3

end

end

 

#=========================================================================

# Do not edit anything under this line unless you know what you're doing!

#=========================================================================

 

#==============================================================================

# â–  Dungeon_Rect

#------------------------------------------------------------------------------

#  ダンジョンを区切ã£ãŸé ˜åŸŸã‚’表ã—ã¾ã™ã€‚

#ã€€å„ Dungeon_Rect ã«ä¸€ã¤ã¥ã¤ Room ãŒå­˜åœ¨ã—ã¾ã™ã€‚

#==============================================================================

class Dungeon_Rect

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :room

attr_accessor :done_split_v

attr_accessor :done_split_h

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

self.done_split_v = false

self.done_split_h = false

end

end

 

#==============================================================================

# â–  Room

#------------------------------------------------------------------------------

#  部屋ã§ã™ã€‚

#==============================================================================

class Room

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :mapping

attr_reader :width

attr_reader :height

attr_reader :couple_areas # 通路ã«é¢ã—ã¦ã„ã‚‹[x, y]ã®ãƒªã‚¹ãƒˆ

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

@width = hx - lx

@height = hy - ly

@events = {}

@couple_areas = []

@mapping = false

end

 

#--------------------------------------------------------------------------

# ◠イベントé…ç½®å¯èƒ½æ•°æ®‹ã‚Šã‚’å–å¾—

#--------------------------------------------------------------------------

def remain

return (hx - lx) * (hy - ly) - @events.size - @couple_areas.size

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’å«ã‚“ã§ã„ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def contains(x, y)

return lx <= x && x < hx && ly <= y && y < hy

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’明るãã™ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def right_area?(x, y)

return lx-1 <= x && x < hx+1 && ly-1 <= y && y < hy+1

end

end

 

#==============================================================================

# â–  Couple

#------------------------------------------------------------------------------

#  通路ã§ã™ã€‚

#==============================================================================

class Couple

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :rect0

attr_accessor :rect1

attr_accessor :direction

end

 

class Game_Map

attr_reader :map

attr_reader :dungeon_base_level

attr_reader :floor_level_rate

#--------------------------------------------------------------------------

# ◠定数

#--------------------------------------------------------------------------

COUPLE_VERTICAL = 0

COUPLE_HORIZONAL = 1

#--------------------------------------------------------------------------

# ◠セットアップ

# map_id : マップ ID

#--------------------------------------------------------------------------

alias saba_setup setup

def setup(map_id)

saba_setup(map_id)

@random_dungeon = nil

make_random_dungeon if dungeon?

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンを作æˆ

#--------------------------------------------------------------------------

def make_random_dungeon

@rect_list = []

@room_list = []

@couple_list = []

@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))

@floor_chip_id = @map.data[0, 0, 0]

@floor_chip_id1 = @map.data[1, 0, 0]

@edge_chip_id = @map.data[0, 1, 0]

@wall_chip_id = @map.data[0, 2, 0]

@blank_chip_id = @map.data[0, 4, 0]

@object_chip_id0 = @map.data[0, 3, 0]

@object_chip_id1 = @map.data[0, 3, 1]

@object_chip_id2 = @map.data[0, 3, 2]

make_rect

make_room

make_couple_more

 

@init_phase = true

 

put_blank_tiles

put_couple_tiles

put_room_tiles

put_shadow

put_wall_tiles

put_edge_tiles

 

if @map_infos[@map_id].name =~ /.*\(([0-9\.+]*),\s*([0-9\.+]*)\)/

@dungeon_base_level = $1.to_i

@floor_level_rate = Float ($2)

puts("Dungeon level set to "+$1+" with a floor multiplier of "+$2+".")

else

@dungeon_base_level = $game_party.average_level

@floor_level_rate = 0.1

end

setup_dungeon_events

@random_data = @map.data

@last_moving = false

 

end

#--------------------------------------------------------------------------

# ◠区切りを作æˆ

#--------------------------------------------------------------------------

def make_rect

split_rect(add_rect(0, 1, @map.width, @map.height))

end

#--------------------------------------------------------------------------

# ◠指定㮠DungeonRect を区切る

#--------------------------------------------------------------------------

def split_rect(parent)

if (parent.hy - parent.ly <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_v = true

end

if (parent.hx - parent.lx <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_h = true;

end

if ((parent.done_split_v) && (parent.done_split_h))

return

end

child = add_rect(parent.lx, parent.ly, parent.hx, parent.hy)

unless parent.done_split_v

split_coord_y = random_range(parent.ly + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hy - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hy = split_coord_y

child.ly = split_coord_y

parent.done_split_v = true

child.done_split_v = true

add_couple(COUPLE_VERTICAL, parent, child)

split_rect(parent)

split_rect(child)

else

split_coord_x = random_range(parent.lx + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hx - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hx = split_coord_x

child.lx = split_coord_x

parent.done_split_h = true

child.done_split_h = true

add_couple(COUPLE_HORIZONAL, parent, child)

split_rect(parent)

split_rect(child)

end

end

#--------------------------------------------------------------------------

# â— ã•ã‚‰ã«é“を作æˆ

#--------------------------------------------------------------------------

def make_couple_more

rectmap = {}

for rect in @rect_list

for i in rect.lx...rect.hx

for j in rect.ly...rect.hy

rectmap[[i, j]] = rect

end

end

end

 

for i in 0..(@map.width-2)

for j in 1..(@map.height-2)

if rectmap[[i, j]] != rectmap[[i, j + 1]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_VERTICAL, rectmap[[i,j]], rectmap[[i, j + 1]])

end

end

if rectmap[[i, j]] != rectmap[[i + 1, j]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_HORIZONAL, rectmap[[i, j]], rectmap[[i + 1, j]])

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンã‹ï¼Ÿ

#--------------------------------------------------------------------------

def dungeon?

if @random_dungeon != nil

return @random_dungeon

end

unless @map_infos

@map_infos = load_data("Data/MapInfos.rvdata2")

end

@random_dungeon = @map_infos[@map_id].name.include?("@")

return @random_dungeon

end

#--------------------------------------------------------------------------

# ◠指定ã®åŒºé–“ã®ä¸­ã§ãƒ©ãƒ³ãƒ€ãƒ ãªå€¤ã‚’å–å¾—

#--------------------------------------------------------------------------

def random_range(b, e)

return (rand(e - b ) + b ).to_i

end

#--------------------------------------------------------------------------

# â— DungeonRect を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_rect(lx, ly, hx, hy)

rect = Dungeon_Rect.new(lx, ly, hx, hy)

@rect_list.push(rect)

return rect

end

#--------------------------------------------------------------------------

# â— Room を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_room(lx, ly, hx, hy)

room = Room.new(lx, ly, hx, hy)

@room_list.push(room)

return room

end

#--------------------------------------------------------------------------

# ◠部屋を作æˆ

#--------------------------------------------------------------------------

def make_room

for rect in @rect_list

w = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hx - rect.lx - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

h = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hy - rect.ly - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

x = random_range(rect.lx + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hx - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - w + 1);

y = random_range(rect.ly + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hy - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - h + 1);

rect.room = add_room(x, y, x + w, y + h);

end

end

#--------------------------------------------------------------------------

# ◠通路 を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_couple(direction, rect0, rect1)

@couple_list.each {|c|

if (c.rect0 == rect0 && c.rect1 == rect1) ||

(c.rect0 == rect1 && c.rect1 == rect0)

# é‡è¤‡ã¯ã¤ãらãªã„

return

end

}

couple = Couple.new

couple.direction = direction

couple.rect0 = rect0

couple.rect1 = rect1

@couple_list.push(couple)

return couple

end

#--------------------------------------------------------------------------

# ◠空ããƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_blank_tiles

for x in 0..@map.width

for y in 0..@map.height

@map.data[x, y, 0] = @blank_chip_id

@map.data[x, y, 1] = 0

@map.data[x, y, 2] = 0

end

end

end

#--------------------------------------------------------------------------

# ◠床ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_room_tiles

for rect in @rect_list

room = rect.room

(room.hx - room.lx).times do |x|

(room.hy - room.ly).times do |y|

put_floor_tile(x + room.lx, y + room.ly)

end

end

end

end

def put_floor_tile(x, y)

if @floor_chip_id1 > 0 && rand(10) == 0

@map.data[x, y, 0] = @floor_chip_id1

else

@map.data[x, y, 0] = @floor_chip_id

end

end

#--------------------------------------------------------------------------

# ◠通路ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_couple_tiles

for couple in @couple_list

case couple.direction

when COUPLE_HORIZONAL then

unless couple.rect0.hx == couple.rect1.lx

p "Errorx:" + couple.rect0.hx.to_s + couple.rect1.lx .to_s

next

end

c0x = couple.rect0.hx

c0y = random_range(couple.rect0.room.ly + 1, couple.rect0.room.hy)

c1x = couple.rect1.lx

c1y = random_range(couple.rect1.room.ly + 1, couple.rect1.room.hy)

line(c0x, c0y, c1x, c1y);

line(couple.rect0.room.hx, c0y, c0x, c0y)

line(couple.rect1.room.lx, c1y, c1x, c1y)

couple.rect0.room.couple_areas.push([couple.rect0.room.hx-1, c0y])

couple.rect1.room.couple_areas.push([couple.rect1.room.lx, c1y])

when COUPLE_VERTICAL then

unless couple.rect0.hy == couple.rect1.ly

p "Errory:" + couple.rect0.hy.to_s + " " + couple.rect1.ly .to_s

next

end

c0x = random_range(couple.rect0.room.lx + 1, couple.rect0.room.hx)

c0y = couple.rect0.hy

c1x = random_range(couple.rect1.room.lx + 1, couple.rect1.room.hx)

c1y = couple.rect1.ly

line(c0x, c0y, c1x, c1y)

line(c0x, couple.rect0.room.hy, c0x, c0y)

line(c1x, couple.rect1.room.ly, c1x, c1y)

couple.rect0.room.couple_areas.push([c0x, couple.rect0.room.hy-1])

couple.rect1.room.couple_areas.push([c1x, couple.rect1.room.ly])

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™é–“ã§åºŠã‚’é…ç½®

#--------------------------------------------------------------------------

def line(x0, y0, x1, y1)

min_x = [x0, x1].min

max_x = [x0, x1].max

min_y = [y0, y1].min

max_y = [y0, y1].max

if ((x0 <= x1) && (y0 >= y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 > y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 <= y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 <= x1) && (y0 < y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(min_x, j)

end

end

end

#--------------------------------------------------------------------------

# â— å£ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_wall_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x, y-1)

@map.data[x, y-1, 0] = @wall_chip_id + 15

end

end

 

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next unless tile == @wall_chip_id + 15

if floor?(x, y-1)

put_object_tile(x, y)

next

end

if floor?(x-1, y) || blank?(x-1, y)

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 15

else

@map.data[x, y, 0] = @wall_chip_id + 11

end

else

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 14

else

@map.data[x, y, 0] = @wall_chip_id + 10

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠障害物ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_object_tile(x, y)

@map.data[x, y, 0] = @object_chip_id0

@map.data[x, y, 1] = @object_chip_id1

@map.data[x, y, 2] = @object_chip_id2

end

#--------------------------------------------------------------------------

# ◠境界ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_edge_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next if inner?(x, y)

if inner?(x, y-1)

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 46

else

@map.data[x, y, 0] = @edge_chip_id + 43

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 45

else

@map.data[x, y, 0] = @edge_chip_id + 33

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 42

else

@map.data[x, y, 0] = @edge_chip_id + 34

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 36

else

@map.data[x, y, 0] = @edge_chip_id + 20

end

end

end

else

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 44

else

@map.data[x, y, 0] = @edge_chip_id + 40

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 38

else

@map.data[x, y, 0] = @edge_chip_id + 28

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 32

else

@map.data[x, y, 0] = @edge_chip_id + 16

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 24

else

if inner?(x+1, y+1) || inner?(x+1, y-1) ||

inner?(x-1, y-1) || inner?(x-1, y+1)

@map.data[x, y, 0] = @edge_chip_id

else

@map.data[x, y, 0] = @blank_chip_id

end

end

end

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠影タイルを置ãã¾ã™

#--------------------------------------------------------------------------

def put_shadow

for y in 0..@map.height

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x-1, y-1)

next unless blank?(x-1, y)

@map.data[x, y, 3] = 5

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå¢ƒç•Œã®å†…å´ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def inner?(x, y)

return floor?(x, y) || wall?(x, y) || object?(x, y)

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒåºŠã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def floor?(x, y)

return false if @map.data[x, y, 2] == @object_chip_id2

return true if @floor_chip_id1 && @map.data[x, y, 0] == @floor_chip_id1

return @map.data[x, y, 0] == @floor_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒã‚«ãƒ©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def blank?(x, y)

return @map.data[x, y, 0] == @blank_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒéšœå®³ç‰©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def object?(x, y)

return @map.data[x, y, 0] == @object_chip_id0

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå£ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def wall?(x, y)

tile = @map.data[x, y, 0]

return false if tile == nil || tile == 0

return tile >= @wall_chip_id && tile <= @wall_chip_id + 15

end

 

end

 

Edited by KilloZapit

Share this post


Link to post
Share on other sites

The heck? I think it might have auto-converted some emoticon bugs when I posted it. It surly isn't that way in my version. I had that happen before too. Just need to add another space.

 

try this:

 

Dungeon generation part:

 

#==============================================================================

# - Dungeon Creation 6 KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# To many changes to really list, lots of little things.

#==============================================================================

module Saba

module Dungeon

# Minumum block size (Hard to explain, try it out yourself)

# Default: 7

MINIMUM_RECT_SIZE = 5

 

# Minimum room size.

# Default: 3

MINIMUM_ROOM_SIZE = 3

 

# Margin between rooms and 'blocks'.

# Default: 2

MARGIN_BETWEEN_RECT_ROOM = 2

 

# The percentage of corridors made. (1/n)

# Works best with lower values.

# Default: 35

MORE_COUPLE_RATE = 35

 

# Variable that stores enemy amount.

ENEMY_COUNT_VARIABLE = 3

end

end

 

#=========================================================================

# Do not edit anything under this line unless you know what you're doing!

#=========================================================================

 

#==============================================================================

# â–  Dungeon_Rect

#------------------------------------------------------------------------------

#  ダンジョンを区切ã£ãŸé ˜åŸŸã‚’表ã—ã¾ã™ã€‚

#ã€€å„ Dungeon_Rect ã«ä¸€ã¤ã¥ã¤ Room ãŒå­˜åœ¨ã—ã¾ã™ã€‚

#==============================================================================

class Dungeon_Rect

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :room

attr_accessor :done_split_v

attr_accessor :done_split_h

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

self.done_split_v = false

self.done_split_h = false

end

end

 

#==============================================================================

# â–  Room

#------------------------------------------------------------------------------

#  部屋ã§ã™ã€‚

#==============================================================================

class Room

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :mapping

attr_reader :width

attr_reader :height

attr_reader :couple_areas # 通路ã«é¢ã—ã¦ã„ã‚‹[x, y]ã®ãƒªã‚¹ãƒˆ

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

@width = hx - lx

@height = hy - ly

@events = {}

@couple_areas = []

@mapping = false

end

 

#--------------------------------------------------------------------------

# ◠イベントé…ç½®å¯èƒ½æ•°æ®‹ã‚Šã‚’å–å¾—

#--------------------------------------------------------------------------

def remain

return (hx - lx) * (hy - ly) - @events.size - @couple_areas.size

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’å«ã‚“ã§ã„ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def contains(x, y)

return lx <= x && x < hx && ly <= y && y < hy

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’明るãã™ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def right_area?(x, y)

return lx-1 <= x && x < hx+1 && ly-1 <= y && y < hy+1

end

end

 

#==============================================================================

# â–  Couple

#------------------------------------------------------------------------------

#  通路ã§ã™ã€‚

#==============================================================================

class Couple

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :rect0

attr_accessor :rect1

attr_accessor :direction

end

 

class Game_Map

attr_reader :map

attr_reader :dungeon_base_level

attr_reader :floor_level_rate

#--------------------------------------------------------------------------

# ◠定数

#--------------------------------------------------------------------------

COUPLE_VERTICAL = 0

COUPLE_HORIZONAL = 1

#--------------------------------------------------------------------------

# ◠セットアップ

# map_id : マップ ID

#--------------------------------------------------------------------------

alias saba_setup setup

def setup(map_id)

saba_setup(map_id)

@random_dungeon = nil

make_random_dungeon if dungeon?

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンを作æˆ

#--------------------------------------------------------------------------

def make_random_dungeon

@rect_list = []

@room_list = []

@couple_list = []

@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))

@floor_chip_id = @map.data[0, 0, 0]

@floor_chip_id1 = @map.data[1, 0, 0]

@edge_chip_id = @map.data[0, 1, 0]

@wall_chip_id = @map.data[0, 2, 0]

@blank_chip_id = @map.data[0, 4, 0]

@object_chip_id0 = @map.data[0, 3, 0]

@object_chip_id1 = @map.data[0, 3, 1]

@object_chip_id2 = @map.data[0, 3, 2]

make_rect

make_room

make_couple_more

 

@init_phase = true

 

put_blank_tiles

put_couple_tiles

put_room_tiles

put_shadow

put_wall_tiles

put_edge_tiles

 

if @map_infos[@map_id].name =~ /.*\(([0-9\.+]*),\s*([0-9\.+]*)\)/

@dungeon_base_level = $1.to_i

@floor_level_rate = Float ($2)

puts("Dungeon level set to "+$1+" with a floor multiplier of "+$2+".")

else

@dungeon_base_level = $game_party.average_level

@floor_level_rate = 0.1

end

setup_dungeon_events

@random_data = @map.data

@last_moving = false

 

end

#--------------------------------------------------------------------------

# ◠区切りを作æˆ

#--------------------------------------------------------------------------

def make_rect

split_rect(add_rect(0, 1, @map.width, @map.height))

end

#--------------------------------------------------------------------------

# ◠指定㮠DungeonRect を区切る

#--------------------------------------------------------------------------

def split_rect(parent)

if (parent.hy - parent.ly <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_v = true

end

if (parent.hx - parent.lx <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_h = true;

end

if ((parent.done_split_v) && (parent.done_split_h))

return

end

child = add_rect(parent.lx, parent.ly, parent.hx, parent.hy)

unless parent.done_split_v

split_coord_y = random_range(parent.ly + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hy - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hy = split_coord_y

child.ly = split_coord_y

parent.done_split_v = true

child.done_split_v = true

add_couple(COUPLE_VERTICAL, parent, child)

split_rect(parent)

split_rect(child)

else

split_coord_x = random_range(parent.lx + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hx - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hx = split_coord_x

child.lx = split_coord_x

parent.done_split_h = true

child.done_split_h = true

add_couple(COUPLE_HORIZONAL, parent, child)

split_rect(parent)

split_rect(child)

end

end

#--------------------------------------------------------------------------

# â— ã•ã‚‰ã«é“を作æˆ

#--------------------------------------------------------------------------

def make_couple_more

rectmap = {}

for rect in @rect_list

for i in rect.lx...rect.hx

for j in rect.ly...rect.hy

rectmap[[i, j]] = rect

end

end

end

 

for i in 0..(@map.width-2)

for j in 1..(@map.height-2)

if rectmap[[i, j]] != rectmap[[i, j + 1]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_VERTICAL, rectmap[[i,j]], rectmap[[i, j + 1]])

end

end

if rectmap[[i, j]] != rectmap[[i + 1, j]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_HORIZONAL, rectmap[[i, j]], rectmap[[i + 1, j]])

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンã‹ï¼Ÿ

#--------------------------------------------------------------------------

def dungeon?

if @random_dungeon != nil

return @random_dungeon

end

unless @map_infos

@map_infos = load_data("Data/MapInfos.rvdata2")

end

@random_dungeon = @map_infos[@map_id].name.include?("@")

return @random_dungeon

end

#--------------------------------------------------------------------------

# ◠指定ã®åŒºé–“ã®ä¸­ã§ãƒ©ãƒ³ãƒ€ãƒ ãªå€¤ã‚’å–å¾—

#--------------------------------------------------------------------------

def random_range(b, e)

return (rand(e - b ) + b ).to_i

end

#--------------------------------------------------------------------------

# â— DungeonRect を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_rect(lx, ly, hx, hy)

rect = Dungeon_Rect.new(lx, ly, hx, hy)

@rect_list.push(rect)

return rect

end

#--------------------------------------------------------------------------

# â— Room を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_room(lx, ly, hx, hy)

room = Room.new(lx, ly, hx, hy)

@room_list.push(room)

return room

end

#--------------------------------------------------------------------------

# ◠部屋を作æˆ

#--------------------------------------------------------------------------

def make_room

for rect in @rect_list

w = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hx - rect.lx - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

h = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hy - rect.ly - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

x = random_range(rect.lx + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hx - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - w + 1);

y = random_range(rect.ly + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hy - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - h + 1);

rect.room = add_room(x, y, x + w, y + h);

end

end

#--------------------------------------------------------------------------

# ◠通路 を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_couple(direction, rect0, rect1)

@couple_list.each {|c|

if (c.rect0 == rect0 && c.rect1 == rect1) ||

(c.rect0 == rect1 && c.rect1 == rect0)

# é‡è¤‡ã¯ã¤ãらãªã„

return

end

}

couple = Couple.new

couple.direction = direction

couple.rect0 = rect0

couple.rect1 = rect1

@couple_list.push(couple)

return couple

end

#--------------------------------------------------------------------------

# ◠空ããƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_blank_tiles

for x in 0..@map.width

for y in 0..@map.height

@map.data[x, y, 0] = @blank_chip_id

@map.data[x, y, 1] = 0

@map.data[x, y, 2] = 0

end

end

end

#--------------------------------------------------------------------------

# ◠床ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_room_tiles

for rect in @rect_list

room = rect.room

(room.hx - room.lx).times do |x|

(room.hy - room.ly).times do |y|

put_floor_tile(x + room.lx, y + room.ly)

end

end

end

end

def put_floor_tile(x, y)

if @floor_chip_id1 > 0 && rand(10) == 0

@map.data[x, y, 0] = @floor_chip_id1

else

@map.data[x, y, 0] = @floor_chip_id

end

end

#--------------------------------------------------------------------------

# ◠通路ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_couple_tiles

for couple in @couple_list

case couple.direction

when COUPLE_HORIZONAL then

unless couple.rect0.hx == couple.rect1.lx

p "Errorx:" + couple.rect0.hx.to_s + couple.rect1.lx .to_s

next

end

c0x = couple.rect0.hx

c0y = random_range(couple.rect0.room.ly + 1, couple.rect0.room.hy)

c1x = couple.rect1.lx

c1y = random_range(couple.rect1.room.ly + 1, couple.rect1.room.hy)

line(c0x, c0y, c1x, c1y);

line(couple.rect0.room.hx, c0y, c0x, c0y)

line(couple.rect1.room.lx, c1y, c1x, c1y)

couple.rect0.room.couple_areas.push([couple.rect0.room.hx-1, c0y])

couple.rect1.room.couple_areas.push([couple.rect1.room.lx, c1y])

when COUPLE_VERTICAL then

unless couple.rect0.hy == couple.rect1.ly

p "Errory:" + couple.rect0.hy.to_s + " " + couple.rect1.ly .to_s

next

end

c0x = random_range(couple.rect0.room.lx + 1, couple.rect0.room.hx)

c0y = couple.rect0.hy

c1x = random_range(couple.rect1.room.lx + 1, couple.rect1.room.hx)

c1y = couple.rect1.ly

line(c0x, c0y, c1x, c1y)

line(c0x, couple.rect0.room.hy, c0x, c0y)

line(c1x, couple.rect1.room.ly, c1x, c1y)

couple.rect0.room.couple_areas.push([c0x, couple.rect0.room.hy-1])

couple.rect1.room.couple_areas.push([c1x, couple.rect1.room.ly])

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™é–“ã§åºŠã‚’é…ç½®

#--------------------------------------------------------------------------

def line(x0, y0, x1, y1)

min_x = [x0, x1].min

max_x = [x0, x1].max

min_y = [y0, y1].min

max_y = [y0, y1].max

if ((x0 <= x1) && (y0 >= y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 > y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 <= y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 <= x1) && (y0 < y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(min_x, j)

end

end

end

#--------------------------------------------------------------------------

# â— å£ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_wall_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x, y-1)

@map.data[x, y-1, 0] = @wall_chip_id + 15

end

end

 

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next unless tile == @wall_chip_id + 15

if floor?(x, y-1)

put_object_tile(x, y)

next

end

if floor?(x-1, y) || blank?(x-1, y)

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 15

else

@map.data[x, y, 0] = @wall_chip_id + 11

end

else

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 14

else

@map.data[x, y, 0] = @wall_chip_id + 10

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠障害物ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_object_tile(x, y)

@map.data[x, y, 0] = @object_chip_id0

@map.data[x, y, 1] = @object_chip_id1

@map.data[x, y, 2] = @object_chip_id2

end

#--------------------------------------------------------------------------

# ◠境界ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_edge_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next if inner?(x, y)

if inner?(x, y-1)

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 46

else

@map.data[x, y, 0] = @edge_chip_id + 43

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 45

else

@map.data[x, y, 0] = @edge_chip_id + 33

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 42

else

@map.data[x, y, 0] = @edge_chip_id + 34

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 36

else

@map.data[x, y, 0] = @edge_chip_id + 20

end

end

end

else

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 44

else

@map.data[x, y, 0] = @edge_chip_id + 40

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 38

else

@map.data[x, y, 0] = @edge_chip_id + 28

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 32

else

@map.data[x, y, 0] = @edge_chip_id + 16

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 24

else

if inner?(x+1, y+1) || inner?(x+1, y-1) ||

inner?(x-1, y-1) || inner?(x-1, y+1)

@map.data[x, y, 0] = @edge_chip_id

else

@map.data[x, y, 0] = @blank_chip_id

end

end

end

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠影タイルを置ãã¾ã™

#--------------------------------------------------------------------------

def put_shadow

for y in 0..@map.height

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x-1, y-1)

next unless blank?(x-1, y)

@map.data[x, y, 3] = 5

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå¢ƒç•Œã®å†…å´ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def inner?(x, y)

return floor?(x, y) || wall?(x, y) || object?(x, y)

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒåºŠã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def floor?(x, y)

return false if @map.data[x, y, 2] == @object_chip_id2

return true if @floor_chip_id1 && @map.data[x, y, 0] == @floor_chip_id1

return @map.data[x, y, 0] == @floor_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒã‚«ãƒ©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def blank?(x, y)

return @map.data[x, y, 0] == @blank_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒéšœå®³ç‰©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def object?(x, y)

return @map.data[x, y, 0] == @object_chip_id0

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå£ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def wall?(x, y)

tile = @map.data[x, y, 0]

return false if tile == nil || tile == 0

return tile >= @wall_chip_id && tile <= @wall_chip_id + 15

end

 

end

 

Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:

Share this post


Link to post
Share on other sites

Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:

 

Oh right, I actually had code for use with this script. Since then I moved it elsewhere, so here is a more current version:

 

#==============================================================================

# - Dungeon Creation 6 KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# To many changes to really list, lots of little things.

#==============================================================================

module Saba

module Dungeon

# Minumum block size (Hard to explain, try it out yourself)

# Default: 7

MINIMUM_RECT_SIZE = 5

 

# Minimum room size.

# Default: 3

MINIMUM_ROOM_SIZE = 3

 

# Margin between rooms and 'blocks'.

# Default: 2

MARGIN_BETWEEN_RECT_ROOM = 2

 

# The percentage of corridors made. (1/n)

# Works best with lower values.

# Default: 35

MORE_COUPLE_RATE = 35

 

# Variable that stores enemy amount.

ENEMY_COUNT_VARIABLE = 3

end

end

 

#=========================================================================

# Do not edit anything under this line unless you know what you're doing!

#=========================================================================

 

#==============================================================================

# â–  Dungeon_Rect

#------------------------------------------------------------------------------

#  ダンジョンを区切ã£ãŸé ˜åŸŸã‚’表ã—ã¾ã™ã€‚

#ã€€å„ Dungeon_Rect ã«ä¸€ã¤ã¥ã¤ Room ãŒå­˜åœ¨ã—ã¾ã™ã€‚

#==============================================================================

class Dungeon_Rect

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :room

attr_accessor :done_split_v

attr_accessor :done_split_h

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

self.done_split_v = false

self.done_split_h = false

end

end

 

#==============================================================================

# â–  Room

#------------------------------------------------------------------------------

#  部屋ã§ã™ã€‚

#==============================================================================

class Room

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :mapping

attr_reader :width

attr_reader :height

attr_reader :couple_areas # 通路ã«é¢ã—ã¦ã„ã‚‹[x, y]ã®ãƒªã‚¹ãƒˆ

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

@width = hx - lx

@height = hy - ly

@events = {}

@couple_areas = []

@mapping = false

end

 

#--------------------------------------------------------------------------

# ◠イベントé…ç½®å¯èƒ½æ•°æ®‹ã‚Šã‚’å–å¾—

#--------------------------------------------------------------------------

def remain

return (hx - lx) * (hy - ly) - @events.size - @couple_areas.size

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’å«ã‚“ã§ã„ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def contains(x, y)

return lx <= x && x < hx && ly <= y && y < hy

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’明るãã™ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def right_area?(x, y)

return lx-1 <= x && x < hx+1 && ly-1 <= y && y < hy+1

end

end

 

 

 

 

#==============================================================================

# â–  Couple

#------------------------------------------------------------------------------

#  通路ã§ã™ã€‚

#==============================================================================

class Couple

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :rect0

attr_accessor :rect1

attr_accessor :direction

end

 

class Game_Map

attr_reader :map

 

#--------------------------------------------------------------------------

# ◠定数

#--------------------------------------------------------------------------

COUPLE_VERTICAL = 0

COUPLE_HORIZONAL = 1

#--------------------------------------------------------------------------

# ◠セットアップ

# map_id : マップ ID

#--------------------------------------------------------------------------

alias saba_setup setup

def setup(map_id)

saba_setup(map_id)

@random_dungeon = nil

make_random_dungeon if dungeon?

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンを作æˆ

#--------------------------------------------------------------------------

def make_random_dungeon

@rect_list = []

@room_list = []

@couple_list = []

@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))

@floor_chip_id = @map.data[0, 0, 0]

@floor_chip_id1 = @map.data[1, 0, 0]

@edge_chip_id = @map.data[0, 1, 0]

@wall_chip_id = @map.data[0, 2, 0]

@blank_chip_id = @map.data[0, 4, 0]

@object_chip_id0 = @map.data[0, 3, 0]

@object_chip_id1 = @map.data[0, 3, 1]

@object_chip_id2 = @map.data[0, 3, 2]

make_rect

make_room

make_couple_more

 

@init_phase = true

 

put_blank_tiles

put_couple_tiles

put_room_tiles

put_shadow

put_wall_tiles

put_edge_tiles

 

setup_dungeon_level

setup_dungeon_events

@random_data = @map.data

@last_moving = false

 

end

 

def setup_dungeon_level; return; end # stub method

 

#--------------------------------------------------------------------------

# ◠区切りを作æˆ

#--------------------------------------------------------------------------

def make_rect

split_rect(add_rect(0, 1, @map.width, @map.height))

end

#--------------------------------------------------------------------------

# ◠指定㮠DungeonRect を区切る

#--------------------------------------------------------------------------

def split_rect(parent)

if (parent.hy - parent.ly <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_v = true

end

if (parent.hx - parent.lx <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_h = true;

end

if ((parent.done_split_v) && (parent.done_split_h))

return

end

child = add_rect(parent.lx, parent.ly, parent.hx, parent.hy)

unless parent.done_split_v

split_coord_y = random_range(parent.ly + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hy - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hy = split_coord_y

child.ly = split_coord_y

parent.done_split_v = true

child.done_split_v = true

add_couple(COUPLE_VERTICAL, parent, child)

split_rect(parent)

split_rect(child)

else

split_coord_x = random_range(parent.lx + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hx - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hx = split_coord_x

child.lx = split_coord_x

parent.done_split_h = true

child.done_split_h = true

add_couple(COUPLE_HORIZONAL, parent, child)

split_rect(parent)

split_rect(child)

end

end

#--------------------------------------------------------------------------

# â— ã•ã‚‰ã«é“を作æˆ

#--------------------------------------------------------------------------

def make_couple_more

rectmap = {}

for rect in @rect_list

for i in rect.lx...rect.hx

for j in rect.ly...rect.hy

rectmap[[i, j]] = rect

end

end

end

 

for i in 0..(@map.width-2)

for j in 1..(@map.height-2)

if rectmap[[i, j]] != rectmap[[i, j + 1]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_VERTICAL, rectmap[[i,j]], rectmap[[i, j + 1]])

end

end

if rectmap[[i, j]] != rectmap[[i + 1, j]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_HORIZONAL, rectmap[[i, j]], rectmap[[i + 1, j]])

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンã‹ï¼Ÿ

#--------------------------------------------------------------------------

def dungeon?

if @random_dungeon != nil

return @random_dungeon

end

unless @map_infos

@map_infos = load_data("Data/MapInfos.rvdata2")

end

@random_dungeon = @map_infos[@map_id].name.include?("@")

return @random_dungeon

end

#--------------------------------------------------------------------------

# ◠指定ã®åŒºé–“ã®ä¸­ã§ãƒ©ãƒ³ãƒ€ãƒ ãªå€¤ã‚’å–å¾—

#--------------------------------------------------------------------------

def random_range(b, e)

return (rand(e - b ) + b ).to_i

end

#--------------------------------------------------------------------------

# â— DungeonRect を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_rect(lx, ly, hx, hy)

rect = Dungeon_Rect.new(lx, ly, hx, hy)

@rect_list.push(rect)

return rect

end

#--------------------------------------------------------------------------

# â— Room を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_room(lx, ly, hx, hy)

room = Room.new(lx, ly, hx, hy)

@room_list.push(room)

return room

end

#--------------------------------------------------------------------------

# ◠部屋を作æˆ

#--------------------------------------------------------------------------

def make_room

for rect in @rect_list

w = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hx - rect.lx - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

h = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hy - rect.ly - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

x = random_range(rect.lx + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hx - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - w + 1);

y = random_range(rect.ly + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hy - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - h + 1);

rect.room = add_room(x, y, x + w, y + h);

end

end

#--------------------------------------------------------------------------

# ◠通路 を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_couple(direction, rect0, rect1)

@couple_list.each {|c|

if (c.rect0 == rect0 && c.rect1 == rect1) ||

(c.rect0 == rect1 && c.rect1 == rect0)

# é‡è¤‡ã¯ã¤ãらãªã„

return

end

}

couple = Couple.new

couple.direction = direction

couple.rect0 = rect0

couple.rect1 = rect1

@couple_list.push(couple)

return couple

end

#--------------------------------------------------------------------------

# ◠空ããƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_blank_tiles

for x in 0..@map.width

for y in 0..@map.height

@map.data[x, y, 0] = @blank_chip_id

@map.data[x, y, 1] = 0

@map.data[x, y, 2] = 0

end

end

end

#--------------------------------------------------------------------------

# ◠床ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_room_tiles

for rect in @rect_list

room = rect.room

(room.hx - room.lx).times do |x|

(room.hy - room.ly).times do |y|

put_floor_tile(x + room.lx, y + room.ly)

end

end

end

end

def put_floor_tile(x, y)

if @floor_chip_id1 > 0 && rand(10) == 0

@map.data[x, y, 0] = @floor_chip_id1

else

@map.data[x, y, 0] = @floor_chip_id

end

end

#--------------------------------------------------------------------------

# ◠通路ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_couple_tiles

for couple in @couple_list

case couple.direction

when COUPLE_HORIZONAL then

unless couple.rect0.hx == couple.rect1.lx

p "Errorx:" + couple.rect0.hx.to_s + couple.rect1.lx .to_s

next

end

c0x = couple.rect0.hx

c0y = random_range(couple.rect0.room.ly + 1, couple.rect0.room.hy)

c1x = couple.rect1.lx

c1y = random_range(couple.rect1.room.ly + 1, couple.rect1.room.hy)

line(c0x, c0y, c1x, c1y);

line(couple.rect0.room.hx, c0y, c0x, c0y)

line(couple.rect1.room.lx, c1y, c1x, c1y)

couple.rect0.room.couple_areas.push([couple.rect0.room.hx-1, c0y])

couple.rect1.room.couple_areas.push([couple.rect1.room.lx, c1y])

when COUPLE_VERTICAL then

unless couple.rect0.hy == couple.rect1.ly

p "Errory:" + couple.rect0.hy.to_s + " " + couple.rect1.ly .to_s

next

end

c0x = random_range(couple.rect0.room.lx + 1, couple.rect0.room.hx)

c0y = couple.rect0.hy

c1x = random_range(couple.rect1.room.lx + 1, couple.rect1.room.hx)

c1y = couple.rect1.ly

line(c0x, c0y, c1x, c1y)

line(c0x, couple.rect0.room.hy, c0x, c0y)

line(c1x, couple.rect1.room.ly, c1x, c1y)

couple.rect0.room.couple_areas.push([c0x, couple.rect0.room.hy-1])

couple.rect1.room.couple_areas.push([c1x, couple.rect1.room.ly])

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™é–“ã§åºŠã‚’é…ç½®

#--------------------------------------------------------------------------

def line(x0, y0, x1, y1)

min_x = [x0, x1].min

max_x = [x0, x1].max

min_y = [y0, y1].min

max_y = [y0, y1].max

if ((x0 <= x1) && (y0 >= y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 > y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 <= y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 <= x1) && (y0 < y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(min_x, j)

end

end

end

#--------------------------------------------------------------------------

# â— å£ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_wall_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x, y-1)

@map.data[x, y-1, 0] = @wall_chip_id + 15

end

end

 

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next unless tile == @wall_chip_id + 15

if floor?(x, y-1)

put_object_tile(x, y)

next

end

if floor?(x-1, y) || blank?(x-1, y)

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 15

else

@map.data[x, y, 0] = @wall_chip_id + 11

end

else

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 14

else

@map.data[x, y, 0] = @wall_chip_id + 10

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠障害物ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_object_tile(x, y)

@map.data[x, y, 0] = @object_chip_id0

@map.data[x, y, 1] = @object_chip_id1

@map.data[x, y, 2] = @object_chip_id2

end

#--------------------------------------------------------------------------

# ◠境界ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_edge_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next if inner?(x, y)

if inner?(x, y-1)

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 46

else

@map.data[x, y, 0] = @edge_chip_id + 43

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 45

else

@map.data[x, y, 0] = @edge_chip_id + 33

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 42

else

@map.data[x, y, 0] = @edge_chip_id + 34

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 36

else

@map.data[x, y, 0] = @edge_chip_id + 20

end

end

end

else

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 44

else

@map.data[x, y, 0] = @edge_chip_id + 40

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 38

else

@map.data[x, y, 0] = @edge_chip_id + 28

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 32

else

@map.data[x, y, 0] = @edge_chip_id + 16

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 24

else

if inner?(x+1, y+1) || inner?(x+1, y-1) ||

inner?(x-1, y-1) || inner?(x-1, y+1)

@map.data[x, y, 0] = @edge_chip_id

else

@map.data[x, y, 0] = @blank_chip_id

end

end

end

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠影タイルを置ãã¾ã™

#--------------------------------------------------------------------------

def put_shadow

for y in 0..@map.height

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x-1, y-1)

next unless blank?(x-1, y)

@map.data[x, y, 3] = 5

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå¢ƒç•Œã®å†…å´ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def inner?(x, y)

return floor?(x, y) || wall?(x, y) || object?(x, y)

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒåºŠã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def floor?(x, y)

return false if @map.data[x, y, 2] == @object_chip_id2

return true if @floor_chip_id1 && @map.data[x, y, 0] == @floor_chip_id1

return @map.data[x, y, 0] == @floor_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒã‚«ãƒ©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def blank?(x, y)

return @map.data[x, y, 0] == @blank_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒéšœå®³ç‰©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def object?(x, y)

return @map.data[x, y, 0] == @object_chip_id0

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå£ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def wall?(x, y)

tile = @map.data[x, y, 0]

return false if tile == nil || tile == 0

return tile >= @wall_chip_id && tile <= @wall_chip_id + 15

end

 

end

 

 

I should post all of my dungeon scripts in my blog thingy sometime. I have a lot of sub-scripts. I have like nine scripts total dedicated to some aspect of dungeons (though a few are really short).

Edited by KilloZapit

Share this post


Link to post
Share on other sites

Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:

 

Oh right, I actually had code for use with this script. Since then I moved it elsewhere, so here is a more current version:

 

#==============================================================================

# - Dungeon Creation 6 KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# To many changes to really list, lots of little things.

#==============================================================================

module Saba

module Dungeon

# Minumum block size (Hard to explain, try it out yourself)

# Default: 7

MINIMUM_RECT_SIZE = 5

 

# Minimum room size.

# Default: 3

MINIMUM_ROOM_SIZE = 3

 

# Margin between rooms and 'blocks'.

# Default: 2

MARGIN_BETWEEN_RECT_ROOM = 2

 

# The percentage of corridors made. (1/n)

# Works best with lower values.

# Default: 35

MORE_COUPLE_RATE = 35

 

# Variable that stores enemy amount.

ENEMY_COUNT_VARIABLE = 3

end

end

 

#=========================================================================

# Do not edit anything under this line unless you know what you're doing!

#=========================================================================

 

#==============================================================================

# â–  Dungeon_Rect

#------------------------------------------------------------------------------

#  ダンジョンを区切ã£ãŸé ˜åŸŸã‚’表ã—ã¾ã™ã€‚

#ã€€å„ Dungeon_Rect ã«ä¸€ã¤ã¥ã¤ Room ãŒå­˜åœ¨ã—ã¾ã™ã€‚

#==============================================================================

class Dungeon_Rect

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :room

attr_accessor :done_split_v

attr_accessor :done_split_h

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

self.done_split_v = false

self.done_split_h = false

end

end

 

#==============================================================================

# â–  Room

#------------------------------------------------------------------------------

#  部屋ã§ã™ã€‚

#==============================================================================

class Room

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :lx

attr_accessor :ly

attr_accessor :hx

attr_accessor :hy

attr_accessor :mapping

attr_reader :width

attr_reader :height

attr_reader :couple_areas # 通路ã«é¢ã—ã¦ã„ã‚‹[x, y]ã®ãƒªã‚¹ãƒˆ

#--------------------------------------------------------------------------

# ◠オブジェクトåˆæœŸåŒ–

#--------------------------------------------------------------------------

def initialize(lx, ly, hx, hy)

self.lx = lx

self.ly = ly

self.hx = hx

self.hy = hy

@width = hx - lx

@height = hy - ly

@events = {}

@couple_areas = []

@mapping = false

end

 

#--------------------------------------------------------------------------

# ◠イベントé…ç½®å¯èƒ½æ•°æ®‹ã‚Šã‚’å–å¾—

#--------------------------------------------------------------------------

def remain

return (hx - lx) * (hy - ly) - @events.size - @couple_areas.size

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’å«ã‚“ã§ã„ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def contains(x, y)

return lx <= x && x < hx && ly <= y && y < hy

end

 

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ã‚’明るãã™ã‚‹ã‹ã‚’å–å¾—

#--------------------------------------------------------------------------

def right_area?(x, y)

return lx-1 <= x && x < hx+1 && ly-1 <= y && y < hy+1

end

end

 

 

 

 

#==============================================================================

# â–  Couple

#------------------------------------------------------------------------------

#  通路ã§ã™ã€‚

#==============================================================================

class Couple

#--------------------------------------------------------------------------

# ◠公開インスタンス変数

#--------------------------------------------------------------------------

attr_accessor :rect0

attr_accessor :rect1

attr_accessor :direction

end

 

class Game_Map

attr_reader :map

 

#--------------------------------------------------------------------------

# ◠定数

#--------------------------------------------------------------------------

COUPLE_VERTICAL = 0

COUPLE_HORIZONAL = 1

#--------------------------------------------------------------------------

# ◠セットアップ

# map_id : マップ ID

#--------------------------------------------------------------------------

alias saba_setup setup

def setup(map_id)

saba_setup(map_id)

@random_dungeon = nil

make_random_dungeon if dungeon?

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンを作æˆ

#--------------------------------------------------------------------------

def make_random_dungeon

@rect_list = []

@room_list = []

@couple_list = []

@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))

@floor_chip_id = @map.data[0, 0, 0]

@floor_chip_id1 = @map.data[1, 0, 0]

@edge_chip_id = @map.data[0, 1, 0]

@wall_chip_id = @map.data[0, 2, 0]

@blank_chip_id = @map.data[0, 4, 0]

@object_chip_id0 = @map.data[0, 3, 0]

@object_chip_id1 = @map.data[0, 3, 1]

@object_chip_id2 = @map.data[0, 3, 2]

make_rect

make_room

make_couple_more

 

@init_phase = true

 

put_blank_tiles

put_couple_tiles

put_room_tiles

put_shadow

put_wall_tiles

put_edge_tiles

 

setup_dungeon_level

setup_dungeon_events

@random_data = @map.data

@last_moving = false

 

end

 

def setup_dungeon_level; return; end # stub method

 

#--------------------------------------------------------------------------

# ◠区切りを作æˆ

#--------------------------------------------------------------------------

def make_rect

split_rect(add_rect(0, 1, @map.width, @map.height))

end

#--------------------------------------------------------------------------

# ◠指定㮠DungeonRect を区切る

#--------------------------------------------------------------------------

def split_rect(parent)

if (parent.hy - parent.ly <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_v = true

end

if (parent.hx - parent.lx <= Saba::Dungeon::MINIMUM_RECT_SIZE * 2)

parent.done_split_h = true;

end

if ((parent.done_split_v) && (parent.done_split_h))

return

end

child = add_rect(parent.lx, parent.ly, parent.hx, parent.hy)

unless parent.done_split_v

split_coord_y = random_range(parent.ly + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hy - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hy = split_coord_y

child.ly = split_coord_y

parent.done_split_v = true

child.done_split_v = true

add_couple(COUPLE_VERTICAL, parent, child)

split_rect(parent)

split_rect(child)

else

split_coord_x = random_range(parent.lx + Saba::Dungeon::MINIMUM_RECT_SIZE, parent.hx - Saba::Dungeon::MINIMUM_RECT_SIZE)

parent.hx = split_coord_x

child.lx = split_coord_x

parent.done_split_h = true

child.done_split_h = true

add_couple(COUPLE_HORIZONAL, parent, child)

split_rect(parent)

split_rect(child)

end

end

#--------------------------------------------------------------------------

# â— ã•ã‚‰ã«é“を作æˆ

#--------------------------------------------------------------------------

def make_couple_more

rectmap = {}

for rect in @rect_list

for i in rect.lx...rect.hx

for j in rect.ly...rect.hy

rectmap[[i, j]] = rect

end

end

end

 

for i in 0..(@map.width-2)

for j in 1..(@map.height-2)

if rectmap[[i, j]] != rectmap[[i, j + 1]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_VERTICAL, rectmap[[i,j]], rectmap[[i, j + 1]])

end

end

if rectmap[[i, j]] != rectmap[[i + 1, j]]

if rand(Saba::Dungeon::MORE_COUPLE_RATE) == 0

add_couple(COUPLE_HORIZONAL, rectmap[[i, j]], rectmap[[i + 1, j]])

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠ランダムダンジョンã‹ï¼Ÿ

#--------------------------------------------------------------------------

def dungeon?

if @random_dungeon != nil

return @random_dungeon

end

unless @map_infos

@map_infos = load_data("Data/MapInfos.rvdata2")

end

@random_dungeon = @map_infos[@map_id].name.include?("@")

return @random_dungeon

end

#--------------------------------------------------------------------------

# ◠指定ã®åŒºé–“ã®ä¸­ã§ãƒ©ãƒ³ãƒ€ãƒ ãªå€¤ã‚’å–å¾—

#--------------------------------------------------------------------------

def random_range(b, e)

return (rand(e - b ) + b ).to_i

end

#--------------------------------------------------------------------------

# â— DungeonRect を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_rect(lx, ly, hx, hy)

rect = Dungeon_Rect.new(lx, ly, hx, hy)

@rect_list.push(rect)

return rect

end

#--------------------------------------------------------------------------

# â— Room を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_room(lx, ly, hx, hy)

room = Room.new(lx, ly, hx, hy)

@room_list.push(room)

return room

end

#--------------------------------------------------------------------------

# ◠部屋を作æˆ

#--------------------------------------------------------------------------

def make_room

for rect in @rect_list

w = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hx - rect.lx - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

h = random_range(Saba::Dungeon::MINIMUM_ROOM_SIZE, rect.hy - rect.ly - (Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM * 2) + 1);

x = random_range(rect.lx + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hx - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - w + 1);

y = random_range(rect.ly + Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM, rect.hy - Saba::Dungeon::MARGIN_BETWEEN_RECT_ROOM - h + 1);

rect.room = add_room(x, y, x + w, y + h);

end

end

#--------------------------------------------------------------------------

# ◠通路 を作æˆã—ã¦è¿½åŠ 

#--------------------------------------------------------------------------

def add_couple(direction, rect0, rect1)

@couple_list.each {|c|

if (c.rect0 == rect0 && c.rect1 == rect1) ||

(c.rect0 == rect1 && c.rect1 == rect0)

# é‡è¤‡ã¯ã¤ãらãªã„

return

end

}

couple = Couple.new

couple.direction = direction

couple.rect0 = rect0

couple.rect1 = rect1

@couple_list.push(couple)

return couple

end

#--------------------------------------------------------------------------

# ◠空ããƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_blank_tiles

for x in 0..@map.width

for y in 0..@map.height

@map.data[x, y, 0] = @blank_chip_id

@map.data[x, y, 1] = 0

@map.data[x, y, 2] = 0

end

end

end

#--------------------------------------------------------------------------

# ◠床ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_room_tiles

for rect in @rect_list

room = rect.room

(room.hx - room.lx).times do |x|

(room.hy - room.ly).times do |y|

put_floor_tile(x + room.lx, y + room.ly)

end

end

end

end

def put_floor_tile(x, y)

if @floor_chip_id1 > 0 && rand(10) == 0

@map.data[x, y, 0] = @floor_chip_id1

else

@map.data[x, y, 0] = @floor_chip_id

end

end

#--------------------------------------------------------------------------

# ◠通路ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_couple_tiles

for couple in @couple_list

case couple.direction

when COUPLE_HORIZONAL then

unless couple.rect0.hx == couple.rect1.lx

p "Errorx:" + couple.rect0.hx.to_s + couple.rect1.lx .to_s

next

end

c0x = couple.rect0.hx

c0y = random_range(couple.rect0.room.ly + 1, couple.rect0.room.hy)

c1x = couple.rect1.lx

c1y = random_range(couple.rect1.room.ly + 1, couple.rect1.room.hy)

line(c0x, c0y, c1x, c1y);

line(couple.rect0.room.hx, c0y, c0x, c0y)

line(couple.rect1.room.lx, c1y, c1x, c1y)

couple.rect0.room.couple_areas.push([couple.rect0.room.hx-1, c0y])

couple.rect1.room.couple_areas.push([couple.rect1.room.lx, c1y])

when COUPLE_VERTICAL then

unless couple.rect0.hy == couple.rect1.ly

p "Errory:" + couple.rect0.hy.to_s + " " + couple.rect1.ly .to_s

next

end

c0x = random_range(couple.rect0.room.lx + 1, couple.rect0.room.hx)

c0y = couple.rect0.hy

c1x = random_range(couple.rect1.room.lx + 1, couple.rect1.room.hx)

c1y = couple.rect1.ly

line(c0x, c0y, c1x, c1y)

line(c0x, couple.rect0.room.hy, c0x, c0y)

line(c1x, couple.rect1.room.ly, c1x, c1y)

couple.rect0.room.couple_areas.push([c0x, couple.rect0.room.hy-1])

couple.rect1.room.couple_areas.push([c1x, couple.rect1.room.ly])

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™é–“ã§åºŠã‚’é…ç½®

#--------------------------------------------------------------------------

def line(x0, y0, x1, y1)

min_x = [x0, x1].min

max_x = [x0, x1].max

min_y = [y0, y1].min

max_y = [y0, y1].max

if ((x0 <= x1) && (y0 >= y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 > y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 > x1) && (y0 <= y1))

for i in min_x..max_x

put_floor_tile(i, min_y)

end

for j in min_y..max_y

put_floor_tile(max_x, j)

end

elsif ((x0 <= x1) && (y0 < y1))

for i in min_x..max_x

put_floor_tile(i, max_y)

end

for j in min_y..max_y

put_floor_tile(min_x, j)

end

end

end

#--------------------------------------------------------------------------

# â— å£ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_wall_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x, y-1)

@map.data[x, y-1, 0] = @wall_chip_id + 15

end

end

 

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next unless tile == @wall_chip_id + 15

if floor?(x, y-1)

put_object_tile(x, y)

next

end

if floor?(x-1, y) || blank?(x-1, y)

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 15

else

@map.data[x, y, 0] = @wall_chip_id + 11

end

else

if floor?(x+1, y) || blank?(x+1, y)

@map.data[x, y, 0] = @wall_chip_id + 14

else

@map.data[x, y, 0] = @wall_chip_id + 10

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠障害物ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_object_tile(x, y)

@map.data[x, y, 0] = @object_chip_id0

@map.data[x, y, 1] = @object_chip_id1

@map.data[x, y, 2] = @object_chip_id2

end

#--------------------------------------------------------------------------

# ◠境界ãƒãƒƒãƒ—ã‚’é…ç½®

#--------------------------------------------------------------------------

def put_edge_tiles

for y in (1..@map.height).to_a.reverse

for x in 0..@map.width

tile = @map.data[x, y, 0]

next if inner?(x, y)

if inner?(x, y-1)

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 46

else

@map.data[x, y, 0] = @edge_chip_id + 43

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 45

else

@map.data[x, y, 0] = @edge_chip_id + 33

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 42

else

@map.data[x, y, 0] = @edge_chip_id + 34

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 36

else

@map.data[x, y, 0] = @edge_chip_id + 20

end

end

end

else

if inner?(x, y+1)

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 44

else

@map.data[x, y, 0] = @edge_chip_id + 40

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 38

else

@map.data[x, y, 0] = @edge_chip_id + 28

end

end

else

if inner?(x-1, y)

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 32

else

@map.data[x, y, 0] = @edge_chip_id + 16

end

else

if inner?(x+1, y)

@map.data[x, y, 0] = @edge_chip_id + 24

else

if inner?(x+1, y+1) || inner?(x+1, y-1) ||

inner?(x-1, y-1) || inner?(x-1, y+1)

@map.data[x, y, 0] = @edge_chip_id

else

@map.data[x, y, 0] = @blank_chip_id

end

end

end

end

end

end

end

end

#--------------------------------------------------------------------------

# ◠影タイルを置ãã¾ã™

#--------------------------------------------------------------------------

def put_shadow

for y in 0..@map.height

for x in 0..@map.width

next unless floor?(x, y)

next if floor?(x-1, y-1)

next unless blank?(x-1, y)

@map.data[x, y, 3] = 5

end

end

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå¢ƒç•Œã®å†…å´ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def inner?(x, y)

return floor?(x, y) || wall?(x, y) || object?(x, y)

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒåºŠã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def floor?(x, y)

return false if @map.data[x, y, 2] == @object_chip_id2

return true if @floor_chip_id1 && @map.data[x, y, 0] == @floor_chip_id1

return @map.data[x, y, 0] == @floor_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒã‚«ãƒ©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def blank?(x, y)

return @map.data[x, y, 0] == @blank_chip_id

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒéšœå®³ç‰©ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def object?(x, y)

return @map.data[x, y, 0] == @object_chip_id0

end

#--------------------------------------------------------------------------

# ◠指定ã®åº§æ¨™ãŒå£ã‹ã©ã†ã‹

#--------------------------------------------------------------------------

def wall?(x, y)

tile = @map.data[x, y, 0]

return false if tile == nil || tile == 0

return tile >= @wall_chip_id && tile <= @wall_chip_id + 15

end

 

end

 

 

I should post all of my dungeon scripts in my blog thingy sometime. I have a lot of sub-scripts. I have like nine scripts total dedicated to some aspect of dungeons (though a few are really short).

Added the corrected version but got a new error. This one is from the Entity Placement Script which I named RDG Event Control.

Edited by Animebryan

Share this post


Link to post
Share on other sites

Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:

 

Oh right, I actually had code for use with this script. Since then I moved it elsewhere, so here is a more current version:

 

I should post all of my dungeon scripts in my blog thingy sometime. I have a lot of sub-scripts. I have like nine scripts total dedicated to some aspect of dungeons (though a few are really short).

Added the corrected version but got a new error. This one is from the Entity Placement Script which I named RDG Event Control.

 

Oh geez... sometimes I forget how convolutedly interdependent some of my scripts can be. One of the reason I don't release that many scripts that much. Oh well, it's good to figure out this stuff. Anyway try this event script:

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

I do hope I am being helpful though. I don't mind looking into things I may have overlooked. That said, stuff like this is probably going to need touching up for you to use it the way you want, even when all the bugs are sorted out. So, yeah.

 

Honestly I am half-tempted to try to make my own dungeon generator, but I don't think I quite understand how it works enough. I mean I understand the basic theory (basically make a rectangle for the whole map and recursively divides it randomly, then makes a room for each rectangle and connect the rooms with corridors), but I don't feel I understand the details enough to really make my own (especially regarding the corridors). The actual entity placement stuff is much simpler really.

 

Hey BTW, do you want my turn-based movement script too? I completely rewrote it though (party because I already had a script I had been working on before finding Saba Kan's script)

Edited by KilloZapit

Share this post


Link to post
Share on other sites

Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:

 

Oh right, I actually had code for use with this script. Since then I moved it elsewhere, so here is a more current version:

 

I should post all of my dungeon scripts in my blog thingy sometime. I have a lot of sub-scripts. I have like nine scripts total dedicated to some aspect of dungeons (though a few are really short).

Added the corrected version but got a new error. This one is from the Entity Placement Script which I named RDG Event Control.

 

Oh geez... sometimes I forget how convolutedly interdependent some of my scripts can be. One of the reason I don't release that many scripts that much. Oh well, it's good to figure out this stuff. Anyway try this event script:

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

I do hope I am being helpful though. I don't mind looking into things I may have overlooked. That said, stuff like this is probably going to need touching up for you to use it the way you want, even when all the bugs are sorted out. So, yeah.

 

Honestly I am half-tempted to try to make my own dungeon generator, but I don't think I quite understand how it works enough. I mean I understand the basic theory (basically make a rectangle for the whole map and recursively divides it randomly, then makes a room for each rectangle and connect the rooms with corridors), but I don't feel I understand the details enough to really make my own (especially regarding the corridors). The actual entity placement stuff is much simpler really.

 

Hey BTW, do you want my turn-based movement script too? I completely rewrote it though (party because I already had a script I had been working on before finding Saba Kan's script)

I replaced the event control to the new one but got another error. When you say turn-based movement do mean the script where enemies on the map only move when you move? Because if that's the case then yes, I definately need that. But does it only work with the random dungeon generator or can I use it on regular maps too? Because this is the standard I wanna run in my dungeons.

Edited by Animebryan

Share this post


Link to post
Share on other sites

Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:

 

Oh right, I actually had code for use with this script. Since then I moved it elsewhere, so here is a more current version:

 

I should post all of my dungeon scripts in my blog thingy sometime. I have a lot of sub-scripts. I have like nine scripts total dedicated to some aspect of dungeons (though a few are really short).

Added the corrected version but got a new error. This one is from the Entity Placement Script which I named RDG Event Control.

 

Oh geez... sometimes I forget how convolutedly interdependent some of my scripts can be. One of the reason I don't release that many scripts that much. Oh well, it's good to figure out this stuff. Anyway try this event script:

 

I do hope I am being helpful though. I don't mind looking into things I may have overlooked. That said, stuff like this is probably going to need touching up for you to use it the way you want, even when all the bugs are sorted out. So, yeah.

 

Honestly I am half-tempted to try to make my own dungeon generator, but I don't think I quite understand how it works enough. I mean I understand the basic theory (basically make a rectangle for the whole map and recursively divides it randomly, then makes a room for each rectangle and connect the rooms with corridors), but I don't feel I understand the details enough to really make my own (especially regarding the corridors). The actual entity placement stuff is much simpler really.

 

Hey BTW, do you want my turn-based movement script too? I completely rewrote it though (party because I already had a script I had been working on before finding Saba Kan's script)

I replaced the event control to the new one but got another error. When you say turn-based movement do mean the script where enemies on the map only move when you move? Because if that's the case then yes, I definately need that. But does it only work with the random dungeon generator or can I use it on regular maps too? Because this is the standard I wanna run in my dungeons.

 

Darn it Saba Kan, there you go putting unexpected things in the mini map script again. Also, my turn based movement script can be used on other maps sure, though I didn't really work too much on how. Right now I just have switch 1 enable it.

 

Event stuff:

 

==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

attr_accessor :room

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

Turn based movement stuff (all mine :P)

 

#==============================================================================

# - Compleatly new turn based movement logic.

# Just because I liked my version better.

#==============================================================================

 

class Game_Map

def turnmode?

return true if dungeon?

return true if $game_switches[1]

return false

end

end

 

class Game_Event < Game_Character

 

attr_accessor :stop_steps

attr_accessor :alerted

attr_accessor :last_chase_x

attr_accessor :last_chase_y

 

alias_method :initialize_event_turnmove_base, :initialize

def initialize(map_id, event)

initialize_event_turnmove_base(map_id, event)

@movesync = false

@stop_steps = 0

@move_steps = 0

@alerted = nil

@last_chase_x = nil

@last_chase_y = nil

@chase_seen = false

end

 

alias_method :update_turnmove_base, :update

def update

@last_moving = moving?

update_turnmove_base

return unless $game_map.turnmode?

if @movesync || @last_moving

$game_player.movesync = true

@movesync = false

end

end

 

alias_method :update_stop_turnmove_base, :update_stop

def update_stop

update_stop_turnmove_base

return unless $game_map.turnmode?

if $game_player.start_move

@stop_steps -= 1

if @stop_steps < 0

if @move_route_forcing

@opacity = 255

@move_route_forcing = false

restore_move_route

end

@stop_steps = 5 - (@move_frequency - ($game_player.move_speed - @move_speed))

@move_steps = [1 + (@move_speed - $game_player.move_speed), 1].max

end

unless @alerted.nil?

@alerted = near_the_player? && alert?

end

@movesync = true

end

end

 

alias_method :update_self_movement_turnmove_base, :update_self_movement

def update_self_movement

return update_self_movement_turnmove_base unless $game_map.turnmode?

return unless ($game_player.moving? || @move_steps > 0) && @stop_steps <= 0

@movesync = true

update_self_movement_turnmove_base

@move_steps -= 1

end

 

def dash?

return super unless $game_map.turnmode?

return $game_player.dash?

end

 

def real_move_speed

return super unless $game_map.turnmode?

[@move_speed, $game_player.move_speed].max + (dash? ? 1 : 0)

end

 

alias_method :stop_count_threshold_turnmove_base, :stop_count_threshold

def stop_count_threshold

return stop_count_threshold_turnmove_base unless $game_map.turnmode?

0

end

 

end

 

class Game_Player

attr_accessor :movesync

attr_reader :start_move

attr_reader :end_move

attr_reader :stop_steps

 

alias_method :initialize_player_turnmove_base, :initialize

def initialize

initialize_player_turnmove_base

@movesync = true

@start_move = false

@end_move = true

@stop_steps = 0

end

 

alias_method :movable_turnmove_base?, :movable?

def movable?

if @movesync

@movesync = false

return false

end

return movable_turnmove_base?

end

 

alias_method :move_by_input_turnmove_base, :move_by_input

def move_by_input

unless $game_map.turnmode?

move_by_input_turnmove_base

return

end

if !movable? || $game_map.interpreter.running?

@start_move = false

return

end

if @stop_steps > 0

#puts("Player Stop: " + @stop_steps.to_s)

@stop_steps -= 1

@start_move = true

@movesync = true

return

end

unless @end_move

#puts("--Round End--")

@end_move = true

end

if Input.dir4 > 0

unless passable?(@x, @y, Input.dir4)

set_direction(Input.dir4)

check_event_trigger_touch_front

return

end

move_straight(Input.dir4)

@start_move = true

elsif Input.press?(:A)

@stop_steps += 1

@start_move = true

@movesync = true

else

@start_move = false

end

if @start_move

#puts("--Round Start--")

@end_move = false

end

end

end

 

 

Honestly I am not sure how good these scripts are in the long run.

Share this post


Link to post
Share on other sites

Turn-based movement. You mean like how TBS games work? Damn that's really simple for something I thought was really complex.

Share this post


Link to post
Share on other sites

More like roguelike games, aka 1 step = 1 round unless quickened or slowed. My script may or may not be the best way to do it. My turnbased movement script actually does let you have enemies who are quicker or slower then the player. It actually took some work to make sure the steps are synced up :P Also I have a kind of complex AI script that has enemies spot and chase you and stuff but I felt it has too much interdependence on my event battler script and my move route scripts. Maybe sometime I will have to release a tech demo :P

Share this post


Link to post
Share on other sites

Hi, I'm totaly new to RM VXA and I was wodering how these scripts work? what do they do? I get the top one generates random dungeons but can you chose the size of the maps & the number of floors or are they random aswell? Because if they are I could really use this for my project.

 

as for the second one I don't even know what it does lol. Sorry for the noobish questions but like I said I am totaly new to this. I don't know anything at all about scripting & I still don't understand how to event yet(looking for good video tutorials if you know of any they would help allot).

 

Oh geez... sometimes I forget how convolutedly interdependent some of my scripts can be. One of the reason I don't release that many scripts that much. Oh well, it's good to figure out this stuff. Anyway try this event script:

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

Event stuff:

 

==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step + $game_variables[2]

n.times do |i|

add_random_enemy

end

(n / (rand(3)+1)).times do |i|

add_random_chest

end

end

 

def add_random_enemy

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

attr_accessor :room

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

Edited by Ragnar6645

Share this post


Link to post
Share on other sites

 

 






Don't worry, it wasn't your fault. It took me a minute but I suddenly remembered this being a problem when it was originally posted. I fixed the B's to b's & ran it again, but this time I ran into another problem:


Oh right, I actually had code for use with this script. Since then I moved it elsewhere, so here is a more current version:

I should post all of my dungeon scripts in my blog thingy sometime. I have a lot of sub-scripts. I have like nine scripts total dedicated to some aspect of dungeons (though a few are really short).

Added the corrected version but got a new error. This one is from the Entity Placement Script which I named RDG Event Control.


Oh geez... sometimes I forget how convolutedly interdependent some of my scripts can be. One of the reason I don't release that many scripts that much. Oh well, it's good to figure out this stuff. Anyway try this event script:

I do hope I am being helpful though. I don't mind looking into things I may have overlooked. That said, stuff like this is probably going to need touching up for you to use it the way you want, even when all the bugs are sorted out. So, yeah.

Honestly I am half-tempted to try to make my own dungeon generator, but I don't think I quite understand how it works enough. I mean I understand the basic theory (basically make a rectangle for the whole map and recursively divides it randomly, then makes a room for each rectangle and connect the rooms with corridors), but I don't feel I understand the details enough to really make my own (especially regarding the corridors). The actual entity placement stuff is much simpler really.

Hey BTW, do you want my turn-based movement script too? I completely rewrote it though (party because I already had a script I had been working on before finding Saba Kan's script)

I replaced the event control to the new one but got another error. When you say turn-based movement do mean the script where enemies on the map only move when you move? Because if that's the case then yes, I definately need that. But does it only work with the random dungeon generator or can I use it on regular maps too? Because this is the standard I wanna run in my dungeons.


Darn it Saba Kan, there you go putting unexpected things in the mini map script again. Also, my turn based movement script can be used on other maps sure, though I didn't really work too much on how. Right now I just have switch 1 enable it.

Event stuff:

==============================================================================
# - Dungeon Creation 6 (Events) KZ Edit
# @based on version 0.14 12/01/21 RGSS3
# @original author Saba Kan
# @translator kirinelf
#------------------------------------------------------------------------------
# Put all event logic here for easier access and stuff.
#==============================================================================

class Room

def put_to_random_place(event)
tiles = []
for i in @lx...@hx
for j in @ly...@hy
next if event.collide_with_characters?(i, j)
#next if i == $game_player.x && j == $game_player.y
next unless $game_map.floor?(i, j)
next unless $game_map.spawner_passable?(i, j)
next if @events[[i, j]] != nil
next if @couple_areas.include?([i, j])
tiles.push([i, j])
end
end
return false if tiles.empty?
key = tiles.sample
@events[key] = event
event.moveto(key[0], key[1])
return true
end

end

class Game_Map
attr_accessor :new_events

def setup_player_initial_position
put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)
end

def setup_dungeon_events
@next_enemy_event_id = 10000
@enemy_events = []
@chest_events = []

for event in @events.values
if event.event.name.include?("*")
@enemy_events.push(event.event)
self.events[event.id].erase
elsif event.event.name.include?("!")
@chest_events.push(event.event)
self.events[event.id].erase
else
put_to_random_place(event)
end
end
setup_enemy
end

def setup_enemy
$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0
return if @enemy_events.count == 0
n = @map.encounter_step + $game_variables[2]
n.times do |i|
add_random_enemy
end
(n / (rand(3)+1)).times do |i|
add_random_chest
end
end

def add_random_enemy
add_enemy(rand(@enemy_events.count))
end

def add_random_chest
add_chest(rand(@chest_events.count))
end

def add_enemy(event_id)
enemy_event = @enemy_events[event_id]
event = Game_Event.new(@map_id, enemy_event)

@new_events = {} unless @new_events
@new_events[@next_enemy_event_id] = event

event.event_id = @next_enemy_event_id
@next_enemy_event_id += 1
$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1
end

def add_chest(event_id)
chest_event = @chest_events[event_id]
event = Game_Event.new(@map_id, chest_event)

@new_events = {} unless @new_events
@new_events[@next_enemy_event_id] = event

event.event_id = @next_enemy_event_id
@next_enemy_event_id += 1
puts("Chest event "+chest_event.id.to_s+" created.")
end

alias saba_randomdungeon_update_events update_events
def update_events
saba_randomdungeon_update_events
if @new_events
for key in @new_events.keys
@events[key] = @new_events[key]
put_to_random_place(@events[key])
$game_minimap.add_event(@events[key]) if $game_minimap
end
end
@init_phase = false
end

def put_to_random_place(event)
return if event.nil?
if @init_phase
room_list = @room_list.select {|room| room.remain != 0 }
else
room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }
end
room_list.shuffle!
loop do
if room_list.empty?
msgbox("Could not place event "+event.id.to_s+"!")
break
end
room = room_list.pop
next if room.nil?
break if room.put_to_random_place(event)
end
end

def setup_starting_map_event
event = @events.values.find {|event| event.starting }
event.clear_starting_flag if event
@interpreter.setup(event.list, event.event_id) if event
event
end

def room(x, y)
for rect in @rect_list
if rect.room.contains(x, y)
return rect.room
end
end
return nil
end

def spawner_passable?(x, y)
return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||
(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||
(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||
(passable?(x, y, 8) && passable?(x, y - 1, 2))
return true
end

end

class Spriteset_Map

alias saba_dungeon_update update
def update
if $game_map.new_events
$game_map.new_events.values.each do |event|
@character_sprites.push(Sprite_Character.new(@viewport1, event))
end
$game_map.new_events = nil
end
saba_dungeon_update
end

end

class Sprite_Character

alias saba_dangeon_update update

def update
saba_dangeon_update
return unless $game_map.dungeon?
if @character.is_a?(Game_Event)
self.visible = false
if $game_player.room
self.visible = $game_player.room.contains(@character.x, @character.y)
@last_visible = self.visible
end
if $game_player.distance(@character) <= 1
self.visible = true
@last_visible = true
else
self.visible |= @last_visible
@last_visible = false
end
if @character.balloon_id != 0 || @character.animation_id != 0 ||
($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))
self.visible = true
@last_visible = true
end
@last_visible &= self.visible
end
end

end

class Game_Event
attr_reader :event
attr_accessor :event_id
attr_reader :erased

alias saba_dungeon_initialize initialize
def initialize(map_id, event)
saba_dungeon_initialize(map_id, event)
@event_id = event.id
end

def name
@event.name
end

alias saba_dungeon_erase erase
def erase
saba_dungeon_erase
return unless enemy?
$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1
end

def enemy?
return name.include?("*")
end

end

class Game_Player

attr_accessor :room

alias saba_dungeon_moveto moveto
def moveto(x, y)
saba_dungeon_moveto(x, y)
$game_map.setup_player_initial_position if $game_map.dungeon?
end

def distance(event)
min = $game_player.distance_xy_from(event.x, event.y)
return min unless $game_player.followers.visible
$game_player.followers.visible_folloers.each do |character|
dist = character.distance_xy_from(event.x, event.y)
if dist < min
min = dist
end
end
return min
end

end

class Game_Character

def distance_xy_from(x, y)
sx = distance_x_from(x)
sy = distance_y_from(y)
return [sx.abs, sy.abs].max
end

end



Turn based movement stuff (all mine :P)

#==============================================================================
# - Compleatly new turn based movement logic.
# Just because I liked my version better.
#==============================================================================

class Game_Map
def turnmode?
return true if dungeon?
return true if $game_switches[1]
return false
end
end

class Game_Event < Game_Character

attr_accessor :stop_steps
attr_accessor :alerted
attr_accessor :last_chase_x
attr_accessor :last_chase_y

alias_method :initialize_event_turnmove_base, :initialize
def initialize(map_id, event)
initialize_event_turnmove_base(map_id, event)
@movesync = false
@stop_steps = 0
@move_steps = 0
@alerted = nil
@last_chase_x = nil
@last_chase_y = nil
@chase_seen = false
end

alias_method :update_turnmove_base, :update
def update
@last_moving = moving?
update_turnmove_base
return unless $game_map.turnmode?
if @movesync || @last_moving
$game_player.movesync = true
@movesync = false
end
end

alias_method :update_stop_turnmove_base, :update_stop
def update_stop
update_stop_turnmove_base
return unless $game_map.turnmode?
if $game_player.start_move
@stop_steps -= 1
if @stop_steps < 0
if @move_route_forcing
@opacity = 255
@move_route_forcing = false
restore_move_route
end
@stop_steps = 5 - (@move_frequency - ($game_player.move_speed - @move_speed))
@move_steps = [1 + (@move_speed - $game_player.move_speed), 1].max
end
unless @alerted.nil?
@alerted = near_the_player? && alert?
end
@movesync = true
end
end

alias_method :update_self_movement_turnmove_base, :update_self_movement
def update_self_movement
return update_self_movement_turnmove_base unless $game_map.turnmode?
return unless ($game_player.moving? || @move_steps > 0) && @stop_steps <= 0
@movesync = true
update_self_movement_turnmove_base
@move_steps -= 1
end

def dash?
return super unless $game_map.turnmode?
return $game_player.dash?
end

def real_move_speed
return super unless $game_map.turnmode?
[@move_speed, $game_player.move_speed].max + (dash? ? 1 : 0)
end

alias_method :stop_count_threshold_turnmove_base, :stop_count_threshold
def stop_count_threshold
return stop_count_threshold_turnmove_base unless $game_map.turnmode?
0
end

end

class Game_Player
attr_accessor :movesync
attr_reader :start_move
attr_reader :end_move
attr_reader :stop_steps

alias_method :initialize_player_turnmove_base, :initialize
def initialize
initialize_player_turnmove_base
@movesync = true
@start_move = false
@end_move = true
@stop_steps = 0
end

alias_method :movable_turnmove_base?, :movable?
def movable?
if @movesync
@movesync = false
return false
end
return movable_turnmove_base?
end

alias_method :move_by_input_turnmove_base, :move_by_input
def move_by_input
unless $game_map.turnmode?
move_by_input_turnmove_base
return
end
if !movable? || $game_map.interpreter.running?
@start_move = false
return
end
if @stop_steps > 0
#puts("Player Stop: " + @stop_steps.to_s)
@stop_steps -= 1
@start_move = true
@movesync = true
return
end
unless @end_move
#puts("--Round End--")
@end_move = true
end
if Input.dir4 > 0
unless passable?(@x, @y, Input.dir4)
set_direction(Input.dir4)
check_event_trigger_touch_front
return
end
move_straight(Input.dir4)
@start_move = true
elsif Input.press?(:A)
@stop_steps += 1
@start_move = true
@movesync = true
else
@start_move = false
end
if @start_move
#puts("--Round Start--")
@end_move = false
end
end
end



Honestly I am not sure how good these scripts are in the long run.


Yeah, that's the problem with Saba Kan's script. On the page where you download it it says that the mini-map & turn based movement were 'optional' add-ons but instead they were required & I can't stand that eyesore of a mini-map. Anyway, replaced the event script & added the turn based movement script (BTW, you left out a # symbol on the 1st line of that event script) & got another error. This is definately a bumpy road trying to get this to work huh?

Hi, I'm totaly new to RM VXA and I was wodering how these scripts work? what do they do? I get the top one generates random dungeons but can you chose the size of the maps & the number of floors or are they random aswell? Because if they are I could really use this for my project.

as for the second one I don't even know what it does lol. Sorry for the noobish questions but like I said I am totaly new to this. I don't know anything at all about scripting & I still don't understand how to event yet(looking for good video tutorials if you know of any they would help allot).



This is a 'work in progress' right now since it hasn't been perfected yet. It generates a random dungeon floor each time you enter a map. This will apply to any maps that has a @ in the beginning of the Event Name. Those maps let you set the size & everything else accordingly. Each map is a single floor, so a whole multi-floor dungeon would consist of multiple maps connected together on the map tree (and connected by transfer events that move your characters from 1 map to another). The 2nd script is to make it so that enemies that walk around on the map only move when you move, which gives you time to think & possibly avoid battles as well. If you haven't learned the basics like switches, variables or eventing yet, then scripting is way out of your league.

I have a pretty good understanding of switches, variables & eventing but don't have the slightest clue when it comes to scripting. Scripting is for the pros who understand the Ruby Scripting Language. Guys like us are better off just asking professional scripters for help with scripts to make certain effects. This subject of a randomly generating dungeon is a tricky one & I've been asking for help with this for a while & most scripters don't want to take on the challange. I was worried that this effort would die out before somebody would help me, but thanks to KilloZapit, we may finally see a universal Random Dungeon Generator that anyone can use.

As for help in explaining the basics, think of switches as Binary code, 0's & 1's. A switch has 2 settings, On or Off. When you want the game to acknowledge something like a quest completed or a chest opened, you change a switch from off to on. Then you can make events check for & do things if that switch is on. Variables are for storing numbers to keep track of, like how many chests you've opened or the number of items you collected. You can have events check for & do things if that variable reaches a certain number. Eventing overall is simply understanding what the event options do & how to use them to manipulate the event to do what you want it to do. However, events can't handle everything we want them to & thats where scripting might be needed. Just look through the tutorial section for more help. I've rambled off-topic long enough. Anyway, hope all that helps. Edited by Animebryan

Share this post


Link to post
Share on other sites

Huh I assume that last is caused by having no enemies or chests on a level. Try this event script:

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step

n.times do |i|

add_random_enemy

end unless @enemy_events.empty?

(n / (rand(3)+1)).times do |i|

add_random_chest

end unless @chest_events.empty?

end

 

def add_random_enemy

return if @enemy_events.empty?

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

return if @chest_events.empty?

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

attr_accessor :room

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

Honestly I think I forgot to mention adding chest events at all! :P They work the same way as enemy events, only with a ! instead of a * in their names, and they don't quite spawn as much and don't respawn like enemies.

 

Also: Honestly I feel basic scripting is something designers should look into... Just because otherwise correcting tiny errors and making tiny changes is a pain. I don't think they should focus on it, but to know the basics is really helpful.

 

Edit: You know the ironic thing is, I actually like Saba Kan's minimap a fair bit... there were some bugs and stuff in it that I had to fix, but I find it nice. I might give the option to hide it or set a key to toggle it though.

 

Oh! And here is something I discovered: The map won't regenerate again unless you go to a different map. You can trick it by transferring to a dummy map and back though. This is something I will probably try to fix, but haven't yet.

 

Edit 2: Yeah, weird-ass stuff starts happening if I try to force the map to update without loading another map first. For now I just have a common even to fadeout, store the mapID, transfer to a small blank map, then back to the current map, then fade in again. It works well.

Edited by KilloZapit

Share this post


Link to post
Share on other sites

As for help in explaining the basics, think of switches as Binary code, 0's & 1's. A switch has 2 settings, On or Off. When you want the game to acknowledge something like a quest completed or a chest opened, you change a switch from off to on. Then you can make events check for & do things if that switch is on. Variables are for storing numbers to keep track of, like how many chests you've opened or the number of items you collected. You can have events check for & do things if that variable reaches a certain number. Eventing overall is simply understanding what the event options do & how to use them to manipulate the event to do what you want it to do. However, events can handle everything we want them to & thats where scripting might be needed. Just look through the tutorial section for more help. I've rambled off-topic long enough. Anyway, hope all that helps.

Thanks, that helped allot I think I understand switches, variables & eventing allot better now lol. I wish the tutorials people make started of by explaining things that simple cause if they did I'd have alot less headaches lol. Thanks again.

Share this post


Link to post
Share on other sites

Huh I assume that last is caused by having no enemies or chests on a level. Try this event script:

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step

n.times do |i|

add_random_enemy

end unless @enemy_events.empty?

(n / (rand(3)+1)).times do |i|

add_random_chest

end unless @chest_events.empty?

end

 

def add_random_enemy

return if @enemy_events.empty?

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

return if @chest_events.empty?

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

($game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

attr_accessor :room

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

 

Honestly I think I forgot to mention adding chest events at all! :P They work the same way as enemy events, only with a ! instead of a * in their names, and they don't quite spawn as much and don't respawn like enemies.

 

Also: Honestly I feel basic scripting is something designers should look into... Just because otherwise correcting tiny errors and making tiny changes is a pain. I don't think they should focus on it, but to know the basics is really helpful.

 

Edit: You know the ironic thing is, I actually like Saba Kan's minimap a fair bit... there were some bugs and stuff in it that I had to fix, but I find it nice. I might give the option to hide it or set a key to toggle it though.

 

Oh! And here is something I discovered: The map won't regenerate again unless you go to a different map. You can trick it by transferring to a dummy map and back though. This is something I will probably try to fix, but haven't yet.

 

Edit 2: Yeah, weird-ass stuff starts happening if I try to force the map to update without loading another map first. For now I just have a common even to fadeout, store the mapID, transfer to a small blank map, then back to the current map, then fade in again. It works well.

Saba Kan's script was set up so that you could just place events anywhere & the script would randomly place them around on it's own. The enemy events were also multiplied based on how many steps were set between encounters (lower right corner of map properties screen). So the event spawning should simply let you place however many events you want & then randomly place them around the map. His script also randomly selects where you spawn at on the map regardless of transfer location. As for basic scripting, I barely understand things like constants & editable content, as well as the fact that certain 'terms' in scripting need to be defined in order to function properly. Other than those, understanding the Ruby language seems challenging to me. To make it worse I can't access a webpage that teaches RGSS3 because my stupid local library is using that god awful Websense which is blocking it as a 'hacking' site, go figure.

 

As far Saba Kan's mini-map, that thing is an eyesore. For one, it's in the middle of the screen. it would be better off in a corner or something. Another thing, there's nothing 'Mini' about it. The dungeon maps I'm using are 100x100 which makes the 'Mini' map as big as the entire screen. The mini-map can't even handle the size of the map & doesn't fully cover the top or bottom sections of the map. As for generating a new map, I already knew you had to move to another map 1st. RPG Maker 2003 already had this feature & when I transfered to the same map it was the same layout. The best way to handle it was simply have 2 maps that randomly generate transfer you back & forth between the 2. The player would never know the difference.

 

I have a variable set to keep track of what Floor/Basement you're on & when you reach a certain range of basements the 2nd of the 2 maps would transfer you to a new pair of maps with a different theme & continue to go back & forth between the 2 maps. Transfering to a dummy map would probably just cause problems. Speaking of which, I have a new error for you to look at. I've replaced the event script & added !'s to my chest events (including other events such as recovery points & stairs leading down).

 

As for help in explaining the basics, think of switches as Binary code, 0's & 1's. A switch has 2 settings, On or Off. When you want the game to acknowledge something like a quest completed or a chest opened, you change a switch from off to on. Then you can make events check for & do things if that switch is on. Variables are for storing numbers to keep track of, like how many chests you've opened or the number of items you collected. You can have events check for & do things if that variable reaches a certain number. Eventing overall is simply understanding what the event options do & how to use them to manipulate the event to do what you want it to do. However, events can handle everything we want them to & thats where scripting might be needed. Just look through the tutorial section for more help. I've rambled off-topic long enough. Anyway, hope all that helps.

Thanks, that helped allot I think I understand switches, variables & eventing allot better now lol. I wish the tutorials people make started of by explaining things that simple cause if they did I'd have alot less headaches lol. Thanks again.

No problem. Glad to be of some help. I know how it feels to be a noob at this sort of thing, in fact I still am when it comes to scripting & such.

Share this post


Link to post
Share on other sites

Oopsy, yeah I forgot I added that little thing. Should be fixed below (Though that code has to do with events not being visible unless they are in the same room or close by, which you may not like),

 

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step

n.times do |i|

add_random_enemy

end unless @enemy_events.empty?

(n / (rand(3)+1)).times do |i|

add_random_chest

end unless @chest_events.empty?

end

 

def add_random_enemy

return if @enemy_events.empty?

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

return if @chest_events.empty?

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

(if $imported["KZ!-EventBattlers"] && $game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

attr_accessor :room

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

Share this post


Link to post
Share on other sites

Oopsy, yeah I forgot I added that little thing. Should be fixed below (Though that code has to do with events not being visible unless they are in the same room or close by, which you may not like),

 

 

 

#==============================================================================

# - Dungeon Creation 6 (Events) KZ Edit

# @based on version 0.14 12/01/21 RGSS3

# @original author Saba Kan

# @translator kirinelf

#------------------------------------------------------------------------------

# Put all event logic here for easier access and stuff.

#==============================================================================

 

class Room

 

def put_to_random_place(event)

tiles = []

for i in @lx...@hx

for j in @ly...@hy

next if event.collide_with_characters?(i, j)

#next if i == $game_player.x && j == $game_player.y

next unless $game_map.floor?(i, j)

next unless $game_map.spawner_passable?(i, j)

next if @events[[i, j]] != nil

next if @couple_areas.include?([i, j])

tiles.push([i, j])

end

end

return false if tiles.empty?

key = tiles.sample

@events[key] = event

event.moveto(key[0], key[1])

return true

end

 

end

 

class Game_Map

attr_accessor :new_events

 

def setup_player_initial_position

put_to_random_place($game_player) unless floor?($game_player.x, $game_player.y)

end

 

def setup_dungeon_events

@next_enemy_event_id = 10000

@enemy_events = []

@chest_events = []

 

for event in @events.values

if event.event.name.include?("*")

@enemy_events.push(event.event)

self.events[event.id].erase

elsif event.event.name.include?("!")

@chest_events.push(event.event)

self.events[event.id].erase

else

put_to_random_place(event)

end

end

setup_enemy

end

 

def setup_enemy

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] = 0

return if @enemy_events.count == 0

n = @map.encounter_step

n.times do |i|

add_random_enemy

end unless @enemy_events.empty?

(n / (rand(3)+1)).times do |i|

add_random_chest

end unless @chest_events.empty?

end

 

def add_random_enemy

return if @enemy_events.empty?

add_enemy(rand(@enemy_events.count))

end

 

def add_random_chest

return if @chest_events.empty?

add_chest(rand(@chest_events.count))

end

 

def add_enemy(event_id)

enemy_event = @enemy_events[event_id]

event = Game_Event.new(@map_id, enemy_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] += 1

end

 

def add_chest(event_id)

chest_event = @chest_events[event_id]

event = Game_Event.new(@map_id, chest_event)

 

@new_events = {} unless @new_events

@new_events[@next_enemy_event_id] = event

 

event.event_id = @next_enemy_event_id

@next_enemy_event_id += 1

puts("Chest event "+chest_event.id.to_s+" created.")

end

 

alias saba_randomdungeon_update_events update_events

def update_events

saba_randomdungeon_update_events

if @new_events

for key in @new_events.keys

@events[key] = @new_events[key]

put_to_random_place(@events[key])

$game_minimap.add_event(@events[key]) if $game_minimap

end

end

@init_phase = false

end

 

def put_to_random_place(event)

return if event.nil?

if @init_phase

room_list = @room_list.select {|room| room.remain != 0 }

else

room_list = @room_list.select {|room| room.remain != 0 && room != $game_player.room }

end

room_list.shuffle!

loop do

if room_list.empty?

msgbox("Could not place event "+event.id.to_s+"!")

break

end

room = room_list.pop

next if room.nil?

break if room.put_to_random_place(event)

end

end

 

def setup_starting_map_event

event = @events.values.find {|event| event.starting }

event.clear_starting_flag if event

@interpreter.setup(event.list, event.event_id) if event

event

end

 

def room(x, y)

for rect in @rect_list

if rect.room.contains(x, y)

return rect.room

end

end

return nil

end

 

def spawner_passable?(x, y)

return false unless (passable?(x, y, 2) && passable?(x, y + 1, 8)) ||

(passable?(x, y, 4) && passable?(x + 1, y, 6)) ||

(passable?(x, y, 6) && passable?(x - 1, y, 4)) ||

(passable?(x, y, 8) && passable?(x, y - 1, 2))

return true

end

 

end

 

class Spriteset_Map

 

alias saba_dungeon_update update

def update

if $game_map.new_events

$game_map.new_events.values.each do |event|

@character_sprites.push(Sprite_Character.new(@viewport1, event))

end

$game_map.new_events = nil

end

saba_dungeon_update

end

 

end

 

class Sprite_Character

 

alias saba_dangeon_update update

 

def update

saba_dangeon_update

return unless $game_map.dungeon?

if @character.is_a?(Game_Event)

self.visible = false

if $game_player.room

self.visible = $game_player.room.contains(@character.x, @character.y)

@last_visible = self.visible

end

if $game_player.distance(@character) <= 1

self.visible = true

@last_visible = true

else

self.visible |= @last_visible

@last_visible = false

end

if @character.balloon_id != 0 || @character.animation_id != 0 ||

(if $imported["KZ!-EventBattlers"] && $game_map.event_battlers != nil && $game_map.event_battlers.include?(@character))

self.visible = true

@last_visible = true

end

@last_visible &= self.visible

end

end

 

end

 

class Game_Event

attr_reader :event

attr_accessor :event_id

attr_reader :erased

 

alias saba_dungeon_initialize initialize

def initialize(map_id, event)

saba_dungeon_initialize(map_id, event)

@event_id = event.id

end

 

def name

@event.name

end

 

alias saba_dungeon_erase erase

def erase

saba_dungeon_erase

return unless enemy?

$game_variables[saba::Dungeon::ENEMY_COUNT_VARIABLE] -= 1

end

 

def enemy?

return name.include?("*")

end

 

end

 

class Game_Player

 

attr_accessor :room

 

alias saba_dungeon_moveto moveto

def moveto(x, y)

saba_dungeon_moveto(x, y)

$game_map.setup_player_initial_position if $game_map.dungeon?

end

 

def distance(event)

min = $game_player.distance_xy_from(event.x, event.y)

return min unless $game_player.followers.visible

$game_player.followers.visible_folloers.each do |character|

dist = character.distance_xy_from(event.x, event.y)

if dist < min

min = dist

end

end

return min

end

 

end

 

class Game_Character

 

def distance_xy_from(x, y)

sx = distance_x_from(x)

sy = distance_y_from(y)

return [sx.abs, sy.abs].max

end

 

end

 

Tried it. Got another error as soon as the program started.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted