• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • Eevee Expo's webhost has been having technical issues since Nov. 20th and you might be unable to connect to our site. Staff are also facing issues connecting, so please send a DM to Cat on-site or through Discord directly for faster service!
Resource icon

Resource Common Tiles (Common events for tiles) v1.0

Marin submitted a new resource:

Common Tiles (Common events for tiles) - When interacting with an event, you can tell it to call one (or more) common events.

That generic Nurse Joy event? The PC? A game corner machine? Whatever you can think of that's used multiple times (and doesn't change one bit) could be made a common event. Common events are global events that can be called from anywhere at any time.

That's useful, but what if it were possible to call those things without events? You wouldn't ever forget to place them, and you can also easily override the so-called "Common Tile" by placing an event on top of it. This cancels out the tile's...

Read more about this resource...
 

silentgamer64

Novice
Member
Joined
Jul 5, 2017
Posts
35
Depends. Does it even work with v16? If not, could you show me the error you get (if any)?
iwqwJS3.png

I'm running v16 and the script is not compatible with it. The only reason I ask is because I can tell from this error that the naming conventions in the code for the Debug menu have changed between v16 and v17. Actually the entire debug menu itself has been reorganized in v17.
 
iwqwJS3.png

I'm running v16 and the script is not compatible with it. The only reason I ask is because I can tell from this error that the naming conventions in the code for the Debug menu have changed between v16 and v17. Actually the entire debug menu itself has been reorganized in v17.

Oh, yeah. I'll see if I can do something to make it work.
 

Simeo

Normal-Type Self Proclamed Expert
Member
Joined
Jul 25, 2018
Posts
48
Hey ! Just a thank you message, it works perfectly you're a boss :)
 

Marina

Cooltrainer
Member
Joined
Mar 10, 2018
Posts
125
I was adding this and an error shows up when I wanted to add a common event:

---------------------------
Error
---------------------------
Script 'Common_Tiles' line 842: NoMethodError occurred.

undefined method `name' for nil:NilClass

from 'Common_Tiles' line 842 in `load_tileset'
from 'Common_Tiles' line 841 in `map'
from 'Common_Tiles' line 841 in `load_tileset'
from 'Common_Tiles' line 795 in `loop'
from 'Common_Tiles' line 869 in `load_tileset'
from 'Common_Tiles' line 734 in `initialize'
from 'Common_Tiles' line 721 in `loop'
from 'Common_Tiles' line 735 in `initialize'
from 'Common_Tiles' line 25 in `new'
from 'Common_Tiles' line 25 in `pbTilesetEditor'
from 'Common_Tiles' line 42 in `pbDebugMenuActions'
from 'Common_Tiles' line 42 in `pbFadeOutIn'
---------------------------
OK
---------------------------

and I am running Essentials v. 17.2
 

Simeo

Normal-Type Self Proclamed Expert
Member
Joined
Jul 25, 2018
Posts
48
I was adding this and an error shows up when I wanted to add a common event:

---------------------------
Error
---------------------------
Script 'Common_Tiles' line 842: NoMethodError occurred.

undefined method `name' for nil:NilClass

from 'Common_Tiles' line 842 in `load_tileset'
from 'Common_Tiles' line 841 in `map'
from 'Common_Tiles' line 841 in `load_tileset'
from 'Common_Tiles' line 795 in `loop'
from 'Common_Tiles' line 869 in `load_tileset'
from 'Common_Tiles' line 734 in `initialize'
from 'Common_Tiles' line 721 in `loop'
from 'Common_Tiles' line 735 in `initialize'
from 'Common_Tiles' line 25 in `new'
from 'Common_Tiles' line 25 in `pbTilesetEditor'
from 'Common_Tiles' line 42 in `pbDebugMenuActions'
from 'Common_Tiles' line 42 in `pbFadeOutIn'
---------------------------
OK
---------------------------

and I am running Essentials v. 17.2
Do you have marin utilities installed? (Check the resource again)
 

Marina

Cooltrainer
Member
Joined
Mar 10, 2018
Posts
125
Do you have marin utilities installed? (Check the resource again)
Yes, I have Marin Utilities and Common Tiles (after main):

# Whether or not you want to use these utility methods. Toggling this off will
# likely break your scripts. So don't do it unless you know what you're doing :)
USING_MARIN_UTILITY = true

# Whether or not you want the custom/better errors message.
SPECIAL_ERRORS = true



# These two settings only apply if SPECIAL_ERRORS is TRUE

DOUBLE_BACKTRACE = false # The interpreter already contains a small
# backtrace for errors in events and such by default.
# Settings this to false will not show the custom
# backtrace.

BACKTRACE_MAX_SIZE = 12 # The backtrace can go all the way from the very first
# call to the very last call. This is the limit as far
# as it can go back, because you could have a massive
# backtrace otherwise.


def pbMarinUtility
return USING_MARIN_UTILITY
end

if USING_MARIN_UTILITY

class Object
def get_variables
return self.instance_variables.map { |v| [v,self.method(v.to_s.gsub(/@/, "").to_sym).call] }
end

def set_variables(vars)
vars.each do |v|
self.method((v[0].to_s.gsub(/@/, "") + "=").to_sym).call(v[1])
end
end
end

# E.g. PokeBattle_Pokemon -> to_sym -> :PokeBattle_Pokemon
class Class
def to_sym
return self.to_s.to_sym
end
end

class NilClass
def empty?
return true
end
end

class Numeric
# Formats the number nicely (e.g. 1234567890 -> format() -> 1,234,567,890)
def format(separator = ',')
a = self.to_s.split('').reverse.breakup(3)
return a.map { |e| e.join('') }.join(separator).reverse
end

# Makes sure the returned string is at least n characters long
# (e.g. 4 -> to_digits -> "004")
# (e.g. 19 -> to_digits -> "019")
# (e.g. 123 -> to_digits -> "123")
def to_digits(n = 3)
str = self.to_s
return str if str.size >= n
ret = ""
(n - str.size).times { ret += "0" }
return ret + str
end

# n root of self. Defaults to 2 => square root.
def root(n = 2)
return (self ** (1.0 / n))
end

# Factorial
# 4 -> fact -> (4 * 3 * 2 * 1) -> 24
def fact
raise ArgumentError, "Cannot execute factorial on negative numerics" if self < 0
tot = 1
for i in 2..self
tot *= i
end
return tot
end

# Combinations
def ncr(k)
return (self.fact / (k.fact * (self - k).fact))
end

# k permutations of n (self)
def npr(k)
return (self.fact / (self - k).fact)
end

# Converts number to binary number (returns as string)
def to_b
return self.to_s(2)
end

def empty?
return false
end

def numeric?
return true
end
end

# Included in TrueClass and FalseClass to be able to call _.is_a?(Boolean)_
# true.is_a?(Boolean)
module Boolean end

class TrueClass
include Boolean

def to_i
return 1
end
end

# false.is_a?(Boolean)
class FalseClass
include Boolean

def to_i
return 0
end
end

# Calculates the total amount of elements in an Enumerable. Example:
# ["one","two","three"].fullsize #=> 11
module Enumerable
def fullsize
n = 0
for e in self
if e.is_a?(String)
n += e.size
elsif e.respond_to?(:fullsize)
n += e.fullsize
elsif e.respond_to?(:size) && !e.is_a?(Numeric)
n += e.size
else
n += 1
end
end
return n
end
end

class Array
# Returns a random element of the array
def random
return self[rand(self.size)]
end

# Shuffles the order of the array
def shuffle
indexes = []
new = []
while new.size != self.size
i = rand(self.size)
if !indexes.include?(i)
indexes << i
new << self
end
end
return new
end

# Shuffles the order of the array and replaces itself
def shuffle!
self.replace(shuffle)
end

# Breaks the array up every n elements
def breakup(n)
ret = []
for i in 0...self.size
ret[(i / n).floor] ||= []
ret[(i / n).floor] << self
end
return ret
end

# Breaks the array up every n elements and replaces itself
def breakup!(n)
self.replace(breakup(n))
end

# Swaps two elements' indexes
def swap(index1, index2)
new = self.clone
tmp = new[index2].clone
new[index2] = new[index1]
new[index1] = tmp
return new
end

# Swaps two elements' indexes and replaces itself
def swap!(index1, index2)
self.replace(swap(index1, index2))
end

# Returns whether or not the first element is equal to the passed argument
def starts_with?(e)
return self.first == e
end

# Returns whether or not the last element is equal to the passed argument
def ends_with?(e)
return self.last == e
end

# Does the same as <<, but concatenates if argument passed is an array
def +(var)
if var.is_a?(Array)
self.concat(var)
else
self << var
end
return self
end

# Deletes every instance of <var> in the array
def -(var)
if var.is_a?(Array)
var.each { |e| self.delete(e) if self.include?(e) }
else
self.delete(var) if self.include?(var)
end
return self
end

# Converts itself to a hash where possible
def to_hash(delete_nil_entries = false)
ret = {}
for i in 0...self.size
next if self.nil? && delete_nil_entries
ret = self
end
return ret
end

# If you have 8 elements, if true, grabs the 5th element, the 4rd if false.
# If you have 7 elements, grabs the 4th.
def mid(round_up = true)
i = (self.size - 1) / 2.0
i = i.ceil if round_up
return self.floor
end

# Returns the average of all elements in the array. Will throw errors on non-numerics.
# Skips <nil> entries.
def average
total = 0
self.each { |n| total += n unless n.nil? }
return total / self.compact.size.to_f
end

# Adds some aliases for <include?>: <has?>, <includes?>, <contains?>
alias has? include?
alias includes? include?
alias contains? include?

