I seem to be in a bit of trouble with my own script. It likes to skip chunks of code. If anyone could help me, I would greatly appreciate it.
Code:
#==============================================================================
# ** MeisMe's Realistic Shop
#------------------------------------------------------------------------------
# Created by MeisMe
# August 2006
# Version 1
#-----------------------------------------------------------------------------
#==============================================================================
class Game_Temp
attr_accessor :buy_rate
attr_accessor :sell_rate
attr_accessor :discount
attr_accessor :tax
attr_accessor :cart_item
attr_accessor :cart_weapon
attr_accessor :cart_armor
attr_accessor :shop_type
alias mim_shop_old_initialize initialize
def initialize
mim_shop_old_initialize
@buy_rate = 100
@sell_rate = 50
@discount = 0
@tax = 7
clear_cart
@shop_type = 0
end
def clear_cart
@cart_item = {}
@cart_weapon = {}
@cart_armor = {}
end
def cart_cleared?
if (@cart_item == {} && @cart_weapon == {} && @cart_armor == {})
return true
end
return false
end
def item_number(item_id)
return @cart_item.include?(item_id) ? @cart_item[item_id] : 0
end
def weapon_number(weapon_id)
return @cart_weapon.include?(weapon_id) ? @cart_weapon[weapon_id] : 0
end
def armor_number(armor_id)
return @cart_armor.include?(armor_id) ? @cart_armor[armor_id] : 0
end
def gain_item(item_id, n)
if item_id > 0
@cart_item[item_id] = [[item_number(item_id) + n, 0].max, 99].min
end
end
def gain_weapon(weapon_id, n)
if weapon_id > 0
@cart_weapon[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
end
end
def gain_armor(armor_id, n)
if armor_id > 0
@cart_armor[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
end
end
def gain_items
for i in 1..$data_items.size
if item_number(i) > 0
$game_party.gain_item(i, item_number(i))
end
end
for i in 1..$data_weapons.size
if weapon_number(i) > 0
gain_weapon($data_weapons[i], weapon_number(i))
end
end
for i in 1..$data_armors.size
if armor_number(i) > 0
$game_party.gain_armor($data_armors[i], armor_number(i))
end
end
end
end
#==============================================================================
class Window_ShopCommand < Window_Selectable
def initialize
super(0, 64, 480, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 3
@column_max = 3
@commands = ["Buy", "Sell", "Exit"]
refresh
self.index = 0
end
def refresh
self.contents.clear
if $game_temp.shop_type == 0
for i in 0...@item_max
draw_item(i)
end
end
if $game_temp.shop_type == 1
self.contents.draw_text(4, 0, 324, 32, "You can only buy at this shop.")
self.index = -1
update_cursor_rect
end
if $game_temp.shop_type == 2
self.contents.draw_text(4, 0, 324, 32, "You can only sell at this shop.")
self.index = -1
update_cursor_rect
end
end
def draw_item(index)
x = 4 + index * 160
self.contents.draw_text(x, 0, 128, 32, @commands[index])
end
def update_cursor_rect
if $game_temp.shop_type == 0
super
end
if $game_temp.shop_type == 1 || $game_temp.shop_type == 2
self.cursor_rect.empty
end
end
end
#==============================================================================
class Window_ShopBuyBG < Window_Base
def initialize
super(0, 128, 320, 352)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 128, 32, 'Item Name')
self.contents.draw_text(4, 0, 284, 32, 'Marked Price', 2)
end
end
#==============================================================================
class Window_ShopBuy < Window_Selectable
def initialize(shop_goods)
super(0, 160, 320, 320)
@shop_goods = shop_goods
refresh
self.index = 0
self.opacity = 0
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for goods_item in @shop_goods
case goods_item[0]
when 0
item = $data_items[goods_item[1]]
when 1
item = $data_weapons[goods_item[1]]
when 2
item = $data_armors[goods_item[1]]
end
if item != nil
@data.push(item)
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id) +
$game_temp.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id) +
$game_temp.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id) +
$game_temp.armor_number(item.id)
end
price = [[item.price * 100 / $game_temp.buy_rate, 9999999].min, 0].max
if number >= 99
self.contents.font.color = disabled_color
else
self.contents.font.color = normal_color
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 192, y, 88, 32, price.to_s, 2)
end
end
#==============================================================================
class Window_ShopNumber < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 128, 320, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@item = nil
@max = 1
@price = 0
@number = 1
end
#--------------------------------------------------------------------------
# * Set Items, Max Quantity, and Price
#--------------------------------------------------------------------------
def set(item, max, price)
@item = item
@max = max
@price = price
@number = 1
refresh
end
#--------------------------------------------------------------------------
# * Set Inputted Quantity
#--------------------------------------------------------------------------
def number
return @number
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_item_name(@item, 4, 96)
self.contents.font.color = normal_color
self.contents.draw_text(236, 96, 32, 32, "Ãâ€â€