# Evaluates the block you pass it for every number between 0 and "slots".
# Example usage:
# Array.make_table { |i| i ** 2 }
# => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
# Array.make_table(10..16) { |i| i.to_s(2) }
# => ["1010", "1011", "1100", "1101", "1110", "1111", "10000"]
# (you can also pass it an array of values to iterate over)
def self.make_table(range = 1..10, &proc)
return range.map { |n| next proc.call(n) }
end

# If true:
# [0, 1, 3, 4, 5] -- etc
# If false:
# [0,1,2,3,4,5] -- etc
Json_Extra_Space_After_Entry = false

# Converts _self_ to a JSON string with an indent of Json_Indent_Width per layer.
def to_json(indent = Hash::Json_Indent_Width, inline = false)
return "[]" unless self.size > 0
full = "["
for i in 0...self.size
nl = false
if self.is_a?(Hash) || self.is_a?(Array)
val = self.to_json(indent + Hash::Json_Indent_Width, i == 0)
nl = !(inline && i == 0)
else
val = self
val = "\"#{val}\"" if val.is_a?(String)
nl = (self.fullsize > 24 || self.map { |e| e.class.to_sym }.include?(:Hash))
end
full += "\n" + " " * indent if nl
full += val.to_s + ","
full += " " if Json_Extra_Space_After_Entry
end
i = 2 + Json_Extra_Space_After_Entry.to_i
full = full[0..(-i)]
full += "\n#{" " * (indent - Hash::Json_Indent_Width)}" if self.fullsize > 24 ||
self.map { |e| e.class.to_sym }.include?(:Hash)
full += "]"
return full
end
end

class Hash
# Converts itself to an array where possible
def to_array(delete_nil_entries = false)
ret = []
keys = self.keys.sort
for key in keys
next if self[key].nil? && delete_nil_entries
ret[key] = self[key]
end
return ret
end

def compact
new = {}
for key in self.keys
new[key] = self[key] unless self[key].nil?
end
return new
end

def compact!
self.replace(compact)
end

# Amount of spaces per "layer" in the JSON.
Json_Indent_Width = 4

# Converts _self_ to a JSON string with an indent of Json_Indent_Width per layer.
def to_json(indent = Json_Indent_Width, _ = nil)
return "{}" if self.size == 0
full = "{"
keys = self.keys.sort do |a,b|
if $JSON_Sort_Order
if $JSON_Sort_Order.include?(a)
if $JSON_Sort_Order.include?(b)
next $JSON_Sort_Order.index(a) <=> $JSON_Sort_Order.index(b)
else
next -1
end
else
if $JSON_Sort_Order.include?(b)
next 1
end
# If neither are in the key, go alphabetical
end
end
if a.numeric?
if b.numeric?
next a <=> b
else
next -1
end
else
if b.numeric?
next 1
else
next a <=> b
end
end
end
for key in keys
if self[key].is_a?(Hash) || self[key].is_a?(Array)
val = self[key].to_json(indent + Json_Indent_Width, key == self.keys[0])
else
val = self[key]
val = "\"#{val}\"" if val.is_a?(String)
end
full += "\n#{" " * indent}\"#{key}\": #{val},"
end
full = full[0..-2]
full += "\n#{" " * (indent - Json_Indent_Width)}}"
return full
end
end

# String class extensions
class String
# Returns true if the string starts with the passed substring.
def starts_with?(str)
return false if !str.is_a?(String)
return false if str.size > self.size
return self[0...str.length] == str
end

# Returns true if the string ends with the passed substring.
def ends_with?(str)
return self.reverse.starts_with?(str.reverse)
end

# Converts to bits
def to_b
return self.unpack('b*')[0]
end

# Converts to bits and replaces itself
def to_b!
self.replace(to_b)
end

# Converts from bits
def from_b
return [self].pack('b*')
end

# Convert from bits and replaces itself
def from_b!
self.replace(from_b)
end

# Returns the first n characters
def first(n = 1)
return self.clone if n >= self.size
return self[0] if n == 1
return self[0...n]
end

# Returns the last n characters
def last(n = 1)
return self.clone if n >= self.size
return self[-1] if n == 1
return self.reverse[0...n].reverse
end

# Returns a random character from the string
def random
return self[rand(self.size)]
end

# Shuffles the order of the characters
def shuffle
return self.split("").shuffle.join("")
end

# Breaks the string up every _n_ characters
def breakup(n)
new = []
for i in 0...self.size
new[(i / n).floor] ||= ""
new[(i / n).floor] += self
end
return new
end

def empty?
return (self.size == 0)
end

def numeric?
i = 0
for e in self.split("")
next if i == 0 && e == "-"
return false unless [0,1,2,3,4,5,6,7,8,9].map { |n| n.to_s }.include?(e)
end
return true
end

# Deflates itself and returns the result
def deflate
return Zlib::Deflate.deflate(self)
end

# Deflates and replaces itself
def deflate!
self.replace(deflate)
end

# Inflates itself and returns the result
def inflate
return Zlib::Inflate.inflate(self)
end

# Inflates and replaces itself
def inflate!
self.replace(inflate)
end

# Adds some aliases for <include?>: <has?>, <includes?>, <contains?>
alias has? include?
alias includes? include?
alias contains? include?
end

# File class extensions
class File
# Copies the source file to the destination path.
def self.copy(source, destination)
data = ""
t = Time.now
File.open(source, 'rb') do |f|
while r = f.read(4096)
if Time.now - t > 1
Graphics.update
t = Time.now
end
data += r
end
end
File.delete(destination) if File.file?(destination)
f = File.new(destination, 'wb')
f.write data
f.close
end

# Renames the old file to be the new file. //exact same as File::move
def self.rename(old, new)
File.move(old, new)
end

# Copies the source to the destination and deletes the source.
def self.move(source, destination)
File.copy(source, destination)
File.delete(source)
end

# Reads the file's data and inflates it with Zlib
def self.inflate(file)
data = ""
t = Time.now
File.open(file, 'rb') do |f|
while r = f.read(4096)
if Time.now - t > 1
Graphics.update
t = Time.now
end
data += r
end
end
data.inflate!
File.delete(file)
f = File.new(file, 'wb')
f.write data
f.close
return data
end

# Reads the file's data and deflates it with Zlib
def self.deflate(file)
data = ""
t = Time.now
File.open(file, 'rb') do |f|
while r = f.read(4096)
if Time.now - t > 1
Graphics.update
t = Time.now
end
data += r
end
end
data.deflate!
File.delete(file)
f = File.new(file, 'wb')
f.write data
f.close
return data
end

# Note: This is VERY basic compression and should NOT serve as encryption.
# Compresses all specified files into one, big package
def self.compress(outfile, files, delete_files = true)
start = Time.now
files = [files] unless files.is_a?(Array)
for i in 0...files.size
if !File.file?(files)
raise "Could not find part of the path `#{files}`"
end
end
files.breakup(500) # 500 files per compressed file
full = ""
t = Time.now
for i in 0...files.size
if Time.now - t > 1
Graphics.update
t = Time.now
end
data = ""
File.open(files, 'rb') do |f|
while r = f.read(4096)
if Time.now - t > 1
Graphics.update
t = Time.now
end
data += r
end
end
File.delete(files) if delete_files
full += "#{data.size}|#{files}|#{data}"
full += "|" if i != files.size - 1
end
File.delete(outfile) if File.file?(outfile)
f = File.new(outfile, 'wb')
f.write full.deflate
f.close
return Time.now - start
end

# Decompresses files compressed with File.compress
def self.decompress(filename, delete_package = true)
start = Time.now
data = ""
t = Time.now
File.open(filename, 'rb') do |f|
while r = f.read(4096)
if Time.now - t > 1
Graphics.update
t = Time.now
end
data += r
end
end
data.inflate!
loop do
size, name = data.split('|')
data = data.split(size + "|" + name + "|")[1..-1].join(size + "|" + name + "|")
size = size.to_i
content = data[0...size]
data = data[(size + 1)..-1]
File.delete(name) if File.file?(name)
f = File.new(name, 'wb')
f.write content
f.close
break if !data || data.size == 0 || data.split('|').size <= 1
end
File.delete(filename) if delete_package
return Time.now - start
end

# Creates all directories that don't exist in the given path, as well as the
# file. If given a second argument, it'll write that to the file.
def self.create(path, data = nil)
start = Time.now
Dir.create(path.split('/')[0..-2].join('/'))
f = File.new(path, 'wb')
f.write data if data && data.size > 0
f.close
return Time.now - start
end
end

# Dir class extensions
class Dir
class << Dir
alias marin_delete delete
end

# Returns all files in the targeted path
def self.get_files(path, recursive = true)
return Dir.get_all(path, recursive).select { |path| File.file?(path) }
end

# Returns all directories in the targeted path
def self.get_dirs(path, recursive = true)
return Dir.get_all(path, recursive).select { |path| File.directory?(path) }
end

# Returns all files and directories in the targeted path
def self.get_all(path, recursive = true)
files = []
Dir.foreach(path) do |f|
next if f == "." || f == ".."
if File.directory?(path + "/" + f) && recursive
files.concat(Dir.get_files(path + "/" + f))
end
files << path + "/" + f
end
return files
end

# Deletes a directory and all files/directories within, unless non_empty is false
def self.delete(path, non_empty = true)
if non_empty
for file in Dir.get_all(path)
if File.directory?(file)
Dir.delete(file, non_empty)
elsif File.file?(file)
File.delete(file)
end
end
end
marin_delete(path)
end

# Creates all directories that don't exist in the given path.
def self.create(path)
split = path.split('/')
for i in 0...split.size
Dir.mkdir(split[0..i].join('/')) unless File.directory?(split[0..i].join('/'))
end
end
end


# Sprite class extensions
class Sprite
# Shorthand for initializing a bitmap by path, bitmap, or width/height:
# -> bmp("Graphics/Pictures/bag")
# -> bmp(32, 32)
# -> bmp(some_other_bitmap)
def bmp(arg1 = nil, arg2 = nil)
if arg1
if arg2
arg1 = Graphics.width if arg1 == -1
arg2 = Graphics.height if arg2 == -1
self.bitmap = Bitmap.new(arg1, arg2)
elsif arg1.is_a?(Bitmap)
self.bitmap = arg1.clone
else
self.bitmap = Bitmap.new(arg1)
end
else
return self.bitmap
end
end

# Alternative to bmp(path):
# -> bmp = "Graphics/Pictures/bag"
def bmp=(arg1)
bmp(arg1)
end

# Usage:
# -> [x] # Sets sprite.x to x
# -> [x,y] # Sets sprite.x to x and sprite.y to y
# -> [x,y,z] # Sets sprite.x to x and sprite.y to y and sprite.z to z
# -> [nil,y] # Sets sprite.y to y
# -> [nil,nil,z] # Sets sprite.z to z
# -> [x,nil,z] # Sets sprite.x to x and sprite.z to z
# Etc.
def xyz=(args)
self.x = args[0] || self.x
self.y = args[1] || self.y
self.z = args[2] || self.z
end

# Returns the x, y, and z coordinates in the xyz=(args) format, [x,y,z]
def xyz
return [self.x,self.y,self.z]
end

# Centers the sprite by setting the origin points to half the width and height
def center_origins
return if !self.bitmap
self.ox = self.bitmap.width / 2
self.oy = self.bitmap.height / 2
end

# Returns the sprite's full width, taking zoom_x into account
def fullwidth
return self.bitmap.width.to_f * self.zoom_x
end

# Returns the sprite's full height, taking zoom_y into account
def fullheight
return self.bitmap.height.to_f * self.zoom_y
end
end

class TextSprite < Sprite
# Sets up the sprite and bitmap. You can also pass text to draw
# either an array of arrays, or an array containing the normal "parameters"
# for drawing text:
# [text,x,y,align,basecolor,shadowcolor]
def initialize(viewport = nil, text = nil, width = -1, height = -1)
super(viewport)
@width = width
@height = height
self.bmp(@width, @height)
pbSetSystemFont(self.bmp)
if text.is_a?(Array)
if text[0].is_a?(Array)
pbDrawTextPositions(self.bmp,text)
else
pbDrawTextPositions(self.bmp,[text])
end
end
end

# Clears the bitmap (and thus all drawn text)
def clear
self.bmp.clear
pbSetSystemFont(self.bmp)
end

# You can also pass text to draw either an array of arrays, or an array
# containing the normal "parameters" for drawing text:
# [text,x,y,align,basecolor,shadowcolor]
def draw(text, clear = false)
self.clear if clear
if text[0].is_a?(Array)
pbDrawTextPositions(self.bmp,text)
else
pbDrawTextPositions(self.bmp,[text])
end
end

# Draws text with outline
# [text,x,y,align,basecolor,shadowcolor]
def draw_outline(text, clear = false)
self.clear if clear
if text[0].is_a?(Array)
for e in text
pbDrawOutlineText(self.bmp,e[1],e[2],640,480,e[0],e[4],e[5],e[3])
end
else
e = text
pbDrawOutlineText(self.bmp,e[1],e[2],640,480,e[0],e[4],e[5],e[3])
end
end

# Draws and breaks a line if the width is exceeded
# [text,x,y,width,numlines,basecolor,shadowcolor]
def draw_ex(text, clear = false)
self.clear if clear
if text[0].is_a?(Array)
for e in text
drawTextEx(self.bmp,e[1],e[2],e[3],e[4],e[0],e[5],e[6])
end
else
e = text
drawTextEx(self.bmp,e[1],e[2],e[3],e[4],e[0],e[5],e[6])
end
end

# Clears and disposes the sprite
def dispose
clear
super
end
end

# A better alternative to the typical @sprites = {}
class SpriteHash
attr_reader :x
attr_reader :y
attr_reader :z
attr_reader :visible
attr_reader :opacity

def initialize
@hash = {}
@x = 0
@y = 0
@z = 0
@visible = true
@opacity = 255
end

# Returns the object in the specified key
def [](key)
key = key.to_sym if key.respond_to?(:to_sym) && !key.is_a?(Numeric)
return @hash[key]
end

# Sets an object in specified key to the specified value
def []=(key, value)
key = key.to_sym if key.respond_to?(:to_sym) && !key.is_a?(Numeric)
add(key, value)
end

# Returns the raw hash
def raw
return @hash
end

# Returns the keys in the hash
def keys
return @hash.keys
end

def length; return self.size; end
def count; return self.size; end

# Returns the amount of keys in the hash
def size
return @hash.keys.size
end

# Clones the hash
def clone
return @hash.clone
end

# Adds an object to the specified key
def add(key, value)
clear_disposed
key = key.to_sym if key.respond_to?(:to_sym) && !key.is_a?(Numeric)
@hash[key] if @hash[key] && @hash[key].respond_to?(:dispose)
@hash[key] = value
clear_disposed
end

# Deletes an object in the specified key
def delete(key)
key = key.to_sym if key.respond_to?(:to_sym) && !key.is_a?(Numeric)
@hash[key] = nil
clear_disposed
end

# Iterates over all sprites
def each
clear_disposed
@hash.each { |s| yield s[1] if block_given? }
end

# Updates all sprites
def update
clear_disposed
for key in @hash.keys
@hash[key].update if @hash[key].respond_to?(:update)
end
end

# Disposes all sprites
def dispose
clear_disposed
for key in @hash.keys
@hash[key].dispose if @hash[key].respond_to?(:dispose)
end
clear_disposed
end

# Compatibility
def disposed?
return false
end

# Changes x on all sprites
def x=(value)
clear_disposed
for key in @hash.keys
@hash[key].x += value - @x
end
@x = value
end

# Changes y on all sprites
def y=(value)
clear_disposed
for key in @hash.keys
@hash[key].y += value - @y
end
@y = value
end

# Changes z on all sprites
def z=(value)
clear_disposed
for key in @hash.keys
@hash[key].z += value - @z
end
@z = value
end

# Changes visibility on all sprites
def visible=(value)
clear_disposed
for key in @hash.keys
@hash[key].visible = value
end
end

# Changes opacity on all sprites
def opacity=(value)
clear_disposed
for key in @hash.keys
@hash[key].opacity += value - @opacity
end
@opacity = [0,value,255].sort[1]
end

# Fades out all sprites
def hide(frames = 16)
clear_disposed
frames.times do
Graphics.update
Input.update
for key in @hash.keys
@hash[key].opacity -= 255 / frames.to_f
end
end
@opacity = 0
end

# Fades in all sprites
def show(frames = 16)
clear_disposed
frames.times do
Graphics.update
Input.update
for key in @hash.keys
@hash[key].opacity += 255 / frames.to_f
end
end
@opacity = 255
end

# Deletes all disposed sprites from the hash
def clear_disposed
for key in @hash.keys
if (@hash[key].disposed? rescue true)
@hash[key] = nil
@hash.delete(key)
end
end
end

# Renames the old key to the new key
def rename(old, new)
self[new] = self[old]
delete(old)
end
end


# Stand-alone methods

# Fades in a black overlay
def showBlk(n = 16)
return if $blkVp || $blk
$blkVp = Viewport.new(0,0,DEFAULTSCREENWIDTH,DEFAULTSCREENHEIGHT)
$blkVp.z = 9999999
$blk = Sprite.new($blkVp)
$blk.bmp(-1,-1)
$blk.bitmap.fill_rect(0,0,DEFAULTSCREENWIDTH,DEFAULTSCREENHEIGHT,Color.new(0,0,0))
$blk.opacity = 0
for i in 0...(n + 1)
Graphics.update
Input.update
yield i if block_given?
$blk.opacity += 256 / n.to_f
end
end

# Fades out and disposes a black overlay
def hideBlk(n)
return if !$blk || !$blkVp
for i in 0...(n + 1)
Graphics.update
Input.update
yield i if block_given?
$blk.opacity -= 256 / n.to_f
end
$blk.dispose
$blk = nil
$blkVp.dispose
$blkVp = nil
end

# Returns the percentage of exp the Pokémon has compared to the next level
def pbGetExpPercentage(pokemon)
pokemon = pokemon.pokemon if pokemon.respond_to?("pokemon")
startexp = PBExperience.pbGetStartExperience(pokemon.level, pokemon.growthrate)
endexp = PBExperience.pbGetStartExperience(pokemon.level + 1, pokemon.growthrate)
return (pokemon.exp - startexp).to_f / (endexp - startexp).to_f
end

alias oldrand rand
def rand(a = nil, b = nil)
if a.is_a?(Range)
l = a.min
u = a.max
return l + oldrand(u - l + 1)
elsif a.is_a?(Numeric)
if b.is_a?(Numeric)
return a + oldrand(b - a)
else
return oldrand(a)
end
elsif a.nil?
if b
return rand(b)
else
return oldrand(2)
end
end
end

# Input module extensions
module Input
# Returns true if any of the buttons below are pressed
def self.any?
return true if defined?(Game_Mouse) && $mouse && $mouse.click?
keys = [Input::C,Input::B,Input::LEFT,Input::RIGHT,Input::UP,Input::DOWN,
# 0-9, a-z
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x50,0x51,0x52,0x53,
0x54,0x55,0x56,0x57,0x58,0x59,0x5A]
for key in keys
return true if Input.triggerex?(key)
end
return false
end
end





if SPECIAL_ERRORS

MessageBox = Win32API.new('user32', 'MessageBox', ['I','P','P','I'], 'I')

def p_msg(msg, title = nil, icon = nil)
case icon
when :error, :err
uType = 0x10
title ||= "Error"
when :q, :question, :ask
uType = 0x20
title ||= "Question"
when :warning, :warn
uType = 0x30
title ||= "Warning"
when :inform, :info, :information
uType = 0x40
title ||= "Info"
else
uType = 0
title ||= "Pokémon"
end
hwnd = Win32API.pbFindRgssWindow
Graphics.update
t = Thread.new { MessageBox.call(hwnd, msg, title, uType); Thread.exit }
while t.status
Graphics.update
end
end

def p_err(ex = $!, message = nil)
if $Rescue
raise
return
end
if ex.is_a?(String)
ex = RuntimeError.new ex
elsif ex.is_a?(Class)
ex = ex.new
end
trace = ex.backtrace || caller
script_id = trace[0][7..-1].split(':')[0].to_i
script = $RGSS_SCRIPTS[script_id][1]
line = trace[0].split(':')[1].to_i
msg = "Script '#{script}' line #{line}: #{ex.class} occurred."
if message || ex.message != ex.class.to_s
if message
msg << "\n\n#{message}"
else
msg << "\n\n#{ex.message}"
message = ex.message
end
end
showtrace = (trace.size > 2)
showtrace = false if !DOUBLE_BACKTRACE && message.include?(':in `')
if showtrace
msg << "\n\n"
msg << trace[0...BACKTRACE_MAX_SIZE].map do |e|
sID = e.split(':')[0][7..-1]
if sID.numeric?
sID = sID.to_i
s = "'" + $RGSS_SCRIPTS[sID][1] + "'"
else
s = "eval"
end
line = e.split(':')[1].to_i
code = e.split(':')[2..-1].join(':')
str = "from #{s} line #{line}"
str << " #{code}" unless code.empty?
next str
end.join("\n")
end
p_msg(msg, "Error", :err)
Kernel.exit! true
end

def p_info(msg, title = nil)
p_msg(msg, title, :info)
end

def p_warn(msg, title = nil)
p_msg(msg, title, :warn)
end

def p_question(msg, title = nil)
p_msg(msg, title, :question)
end

trace_var(:$scene, proc do |object|
break unless object
unless object.instance_variable_get(:@__old_main)
object.instance_variable_set(:@__old_main, object.method(:main))
def object.main
self.instance_variable_get(:@__old_main).call
rescue
p_err
end
end
end)

else

def p_err(*args)
raise *args
end

end # if SPECIAL_ERRORS


def pbGetActiveEventPage(event, mapid = nil)
mapid ||= event.map.map_id if event.respond_to?(:map)
pages = (event.is_a?(RPG::Event) ? event.pages : event.instance_eval { @event.pages })
for i in 0...pages.size
c = pages[pages.size - 1 - i].condition
ss = !(c.self_switch_valid && !$game_self_switches[[mapid,
event.id,c.self_switch_ch]])
sw1 = !(c.switch1_valid && !$game_switches[c.switch1_id])
sw2 = !(c.switch2_valid && !$game_switches[c.switch2_id])
var = true
if c.variable_valid
if !c.variable_value || !$game_variables[c.variable_id].is_a?(Numeric) ||
$game_variables[c.variable_id] < c.variable_value
var = false
end
end
if ss && sw1 && sw2 && var # All conditions are met
return pages[pages.size - 1 - i]
end
end
return nil
end



end # if USING_MARIN_UTILITY



#==============================================================================#
# Common Tiles #
# by Marin #
#==============================================================================#
# Instructions #
# #
# This editor allows you to trigger common events simply by interacting with #
# a tile -- no events are needed. #
# #
# Each tile has an array of common event IDs. Whenever you interact with a #
# tile, it'll try to trigger all common events of all three layers, UNLESS #
# the tile has an event on it. Events essentially "override" these common #
# events. #
# #
# Whenever it tries to call common events on a tile, it will call everything #
# in a certain, logical order: #
# Between layers: 3 -> 2 -> 1 #
# Between one tile's common events: First added -> last added #
#==============================================================================#
# Please give credit when using this. #
#==============================================================================#

# The function to call to open the editor
def pbTilesetEditor
TilesetEditor.new
end

if defined?(ERRORTEXT)
# Aliasing the Debug menu to add this editor
alias ct_debug_menu_cmds pbDebugMenuCommands
def pbDebugMenuCommands(showall = true)
cmds = ct_debug_menu_cmds(showall)
cmds.add("editorsmenu","tilesets",_INTL("Edit Common Tiles"),
_INTL("Edit the common events of tiles."))
return cmds
end

# Aliasing the Debug menu to add this editor
alias ct_debug_actions pbDebugMenuActions
def pbDebugMenuActions(cmd = "", sprites = nil, viewport = nil)
if cmd == "tilesets"
pbFadeOutIn(99999) { pbTilesetEditor }
return
end
ct_debug_actions(cmd, sprites, viewport)
end
else
def pbDebugMenu
viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
viewport.z=99999
sprites={}
commands=CommandList.new
commands.add("switches",_INTL("Switches"))
commands.add("variables",_INTL("Variables"))
commands.add("refreshmap",_INTL("Refresh Map"))
commands.add("warp",_INTL("Warp to Map"))
commands.add("healparty",_INTL("Heal Party"))
commands.add("additem",_INTL("Add Item"))
commands.add("fillbag",_INTL("Fill Bag"))
commands.add("clearbag",_INTL("Empty Bag"))
commands.add("addpokemon",_INTL("Add Pokémon"))
commands.add("fillboxes",_INTL("Fill Storage Boxes"))
commands.add("clearboxes",_INTL("Clear Storage Boxes"))
commands.add("usepc",_INTL("Use PC"))
commands.add("setplayer",_INTL("Set Player Character"))
commands.add("renameplayer",_INTL("Rename Player"))
commands.add("randomid",_INTL("Randomise Player's ID"))
commands.add("changeoutfit",_INTL("Change Player Outfit"))
commands.add("setmoney",_INTL("Set Money"))
commands.add("setcoins",_INTL("Set Coins"))
commands.add("setbadges",_INTL("Set Badges"))
commands.add("demoparty",_INTL("Give Demo Party"))
commands.add("toggleshoes",_INTL("Toggle Running Shoes Ownership"))
commands.add("togglepokegear",_INTL("Toggle Pokégear Ownership"))
commands.add("togglepokedex",_INTL("Toggle Pokédex Ownership"))
commands.add("dexlists",_INTL("Dex List Accessibility"))
commands.add("readyrematches",_INTL("Ready Phone Rematches"))
commands.add("mysterygift",_INTL("Manage Mystery Gifts"))
commands.add("daycare",_INTL("Day Care Options..."))
commands.add("quickhatch",_INTL("Quick Hatch"))
commands.add("roamerstatus",_INTL("Roaming Pokémon Status"))
commands.add("roam",_INTL("Advance Roaming"))
commands.add("setencounters",_INTL("Set Encounters"))
commands.add("setmetadata",_INTL("Set Metadata"))
commands.add("terraintags",_INTL("Set Terrain Tags"))
commands.add("trainertypes",_INTL("Edit Trainer Types"))
commands.add("resettrainers",_INTL("Reset Trainers"))
commands.add("testwildbattle",_INTL("Test Wild Battle"))
commands.add("testdoublewildbattle",_INTL("Test Double Wild Battle"))
commands.add("testtrainerbattle",_INTL("Test Trainer Battle"))
commands.add("testdoubletrainerbattle",_INTL("Test Double Trainer Battle"))
commands.add("relicstone",_INTL("Relic Stone"))
commands.add("purifychamber",_INTL("Purify Chamber"))
commands.add("extracttext",_INTL("Extract Text"))
commands.add("compiletext",_INTL("Compile Text"))
commands.add("compiledata",_INTL("Compile Data"))
commands.add("mapconnections",_INTL("Map Connections"))
commands.add("animeditor",_INTL("Animation Editor"))
commands.add("debugconsole",_INTL("Debug Console"))
commands.add("togglelogging",_INTL("Toggle Battle Logging"))
commands.add("commontiles",_INTL("Edit Common Tiles"))
sprites["cmdwindow"]=Window_CommandPokemonEx.new(commands.list)
cmdwindow=sprites["cmdwindow"]
cmdwindow.viewport=viewport
cmdwindow.resizeToFit(cmdwindow.commands)
cmdwindow.height=Graphics.height if cmdwindow.height>Graphics.height
cmdwindow.x=0
cmdwindow.y=0
cmdwindow.visible=true
pbFadeInAndShow(sprites)
ret=-1
loop do
loop do
cmdwindow.update
Graphics.update
Input.update
if Input.trigger?(Input::B)
ret=-1
break
end
if Input.trigger?(Input::C)
ret=cmdwindow.index
break
end
end
break if ret==-1
cmd=commands.getCommand(ret)
if cmd=="switches"
pbFadeOutIn(99999) { pbDebugScreen(0) }
elsif cmd=="variables"
pbFadeOutIn(99999) { pbDebugScreen(1) }
elsif cmd=="refreshmap"
$game_map.need_refresh = true
Kernel.pbMessage(_INTL("The map will refresh."))
elsif cmd=="warp"
map=pbWarpToMap()
if map
pbFadeOutAndHide(sprites)
pbDisposeSpriteHash(sprites)
viewport.dispose
if $scene.is_a?(Scene_Map)
$game_temp.player_new_map_id=map[0]
$game_temp.player_new_x=map[1]
$game_temp.player_new_y=map[2]
$game_temp.player_new_direction=2
$scene.transfer_player
$game_map.refresh
else
Kernel.pbCancelVehicles
$MapFactory.setup(map[0])
$game_player.moveto(map[1],map[2])
$game_player.turn_down
$game_map.update
$game_map.autoplay
$game_map.refresh
end
return
end
elsif cmd=="healparty"
for i in $Trainer.party
i.heal
end
Kernel.pbMessage(_INTL("Your Pokémon were healed."))
elsif cmd=="additem"
item=pbListScreen(_INTL("ADD ITEM"),ItemLister.new(0))
if item && item>0
params=ChooseNumberParams.new
params.setRange(1,BAGMAXPERSLOT)
params.setInitialValue(1)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("Choose the number of items."),params
)
if qty>0
if qty==1
Kernel.pbReceiveItem(item)
else
Kernel.pbMessage(_INTL("The item was added."))
$PokemonBag.pbStoreItem(item,qty)
end
end
end
elsif cmd=="fillbag"
params=ChooseNumberParams.new
params.setRange(1,BAGMAXPERSLOT)
params.setInitialValue(1)
params.setCancelValue(0)
qty=Kernel.pbMessageChooseNumber(
_INTL("Choose the number of items."),params
)
if qty>0
itemconsts=[]
for i in PBItems.constants
itemconsts.push(PBItems.const_get(i))
end
itemconsts.sort!{|a,b| a<=>b}
for i in itemconsts
$PokemonBag.pbStoreItem(i,qty)
end
Kernel.pbMessage(_INTL("The Bag was filled with {1} of each item.",qty))
end
elsif cmd=="clearbag"
$PokemonBag.clear
Kernel.pbMessage(_INTL("The Bag was cleared."))
elsif cmd=="addpokemon"
species=pbChooseSpeciesOrdered(1)
if species!=0
params=ChooseNumberParams.new
params.setRange(1,PBExperience::MAXLEVEL)
params.setInitialValue(5)
params.setCancelValue(0)
level=Kernel.pbMessageChooseNumber(
_INTL("Set the Pokémon's level."),params)
if level>0
pbAddPokemon(species,level)
end
end
elsif cmd=="fillboxes"
$Trainer.formseen=[] if !$Trainer.formseen
$Trainer.formlastseen=[] if !$Trainer.formlastseen
added=0; completed=true
for i in 1..PBSpecies.maxValue
if added>=STORAGEBOXES*30
completed=false; break
end
cname=getConstantName(PBSpecies,i) rescue nil
next if !cname
pkmn=PokeBattle_Pokemon.new(i,50,$Trainer)
$PokemonStorage[(i-1)/$PokemonStorage.maxPokemon(0),
(i-1)%$PokemonStorage.maxPokemon(0)]=pkmn
$Trainer.seen=true
$Trainer.owned=true
$Trainer.formlastseen=[] if !$Trainer.formlastseen
$Trainer.formlastseen=[0,0] if $Trainer.formlastseen==[]
$Trainer.formseen=[[],[]] if !$Trainer.formseen
for j in 0..27
$Trainer.formseen[0][j]=true
$Trainer.formseen[1][j]=true
end
added+=1
end
Kernel.pbMessage(_INTL("Boxes were filled with one Pokémon of each species."))
if !completed
Kernel.pbMessage(_INTL("Note: The number of storage spaces ({1} boxes of 30) is less than the number of species.",STORAGEBOXES))
end
elsif cmd=="clearboxes"
for i in 0...$PokemonStorage.maxBoxes
for j in 0...$PokemonStorage.maxPokemon(i)
$PokemonStorage[i,j]=nil
end
end
Kernel.pbMessage(_INTL("The Boxes were cleared."))
elsif cmd=="usepc"
pbPokeCenterPC
elsif cmd=="setplayer"
limit=0
for i in 0...8
meta=pbGetMetadata(0,MetadataPlayerA+i)
if !meta
limit=i
break
end
end
if limit<=1
Kernel.pbMessage(_INTL("There is only one player defined."))
else
params=ChooseNumberParams.new
params.setRange(0,limit-1)
params.setDefaultValue($PokemonGlobal.playerID)
newid=Kernel.pbMessageChooseNumber(
_INTL("Choose the new player character."),params)
if newid!=$PokemonGlobal.playerID
pbChangePlayer(newid)
Kernel.pbMessage(_INTL("The player character was changed."))
end
end
elsif cmd=="renameplayer"
trname=pbEnterPlayerName("Your name?",0,7,$Trainer.name)
if trname==""
trainertype=pbGetPlayerTrainerType
gender=pbGetTrainerTypeGender(trainertype)
trname=pbSuggestTrainerName(gender)
end
$Trainer.name=trname
Kernel.pbMessage(_INTL("The player's name was changed to {1}.",$Trainer.name))
elsif cmd=="randomid"
$Trainer.id=rand(256)
$Trainer.id|=rand(256)<<8
$Trainer.id|=rand(256)<<16
$Trainer.id|=rand(256)<<24
Kernel.pbMessage(_INTL("The player's ID was changed to {1} (2).",$Trainer.publicID,$Trainer.id))
elsif cmd=="changeoutfit"
oldoutfit=$Trainer.outfit
params=ChooseNumberParams.new
params.setRange(0,99)
params.setDefaultValue(oldoutfit)
$Trainer.outfit=Kernel.pbMessageChooseNumber(_INTL("Set the player's outfit."),params)
Kernel.pbMessage(_INTL("Player's outfit was changed.")) if $Trainer.outfit!=oldoutfit
elsif cmd=="setmoney"
params=ChooseNumberParams.new
params.setMaxDigits(6)
params.setDefaultValue($Trainer.money)
$Trainer.money=Kernel.pbMessageChooseNumber(
_INTL("Set the player's money."),params)
Kernel.pbMessage(_INTL("You now have ${1}.",$Trainer.money))
elsif cmd=="setcoins"
params=ChooseNumberParams.new
params.setRange(0,MAXCOINS)
params.setDefaultValue($PokemonGlobal.coins)
$PokemonGlobal.coins=Kernel.pbMessageChooseNumber(
_INTL("Set the player's Coin amount."),params)
Kernel.pbMessage(_INTL("You now have {1} Coins.",$PokemonGlobal.coins))
elsif cmd=="setbadges"
badgecmd=0
loop do
badgecmds=[]
for i in 0...32
badgecmds.push(_INTL("{1} Badge {2}",$Trainer.badges ? "[Y]" : "[ ]",i+1))
end
badgecmd=Kernel.pbShowCommands(nil,badgecmds,-1,badgecmd)
break if badgecmd<0
$Trainer.badges[badgecmd]=!$Trainer.badges[badgecmd]
end
elsif cmd=="demoparty"
pbCreatePokemon
Kernel.pbMessage(_INTL("Filled party with demo Pokémon."))
elsif cmd=="toggleshoes"
$PokemonGlobal.runningShoes=!$PokemonGlobal.runningShoes
Kernel.pbMessage(_INTL("Gave Running Shoes.")) if $PokemonGlobal.runningShoes
Kernel.pbMessage(_INTL("Lost Running Shoes.")) if !$PokemonGlobal.runningShoes
elsif cmd=="togglepokegear"
$Trainer.pokegear=!$Trainer.pokegear
Kernel.pbMessage(_INTL("Gave Pokégear.")) if $Trainer.pokegear
Kernel.pbMessage(_INTL("Lost Pokégear.")) if !$Trainer.pokegear
elsif cmd=="togglepokedex"
$Trainer.pokedex=!$Trainer.pokedex
Kernel.pbMessage(_INTL("Gave Pokédex.")) if $Trainer.pokedex
Kernel.pbMessage(_INTL("Lost Pokédex.")) if !$Trainer.pokedex
elsif cmd=="dexlists"
dexescmd=0
loop do
dexescmds=[]
d=pbDexNames
for i in 0...d.length
name=d
name=name[0] if name.is_a?(Array)
dexindex=i
unlocked=$PokemonGlobal.pokedexUnlocked[dexindex]
dexescmds.push(_INTL("{1} {2}",unlocked ? "[Y]" : "[ ]",name))
end
dexescmd=Kernel.pbShowCommands(nil,dexescmds,-1,dexescmd)
break if dexescmd<0
dexindex=dexescmd
if $PokemonGlobal.pokedexUnlocked[dexindex]
pbLockDex(dexindex)
else
pbUnlockDex(dexindex)
end
end
elsif cmd=="readyrematches"
if !$PokemonGlobal.phoneNumbers || $PokemonGlobal.phoneNumbers.length==0
Kernel.pbMessage(_INTL("There are no trainers in the Phone."))
else
for i in $PokemonGlobal.phoneNumbers
if i.length==8 # A trainer with an event
i[4]=2
pbSetReadyToBattle(i)
end
end
Kernel.pbMessage(_INTL("All trainers in the Phone are now ready to rebattle."))
end
elsif cmd=="mysterygift"
pbManageMysteryGifts
elsif cmd=="daycare"
daycarecmd=0
loop do
daycarecmds=[
_INTL("Summary"),
_INTL("Deposit Pokémon"),
_INTL("Withdraw Pokémon"),
_INTL("Generate egg"),
_INTL("Collect egg"),
_INTL("Dispose egg")
]
daycarecmd=Kernel.pbShowCommands(nil,daycarecmds,-1,daycarecmd)
break if daycarecmd<0
case daycarecmd
when 0 # Summary
if $PokemonGlobal.daycare
num=pbDayCareDeposited
Kernel.pbMessage(_INTL("{1} Pokémon are in the Day Care.",num))
if num>0
txt=""
for i in 0...num
next if !$PokemonGlobal.daycare[0]
pkmn=$PokemonGlobal.daycare[0]
initlevel=$PokemonGlobal.daycare[1]
gender=[_INTL("♂"),_INTL("♀"),_INTL("genderless")][pkmn.gender]
txt+=_INTL("{1}) {2} ({3}), Lv.{4} (deposited at Lv.{5})",
i,pkmn.name,gender,pkmn.level,initlevel)
txt+="\n" if i<num-1
end
Kernel.pbMessage(txt)
end
if $PokemonGlobal.daycareEgg==1
Kernel.pbMessage(_INTL("An egg is waiting to be picked up."))
elsif pbDayCareDeposited==2
if pbDayCareGetCompat==0
Kernel.pbMessage(_INTL("The deposited Pokémon can't breed."))
else
Kernel.pbMessage(_INTL("The deposited Pokémon can breed."))
end
end
end
when 1 # Deposit Pokémon
if pbEggGenerated?
Kernel.pbMessage(_INTL("Egg is available, can't deposit Pokémon."))
elsif pbDayCareDeposited==2
Kernel.pbMessage(_INTL("Two Pokémon are deposited already."))
elsif $Trainer.party.length==0
Kernel.pbMessage(_INTL("Party is empty, can't desposit Pokémon."))
else
pbChooseNonEggPokemon(1,3)
if pbGet(1)>=0
pbDayCareDeposit(pbGet(1))
Kernel.pbMessage(_INTL("Deposited {1}.",pbGet(3)))
end
end
when 2 # Withdraw Pokémon
if pbEggGenerated?
Kernel.pbMessage(_INTL("Egg is available, can't withdraw Pokémon."))
elsif pbDayCareDeposited==0
Kernel.pbMessage(_INTL("No Pokémon are in the Day Care."))
elsif $Trainer.party.length>=6
Kernel.pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
else
pbDayCareChoose(_INTL("Which one do you want back?"),1)
if pbGet(1)>=0
pbDayCareGetDeposited(pbGet(1),3,4)
pbDayCareWithdraw(pbGet(1))
Kernel.pbMessage(_INTL("Withdrew {1}.",pbGet(3)))
end
end
when 3 # Generate egg
if $PokemonGlobal.daycareEgg==1
Kernel.pbMessage(_INTL("An egg is already waiting."))
elsif pbDayCareDeposited!=2
Kernel.pbMessage(_INTL("There aren't 2 Pokémon in the Day Care."))
elsif pbDayCareGetCompat==0
Kernel.pbMessage(_INTL("The Pokémon in the Day Care can't breed."))
else
$PokemonGlobal.daycareEgg=1
Kernel.pbMessage(_INTL("An egg is now waiting in the Day Care."))
end
when 4 # Collect egg
if $PokemonGlobal.daycareEgg!=1
Kernel.pbMessage(_INTL("There is no egg available."))
elsif $Trainer.party.length>=6
Kernel.pbMessage(_INTL("Party is full, can't collect the egg."))
else
pbDayCareGenerateEgg
$PokemonGlobal.daycareEgg=0
$PokemonGlobal.daycareEggSteps=0
Kernel.pbMessage(_INTL("Collected the {1} egg.",
PBSpecies.getName($Trainer.party[$Trainer.party.length-1].species)))
end
when 5 # Dispose egg
if $PokemonGlobal.daycareEgg!=1
Kernel.pbMessage(_INTL("There is no egg available."))
else
$PokemonGlobal.daycareEgg=0
$PokemonGlobal.daycareEggSteps=0
Kernel.pbMessage(_INTL("Disposed of the egg."))
end
end
end
elsif cmd=="quickhatch"
for pokemon in $Trainer.party
pokemon.eggsteps=1 if pokemon.isEgg?
end
Kernel.pbMessage(_INTL("All eggs on your party now require one step to hatch."))
elsif cmd=="roamerstatus"
if RoamingSpecies.length==0
Kernel.pbMessage(_INTL("No roaming Pokémon defined."))
else
text="\\l[8]"
for i in 0...RoamingSpecies.length
poke=RoamingSpecies
if $game_switches[poke[2]]
status=$PokemonGlobal.roamPokemon
if status==true
if $PokemonGlobal.roamPokemonCaught
text+=_INTL("{1} (Lv.{2}) caught.",
PBSpecies.getName(getID(PBSpecies,poke[0])),poke[1])
else
text+=_INTL("{1} (Lv.{2}) defeated.",
PBSpecies.getName(getID(PBSpecies,poke[0])),poke[1])
end
else
curmap=$PokemonGlobal.roamPosition
if curmap
mapinfos=$RPGVX ? load_data("Data/MapInfos.rvdata") : load_data("Data/MapInfos.rxdata")
text+=_INTL("{1} (Lv.{2}) roaming on map {3} ({4}){5}",
PBSpecies.getName(getID(PBSpecies,poke[0])),poke[1],curmap,
mapinfos[curmap].name,(curmap==$game_map.map_id) ? _INTL("(this map)") : "")
else
text+=_INTL("{1} (Lv.{2}) roaming (map not set).",
PBSpecies.getName(getID(PBSpecies,poke[0])),poke[1])
end
end
else
text+=_INTL("{1} (Lv.{2}) not roaming (switch {3} is off).",
PBSpecies.getName(getID(PBSpecies,poke[0])),poke[1],poke[2])
end
text+="\n" if i<RoamingSpecies.length-1
end
Kernel.pbMessage(text)
end
elsif cmd=="roam"
if RoamingSpecies.length==0
Kernel.pbMessage(_INTL("No roaming Pokémon defined."))
else
pbRoamPokemon(true)
$PokemonGlobal.roamedAlready=false
Kernel.pbMessage(_INTL("Pokémon have roamed."))
end
elsif cmd=="setencounters"
encdata=load_data("Data/encounters.dat")
oldencdata=Marshal.dump(encdata)
mapedited=false
map=pbDefaultMap()
loop do
map=pbListScreen(_INTL("SET ENCOUNTERS"),MapLister.new(map))
break if map<=0
mapedited=true if map==pbDefaultMap()
pbEncounterEditorMap(encdata,map)
end
save_data(encdata,"Data/encounters.dat")
pbSaveEncounterData()
pbClearData()
elsif cmd=="setmetadata"
pbMetadataScreen(pbDefaultMap())
pbClearData()
elsif cmd=="terraintags"
pbFadeOutIn(99999) { pbTilesetScreen }
elsif cmd=="trainertypes"
pbFadeOutIn(99999) { pbTrainerTypeEditor }
elsif cmd=="resettrainers"
if $game_map
for event in $game_map.events.values
if event.name[/Trainer\(\d+\)/]
$game_self_switches[[$game_map.map_id,event.id,"A"]]=false
$game_self_switches[[$game_map.map_id,event.id,"B"]]=false
end
end
$game_map.need_refresh=true
Kernel.pbMessage(_INTL("All Trainers on this map were reset."))
else
Kernel.pbMessage(_INTL("This command can't be used here."))
end
elsif cmd=="testwildbattle"
species=pbChooseSpeciesOrdered(1)
if species!=0
params=ChooseNumberParams.new
params.setRange(1,PBExperience::MAXLEVEL)
params.setInitialValue(5)
params.setCancelValue(0)
level=Kernel.pbMessageChooseNumber(
_INTL("Set the Pokémon's level."),params)
if level>0
pbWildBattle(species,level)
end
end
elsif cmd=="testdoublewildbattle"
Kernel.pbMessage(_INTL("Choose the first Pokémon."))
species1=pbChooseSpeciesOrdered(1)
if species1!=0
params=ChooseNumberParams.new
params.setRange(1,PBExperience::MAXLEVEL)
params.setInitialValue(5)
params.setCancelValue(0)
level1=Kernel.pbMessageChooseNumber(
_INTL("Set the first Pokémon's level."),params)
if level1>0
Kernel.pbMessage(_INTL("Choose the second Pokémon."))
species2=pbChooseSpeciesOrdered(1)
if species2!=0
params=ChooseNumberParams.new
params.setRange(1,PBExperience::MAXLEVEL)
params.setInitialValue(5)
params.setCancelValue(0)
level2=Kernel.pbMessageChooseNumber(
_INTL("Set the second Pokémon's level."),params)
if level2>0
pbDoubleWildBattle(species1,level1,species2,level2)
end
end
end
end
elsif cmd=="testtrainerbattle"
battle=pbListScreen(_INTL("SINGLE TRAINER"),TrainerBattleLister.new(0,false))
if battle
trainerdata=battle[1]
pbTrainerBattle(trainerdata[0],trainerdata[1],"...",false,trainerdata[4],true)
end
elsif cmd=="testdoubletrainerbattle"
battle1=pbListScreen(_INTL("DOUBLE TRAINER 1"),TrainerBattleLister.new(0,false))
if battle1
battle2=pbListScreen(_INTL("DOUBLE TRAINER 2"),TrainerBattleLister.new(0,false))
if battle2
trainerdata1=battle1[1]
trainerdata2=battle2[1]
pbDoubleTrainerBattle(trainerdata1[0],trainerdata1[1],trainerdata1[4],"...",
trainerdata2[0],trainerdata2[1],trainerdata2[4],"...",
true)
end
end
elsif cmd=="relicstone"
pbRelicStone()
elsif cmd=="purifychamber"
pbPurifyChamber()
elsif cmd=="extracttext"
pbExtractText
elsif cmd=="compiletext"
pbCompileTextUI
elsif cmd=="compiledata"
msgwindow=Kernel.pbCreateMessageWindow
pbCompileAllData(true) {|msg| Kernel.pbMessageDisplay(msgwindow,msg,false) }
Kernel.pbMessageDisplay(msgwindow,_INTL("All game data was compiled."))
Kernel.pbDisposeMessageWindow(msgwindow)
elsif cmd=="mapconnections"
pbFadeOutIn(99999) { pbEditorScreen }
elsif cmd=="animeditor"
pbFadeOutIn(99999) { pbAnimationEditor }
elsif cmd=="debugconsole"
Console::setup_console
elsif cmd=="togglelogging"
$INTERNAL=!$INTERNAL
Kernel.pbMessage(_INTL("Debug logs for battles will be made in the Data folder.")) if $INTERNAL
Kernel.pbMessage(_INTL("Debug logs for battles will not be made.")) if !$INTERNAL
elsif cmd == "commontiles"
pbFadeOutIn(99999) { pbTilesetEditor }
end
end
pbFadeOutAndHide(sprites)
pbDisposeSpriteHash(sprites)
viewport.dispose
end
end

# RPG::Tileset#common_events is what stores the common events
module RPG
class Tileset
attr_writer :common_events

alias common_event_init initialize
def initialize(*args)
common_event_init(*args)
@common_events ||= [nil] * (@priorities.xsize - 384)
end

def common_events
@common_events ||= [nil] * (@priorities.xsize - 384)
return @common_events
end
end
end

# Returns this map's tileset
class Game_Map
def tileset
return $data_tilesets[@map.tileset_id]
end
end

# Overwrite Game_Player#check_event_trigger_there to call any common events
class Game_Player
alias ct_check_there check_event_trigger_there
def check_event_trigger_there(triggers)
ret = ct_check_there(triggers)
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
return ret if $game_player.map.events.any? { |e| e[1].x == new_x && e[1].y == new_y }
return ret unless $game_map.valid?(new_x, new_y)
common_events = []
for i in [2, 1, 0]
tile_id = $game_player.map.data[new_x, new_y, i]
tile_id -= 384
if $game_player.map.tileset.common_events[tile_id]
for j in 0...$game_player.map.tileset.common_events[tile_id].size
common_events << $game_player.map.tileset.common_events[tile_id][j]
end
end
end
for c in common_events
pbCommonEvent(c)
end
return ret
end
end

class TilesetEditor
SelectorColor = Color.new(239,52,52) # The color of the tile selector
SelectorWidth = 3 # How many pixels the tile selector should be wide

def initialize
# Initialize a new Viewport for all graphical elements
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z = 99999
# Black overlay
@blk = Sprite.new(@viewport)
@blk.bmp(-1,-1)
@blk.bmp.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
@blk.z = -1
# Load all tilesets from Data/Tilesets
@data = File.open('Data/Tilesets.rxdata', 'rb') do |f|
next Marshal.load(f)[1..-1] # Ignore the first entry, nil
end
# Which tileset is selected
@sel = 0
loop do
@sel = choose_tileset # Pick a tileset
if @sel == -1
if Kernel.pbConfirmMessage("Save before exiting?")
File.delete('Data/Tilesets.rxdata') if File.file?('Data/Tilesets.rxdata')
f = File.new('Data/Tilesets.rxdata', 'wb')
Marshal.dump([nil].concat(@data), f)
f.close
Kernel.pbMessage("For the changes to take effect, please close RPG" +
" Maker <b>without saving</b> the project.")
end
break
end
load_tileset # Load the sprite, initialize a selector sprite and call main
end
@blk.dispose
@blk = nil
@viewport.dispose
@viewport = nil
end

# Picks a tileset from all tilesets
def choose_tileset
cmds = []
@data.each_with_index { |e,i| cmds << "#{i + 1}: #{e.name}" }
Kernel.pbMessage("Choose a Tileset to edit.", cmds, -1)
end

# Gets the array of terrain tags per tile
def get_terrain_tags(tileset = @data[@sel])
tags = tileset.terrain_tags
new = []
for x in 384...tags.xsize
new << tags[x]
end
return new
end

# Gets the array of priority values per tile
def get_priorities(tileset = @data[@sel])
pr = tileset.priorities
new = []
for x in 384...pr.xsize
new << pr[x]
end
return new
end

def load_tileset(tileset = @data[@sel])
# Create the tileset's sprite
@tileset = Sprite.new(@viewport)
@tileset.bmp("Graphics/Tilesets/" + tileset.tileset_name)
@selector = make_selector
@current = Sprite.new(@viewport)
@current.bmp(@tileset.bmp)
@current.src_rect.width = 32
@current.src_rect.height = 32
@current.zoom_x = 2
@current.zoom_y = 2
@current.x = @tileset.bmp.width + (Graphics.width - @tileset.bmp.width) / 2
@current.y = Graphics.height / 2
@current.x -= 32
@current.y -= 32
@x = 0
@y = 0
@txt = TextSprite.new(@viewport,[
["Terrain Tag: #{get_terrain_tags[0]}", @current.x + 32, @current.y + 70,
2, Color.new(255,255,255)],
["Priority: #{get_priorities[0]}", @current.x + 32, @current.y + 100,
2, Color.new(255,255,255)],
["Common Events: #{@data[@sel].common_events[0].size rescue 0}",
@current.x + 32, @current.y + 130, 2, Color.new(255,255,255)],
["Tile ID: #{@x + 8 * @y + 384}", @current.x + 32, @current.y + 160, 2, Color.new(255,255,255)]
])
loop do
Graphics.update
Input.update
old_x = @x
old_y = @y
refresh = false
if Input.repeat?(Input::RIGHT) && @x % 8 < 7
@selector.x += 32
@x += 1
end
if Input.repeat?(Input::LEFT) && @x % 8 > 0
@selector.x -= 32
@x -= 1
end
if Input.repeat?(Input::DOWN) && @y < @tileset.bmp.height / 32 - 1
if @selector.y >= Graphics.height - 32
@tileset.y -= 32
else
@selector.y += 32
end
@y += 1
end
if Input.repeat?(Input::UP) && @y > 0
if @selector.y <= 0
@tileset.y += 32
else
@selector.y -= 32
end
@y -= 1
end
if Input.trigger?(Input::C)
options = []
options << "Add Common Event"
options << "Show Common events" if (@data[@sel].common_events[@x + @y * 8].size > 0 rescue false)
options << "Cancel"
cmd = Kernel.pbMessage("What do want to do with this tile?", options, 2)
next if cmd == -1
if cmd == 0 # Add Common Event
params = ChooseNumberParams.new
params.setMaxDigits(3)
id = Kernel.pbMessageChooseNumber("Enter the ID of the common event you'd like to assign " +
"to this tile.", params)
@data[@sel].common_events[@x + @y * 8] ||= []
@data[@sel].common_events[@x + @y * 8] << id
refresh = true
elsif cmd == 1 && options.size == 3 # Show Common events
display = @data[@sel].common_events[@x + @y * 8].map do |e|
next "#{e}: #{$data_common_events[e].name}"
end
cmd = Kernel.pbMessage("These are all common events assigned to this event.",
display, -1)
break if cmd == -1
if Kernel.pbConfirmMessage("Do you want to delete common event \"<b>#{display[cmd]}</b>\"?")
@data[@sel].common_events[@x + @y * 8][cmd] = nil
@data[@sel].common_events[@x + @y * 8].compact!
refresh = true
end
end
end
if @x != old_x || @y != old_y || refresh
@current.src_rect.x = @x * 32
@current.src_rect.y = @y * 32
@txt.clear
@txt.draw([
["Terrain Tag: #{get_terrain_tags[@x + @y * 8]}", @current.x + 32,
@current.y + 70, 2, Color.new(255,255,255)],
["Priority: #{get_priorities[@x + @y * 8]}", @current.x + 32,
@current.y + 100, 2, Color.new(255,255,255)],
["Common Events: #{@data[@sel].common_events[@x + @y * 8].size rescue 0}",
@current.x + 32, @current.y + 130, 2, Color.new(255,255,255)],
["Tile ID: #{@x + 8 * @y + 384}", @current.x + 32, @current.y + 160, 2, Color.new(255,255,255)]
])
end
break if Input.trigger?(Input::B)
end
@tileset.dispose
@tileset = nil
@selector.dispose
@selector = nil
@current.dispose
@current = nil
@txt.dispose
@txt = nil
Input.update
end

# Creates a sprite used as the selector and returns it
def make_selector
selector = Sprite.new(@viewport)
selector.bmp(32,32)
selector.bmp.fill_rect(0,0,32,SelectorWidth,SelectorColor)
selector.bmp.fill_rect(0,0,SelectorWidth,32,SelectorColor)
selector.bmp.fill_rect(32 - SelectorWidth,0,32,32,SelectorColor)
selector.bmp.fill_rect(0,32- SelectorWidth,32,32,SelectorColor)
return selector
end
end
 

Fobby

local weirdo
Member
Joined
Oct 21, 2020
Posts
61
Quick question: does it work for events you have to touch, like arrow tiles?
 

boonzeet

Developer of Pokemon: Secrets of the Ages
Member
Joined
Mar 13, 2019
Posts
70
Will this script ever be updated to v19.1? Thank you o:

I've attached below an unofficial update for this script to work for v19:
Ruby:
Expand Collapse Copy
#==============================================================================#
#                               Common Tiles                                   #
#                                 by Marin                                     #
#==============================================================================#
#                               Instructions                                   #
#                                                                              #
#  This editor allows you to trigger common events simply by interacting with  #
#                     a tile -- no events are needed.                          #
#                                                                              #
#   Each tile has an array of common event IDs. Whenever you interact with a   #
#   tile, it'll try to trigger all common events of all three layers, UNLESS   #
#   the tile has an event on it. Events essentially "override" these common    #
#                                  events.                                     #
#                                                                              #
#  Whenever it tries to call common events on a tile, it will call everything  #
#                         in a certain, logical order:                         #
#                         Between layers: 3 -> 2 -> 1                          #
#          Between one tile's common events: First added -> last added         #
#==============================================================================#
#                    Please give credit when using this.                       #
#==============================================================================#
PluginManager.register({
  :name => "Common Tiles",
  :version => "1.3",
  :credits => "Marin",
  :link => "https://eeveeexpo.com/resources/166/",
})
# The function to call to open the editor
def pbTilesetEditor
  TilesetEditor.new
end
DebugMenuCommands.register("editcommontiles", {
  "parent" => "editorsmenu",
  "name" => _INTL("Edit Common Tiles"),
  "description" => _INTL("Edit the common events of tiles."),
  "effect" => proc {
    pbFadeOutIn(99999) { pbTilesetEditor }
  },
})
# RPG::Tileset#common_events is what stores the common events
module RPG
  class Tileset
    attr_writer :common_events
    alias common_event_init initialize
    def initialize(*args)
      common_event_init(*args)
      @common_events ||= [nil] * (@priorities.xsize - 384)
    end
    def common_events
      @common_events ||= [nil] * (@priorities.xsize - 384)
      return @common_events
    end
  end
end
# Returns this map's tileset
class Game_Map
  def tileset
    return $data_tilesets[@map.tileset_id]
  end
end
# Overwrite Game_Player#check_event_trigger_there to call any common events
class Game_Player
  alias ct_check_there check_event_trigger_there
  def check_event_trigger_there(triggers)
    ret = ct_check_there(triggers)
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    return ret if $game_player.map.events.any? { |e| e[1].x == new_x && e[1].y == new_y }
    return ret unless $game_map.valid?(new_x, new_y)
    common_events = []
    for i in [2, 1, 0]
      tile_id = $game_player.map.data[new_x, new_y, i]
      tile_id -= 384
      if $game_player.map.tileset.common_events[tile_id]
        for j in 0...$game_player.map.tileset.common_events[tile_id].size
          common_events << $game_player.map.tileset.common_events[tile_id][j]
        end
      end
    end
    for c in common_events
      pbCommonEvent(c)
    end
    return ret
  end
end
class TilesetEditor
  SelectorColor = Color.new(239, 52, 52) # The color of the tile selector
  SelectorWidth = 3 # How many pixels the tile selector should be wide
  def initialize
    # Initialize a new Viewport for all graphical elements
    @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
    @viewport.z = 99999
    # Black overlay
    @blk = Sprite.new(@viewport)
    @blk.bmp(-1, -1)
    @blk.bmp.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0, 0, 0))
    @blk.z = -1
    # Load all tilesets from Data/Tilesets
    @data = File.open("Data/Tilesets.rxdata", "rb") do |f|
      next Marshal.load(f)[1..-1] # Ignore the first entry, nil
    end
    # Which tileset is selected
    @sel = 0
    loop do
      @sel = choose_tileset # Pick a tileset
      if @sel == -1
        if Kernel.pbConfirmMessage("Save before exiting?")
          File.delete("Data/Tilesets.rxdata") if File.file?("Data/Tilesets.rxdata")
          f = File.new("Data/Tilesets.rxdata", "wb")
          Marshal.dump([nil].concat(@data), f)
          f.close
          Kernel.pbMessage("For the changes to take effect, please close RPG" +
                           " Maker <b>without saving</b> the project.")
        end
        break
      end
      load_tileset # Load the sprite, initialize a selector sprite and call main
    end
    @blk.dispose
    @blk = nil
    @viewport.dispose
    @viewport = nil
  end
  # Picks a tileset from all tilesets
  def choose_tileset
    cmds = []
    @data.each_with_index { |e, i| cmds << "#{i + 1}: #{e.name}" }
    Kernel.pbMessage("Choose a Tileset to edit.", cmds, -1)
  end
  # Gets the array of terrain tags per tile
  def get_terrain_tags(tileset = @data[@sel])
    tags = tileset.terrain_tags
    new = []
    for x in 384...tags.xsize
      new << tags[x]
    end
    return new
  end
  # Gets the array of priority values per tile
  def get_priorities(tileset = @data[@sel])
    pr = tileset.priorities
    new = []
    for x in 384...pr.xsize
      new << pr[x]
    end
    return new
  end
  def load_tileset(tileset = @data[@sel])
    # Create the tileset's sprite
    @tileset = Sprite.new(@viewport)
    @tileset.bmp("Graphics/Tilesets/" + tileset.tileset_name)
    @selector = make_selector
    @current = Sprite.new(@viewport)
    @current.bmp(@tileset.bmp)
    @current.src_rect.width = 32
    @current.src_rect.height = 32
    @current.zoom_x = 2
    @current.zoom_y = 2
    @current.x = @tileset.bmp.width + (Graphics.width - @tileset.bmp.width) / 2
    @current.y = Graphics.height / 2
    @current.x -= 32
    @current.y -= 32
    @x = 0
    @y = 0
    @txt = TextSprite.new(@viewport, [
      ["Terrain Tag: #{get_terrain_tags[0]}", @current.x + 32, @current.y + 70,
       2, Color.new(255, 255, 255)],
      ["Priority: #{get_priorities[0]}", @current.x + 32, @current.y + 100,
       2, Color.new(255, 255, 255)],
      ["Common Events: #{@data[@sel].common_events[0] ? @data[@sel].common_events[0].size : 0}",
       @current.x + 32, @current.y + 130, 2, Color.new(255, 255, 255)],
      ["Tile ID: #{@x + 8 * @y + 384}", @current.x + 32, @current.y + 160, 2, Color.new(255, 255, 255)],
    ])
    loop do
      Graphics.update
      Input.update
      old_x = @x
      old_y = @y
      refresh = false
      if Input.repeat?(Input::RIGHT) && @x % 8 < 7
        @selector.x += 32
        @x += 1
      end
      if Input.repeat?(Input::LEFT) && @x % 8 > 0
        @selector.x -= 32
        @x -= 1
      end
      if Input.repeat?(Input::DOWN) && @y < @tileset.bmp.height / 32 - 1
        if @selector.y >= Graphics.height - 32
          @tileset.y -= 32
        else
          @selector.y += 32
        end
        @y += 1
      end
      if Input.repeat?(Input::UP) && @y > 0
        if @selector.y <= 0
          @tileset.y += 32
        else
          @selector.y -= 32
        end
        @y -= 1
      end
      if Input.trigger?(Input::C)
        options = []
        options << "Add Common Event"
        options << "Show Common events" if (@data[@sel].common_events[@x + @y * 8] && @data[@sel].common_events[@x + @y * 8].size > 0)
        options << "Cancel"
        cmd = Kernel.pbMessage("What do want to do with this tile?", options, 2)
        next if cmd == -1
        if cmd == 0 # Add Common Event
          params = ChooseNumberParams.new
          params.setMaxDigits(3)
          id = Kernel.pbMessageChooseNumber("Enter the ID of the common event you'd like to assign " +
                                            "to this tile.", params)
          @data[@sel].common_events[@x + @y * 8] ||= []
          @data[@sel].common_events[@x + @y * 8] << id
          refresh = true
        elsif cmd == 1 && options.size == 3 # Show Common events
          display = @data[@sel].common_events[@x + @y * 8].map do |e|
            next "#{e}: #{$data_common_events[e].name}"
          end
          cmd = Kernel.pbMessage("These are all common events assigned to this event.",
                                 display, -1)
          break if cmd == -1
          if Kernel.pbConfirmMessage("Do you want to delete common event \"<b>#{display[cmd]}</b>\"?")
            @data[@sel].common_events[@x + @y * 8][cmd] = nil
            @data[@sel].common_events[@x + @y * 8].compact!
            refresh = true
          end
        end
      end
      if @x != old_x || @y != old_y || refresh
        @current.src_rect.x = @x * 32
        @current.src_rect.y = @y * 32
        @txt.clear
        @txt.draw([
          ["Terrain Tag: #{get_terrain_tags[@x + @y * 8]}", @current.x + 32,
           @current.y + 70, 2, Color.new(255, 255, 255)],
          ["Priority: #{get_priorities[@x + @y * 8]}", @current.x + 32,
           @current.y + 100, 2, Color.new(255, 255, 255)],
          ["Common Events: #{@data[@sel].common_events[@x + @y * 8] ? @data[@sel].common_events[@x + @y * 8].size : 0}",
           @current.x + 32, @current.y + 130, 2, Color.new(255, 255, 255)],
          ["Tile ID: #{@x + 8 * @y + 384}", @current.x + 32, @current.y + 160, 2, Color.new(255, 255, 255)],
        ])
      end
      break if Input.trigger?(Input::B)
    end
    @tileset.dispose
    @tileset = nil
    @selector.dispose
    @selector = nil
    @current.dispose
    @current = nil
    @txt.dispose
    @txt = nil
    Input.update
  end
  # Creates a sprite used as the selector and returns it
  def make_selector
    selector = Sprite.new(@viewport)
    selector.bmp(32, 32)
    selector.bmp.fill_rect(0, 0, 32, SelectorWidth, SelectorColor)
    selector.bmp.fill_rect(0, 0, SelectorWidth, 32, SelectorColor)
    selector.bmp.fill_rect(32 - SelectorWidth, 0, 32, 32, SelectorColor)
    selector.bmp.fill_rect(0, 32 - SelectorWidth, 32, 32, SelectorColor)
    return selector
  end
end

It was a minor change required, so no need to credit me.

EDIT: Cleaned up error messages in the console from rescue use
 
Last edited:
Back
Top