Help with Shop Menu [RPG Maker XP] - JackMonty - 12-11-2012
Hi All,
I’m having a small issue with a shop script – see below.
Code: #_______________________________________________________________________________
# MOG Scene Shop V1.0
#_______________________________________________________________________________
# By Moghunter
#_______________________________________________________________________________
if true
module MOG
#Transition Time.
MNSHPT= 30
#Transition Type (Name)
MNSHPTT= "006-Stripe02"
end
$mogscript = {} if $mogscript == nil
$mogscript["menu_"] = true
###############
# Window_Base #
###############
class Window_Base < Window
def draw_item_name_ex(item, x, y)
if item == nil
return
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.font.color = normal_color
self.contents.draw_text(x + 28, y, 150, 32, item.name)
end
def nada
face = RPG::Cache.picture("")
end
def drw_face(actor,x,y)
face = RPG::Cache.picture(actor.name + "_fc") rescue nada
cw = face.width
ch = face.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x , y - ch, face, src_rect)
end
end
################
# Win_Shop_Sel #
################
class Win_Shop_Sel < Window_Base
attr_reader :index
def initialize(x, y, width, height)
super(x, y, width, height)
@item_max = 1
@column_max = 1
@index = -1
end
def index=(index)
@index = index
update_cursor_rect
end
def row_max
return (@item_max + @column_max - 1) / @column_max
end
def top_row
return self.oy / 32
end
def top_row=(row)
if row < 0
row = 0
end
if row > row_max - 1
row = row_max - 1
end
self.oy = row * 32
end
def page_row_max
return (self.height - 32) / 32
end
def page_item_max
return page_row_max * @column_max
end
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
return
end
row = @index / @column_max
if row < self.top_row
self.top_row = row
end
if row > self.top_row + (self.page_row_max - 1)
self.top_row = row - (self.page_row_max - 1)
end
cursor_width = self.width / @column_max - 32
x = @index % @column_max * 80
y = @index / @column_max * 32 - self.oy
self.cursor_rect.set(x, y, 32, 32)
end
def update
super
if self.active and @item_max > 0 and @index >= 0
if Input.repeat?(Input::RIGHT)
if @column_max >= 2 and @index < @item_max - 1
$game_system.se_play($data_system.cursor_se)
@index += 1
end
end
if Input.repeat?(Input::LEFT)
if @column_max >= 2 and @index > 0
$game_system.se_play($data_system.cursor_se)
@index -= 1
end
end
end
update_cursor_rect
end
end
######################
# Window_ShopCommand #
######################
class Window_ShopCommand < Win_Shop_Sel
def initialize
super(58, 68, 230, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 3
@column_max = 3
@commands = ["", "", ""]
self.index = 0
end
end
##################
# Window_ShopBuy #
##################
class Window_ShopBuy < Window_Selectable
def initialize(shop_goods)
super(-10, 180, 310, 225)
@shop_goods = shop_goods
refresh
self.index = 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
@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)
self.contents.font.name = "Georgia"
self.contents.font.bold = false
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
x = 4
y = index * 32
if item.price <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
rect = Rect.new(x, y, self.width - 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, 150, 32, item.name, 0)
self.contents.font.color = Color.new(50,250,150,255)
self.contents.draw_text(x + 150, y, 88, 32, "Yen", 1)
if item.price <= $game_party.gold
if number < 99
self.contents.font.color = Color.new(200,200,50,255)
else
self.contents.font.color = disabled_color
end
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(x + 180, y, 88, 32, item.price.to_s, 2)
end
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
###################
# Window_ShopSell #
###################
class Window_ShopSell < Window_Selectable
def initialize
super(-10, 180, 305, 225)
@column_max = 1
refresh
self.index = 0
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
end
@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)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
if item.price > 0
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
self.contents.font.name = "Georgia"
x = 4 + index % 1 * (288 + 32)
y = index / 1 * 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, 150, 32, item.name, 0)
self.contents.draw_text(x + 230, y, 16, 32, ":", 1)
self.contents.draw_text(x + 240, y, 24, 32, number.to_s, 2)
end
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#####################
# Window_ShopNumber #
#####################
class Window_ShopNumber < Window_Base
def initialize
super(-10, 180, 310, 225)
self.contents = Bitmap.new(width - 32, height - 32)
@item = nil
@max = 1
@price = 0
@number = 1
end
def set(item, max, price)
@item = item
@max = max
@price = price
@number = 1
refresh
end
def number
return @number
end
def refresh
self.contents.clear
self.contents.font.name = "Georgia"
self.contents.font.bold = true
draw_item_name_ex(@item, 4, 66)
self.contents.font.color = Color.new(50,150,250,255)
self.contents.draw_text(185, 66, 32, 32, "x")
self.contents.font.color = normal_color
self.contents.draw_text(208, 66, 24, 32, @number.to_s, 2)
self.cursor_rect.set(304, 66, 32, 32)
total_price = @price * @number
cx = contents.text_size("Yen").width
self.contents.font.color = Color.new(200,200,50,255)
self.contents.draw_text(4, 160, 228-2, 32, total_price.to_s, 2)
self.contents.font.color = Color.new(50,250,150,255)
self.contents.draw_text(90, 160, 88, 32, "Yen", 1)
end
def update
super
if self.active
if Input.repeat?(Input::RIGHT) and @number < @max
$game_system.se_play($data_system.cursor_se)
@number += 1
refresh
end
if Input.repeat?(Input::LEFT) and @number > 1
$game_system.se_play($data_system.cursor_se)
@number -= 1
refresh
end
if Input.repeat?(Input::UP) and @number < @max
$game_system.se_play($data_system.cursor_se)
@number = [@number + 10, @max].min
refresh
end
if Input.repeat?(Input::DOWN) and @number > 1
$game_system.se_play($data_system.cursor_se)
@number = [@number - 10, 1].max
refresh
end
end
end
end
#####################
# Window_ShopStatus #
#####################
class Window_ShopStatus < Window_Base
def initialize
super(300, 128, 350, 300)
self.contents = Bitmap.new(width - 32, height - 32)
@item = nil
refresh
end
def refresh
self.contents.clear
self.contents.font.name = "Georgia"
if @item == nil
return
end
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
self.contents.font.color = system_color
self.contents.draw_text(210, 0, 200, 32, "Own :")
self.contents.font.color = normal_color
self.contents.draw_text(245, 0, 32, 32, number.to_s, 2)
if @item.is_a?(RPG::Item)
return
end
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.equippable?(@item)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
self.contents.draw_text(65, 0, 100, 32, "Equip", 2)
drw_face(actor,0 ,80 + 64 * i)
if @item.is_a?(RPG::Weapon)
item1 = $data_weapons[actor.weapon_id]
elsif @item.kind == 0
item1 = $data_armors[actor.armor1_id]
elsif @item.kind == 1
item1 = $data_armors[actor.armor2_id]
elsif @item.kind == 2
item1 = $data_armors[actor.armor3_id]
else
item1 = $data_armors[actor.armor4_id]
end
if actor.equippable?(@item)
if @item.is_a?(RPG::Weapon)
atk1 = item1 != nil ? item1.atk : 0
atk2 = @item != nil ? @item.atk : 0
pdef1 = item1 != nil ? item1.pdef : 0
mdef1 = item1 != nil ? item1.mdef : 0
pdef2 = @item != nil ? @item.pdef : 0
mdef2 = @item != nil ? @item.mdef : 0
self.contents.draw_text(-20, 50 + 64 * i, 112, 32,"Attack", 2)
self.contents.draw_text(70, 50 + 64 * i, 112, 32,"Def", 2)
self.contents.draw_text(170, 50 + 64 * i, 112, 32,"M.Def", 2)
change = atk2 - atk1
change2 = pdef2 - pdef1
change3 = mdef2 - mdef1
if atk2 > atk1
self.contents.font.color = Color.new(50,250,150,255)
elsif atk2 == atk1
self.contents.font.color = disabled_color
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(20, 50 + 64 * i, 112, 32,sprintf("%d", change), 2)
if pdef2 > pdef1
self.contents.font.color = Color.new(50,250,150,255)
elsif pdef2 == pdef1
self.contents.font.color = disabled_color
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(110, 50 + 64 * i, 112, 32,sprintf("%d", change2), 2)
if mdef2 > mdef1
self.contents.font.color = Color.new(50,250,150,255)
elsif mdef2 == mdef1
self.contents.font.color = disabled_color
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(200, 50 + 64 * i, 112, 32,sprintf("%d", change3), 2)
end
if @item.is_a?(RPG::Armor)
pdef1 = item1 != nil ? item1.pdef : 0
mdef1 = item1 != nil ? item1.mdef : 0
eva1 = item1 != nil ? item1.eva : 0
pdef2 = @item != nil ? @item.pdef : 0
mdef2 = @item != nil ? @item.mdef : 0
eva2 = @item != nil ? @item.eva : 0
change = pdef2 - pdef1
change2 = mdef2 - mdef1
change3 = eva2 - eva1
self.contents.draw_text(-15, 50 + 64 * i, 112, 32,"Def", 2)
self.contents.draw_text(80, 50 + 64 * i, 112, 32,"M.Def", 2)
self.contents.draw_text(170, 50 + 64 * i, 112, 32,"Evade", 2)
if pdef2 > pdef1
self.contents.font.color = Color.new(50,250,150,255)
elsif pdef2 == pdef1
self.contents.font.color = disabled_color
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(20, 50 + 64 * i, 112, 32,sprintf("%d", change), 2)
if mdef2 > mdef1
self.contents.font.color = Color.new(50,250,150,255)
elsif mdef2 == mdef1
self.contents.font.color = disabled_color
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(110, 50 + 64 * i, 112, 32,sprintf("%d", change2), 2)
if eva2 > eva1
self.contents.font.color = Color.new(50,250,150,255)
elsif eva2 == eva1
self.contents.font.color = disabled_color
else
self.contents.font.color = Color.new(250,100,50,255)
end
self.contents.draw_text(200, 50 + 64 * i, 112, 32,sprintf("%d", change3), 2)
end
end
if item1 != nil
if actor.equippable?(@item)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4
y = 64 + 64 * i
bitmap = RPG::Cache.icon(item1.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x + 50, y - 35, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 75, y - 40, 212, 32, item1.name)
end
end
end
def item=(item)
if @item != item
@item = item
refresh
end
end
end
##############
# Scene_Shop #
##############
class Scene_Shop
def main
@mshop_back = Plane.new
@mshop_back.bitmap = RPG::Cache.picture("MN_BK2")
@mshop_back.z = 10
@mshop_lay = Sprite.new
@mshop_lay.bitmap = RPG::Cache.picture("Shop_Lay")
@mshop_lay.z = 15
@mshop_com = Sprite.new
@mshop_com.bitmap = RPG::Cache.picture("Shop_Com01")
@mshop_com.z = 20
@help_window = Window_Help.new
@help_window.contents.font.name = "Georgia"
@help_window.y = 413
@command_window = Window_ShopCommand.new
@command_window.visible = false
@gold_window = Window_Gold.new
@gold_window.x = 460
@gold_window.y = -5
@dummy_window = Window_Base.new(0, 128, 640, 352)
@buy_window = Window_ShopBuy.new($game_temp.shop_goods)
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
@sell_window = Window_ShopSell.new
@sell_window.active = false
@sell_window.visible = false
@sell_window.help_window = @help_window
@number_window = Window_ShopNumber.new
@number_window.active = false
@number_window.visible = false
@status_window = Window_ShopStatus.new
@status_window.visible = false
@help_window.opacity = 0
@status_window.opacity = 0
@sell_window.opacity = 0
@buy_window.opacity = 0
@gold_window.opacity = 0
@command_window.opacity = 0
@number_window.opacity = 0
@dummy_window.opacity = 0
Graphics.transition(MOG::MNSHPT, "Graphics/Transitions/" + MOG::MNSHPTT)
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
for i in 0..30
@mshop_back.ox += 1
@help_window.x -= 15
@gold_window.x += 15
@mshop_lay.zoom_x += 0.1
@mshop_lay.opacity -= 10
@command_window.x -= 15
@mshop_com.x -= 15
Graphics.update
end
Graphics.freeze
@help_window.dispose
@command_window.dispose
@gold_window.dispose
@dummy_window.dispose
@buy_window.dispose
@sell_window.dispose
@number_window.dispose
@status_window.dispose
@mshop_back.dispose
@mshop_lay.dispose
@mshop_com.dispose
end
def update
@mshop_back.ox += 1
if @help_window.x < 0
@help_window.x += 10
@help_window.contents_opacity += 10
elsif @help_window.x >= 0
@help_window.x = 0
@help_window.contents_opacity = 255
end
if @buy_window.x < -10
@buy_window.x += 15
@buy_window.contents_opacity += 6
elsif @buy_window.x >= -10
@buy_window.x = -10
@buy_window.contents_opacity = 255
end
if @buy_window.visible == false
@buy_window.x = -300
end
if @sell_window.x < -10
@sell_window.x += 15
@sell_window.contents_opacity += 6
elsif @buy_window.x >= -10
@sell_window.x = -10
@sell_window.contents_opacity = 255
end
if @sell_window.visible == false
@sell_window.x = -300
end
if @number_window.x < -10
@number_window.x += 15
@number_window.contents_opacity += 6
elsif @number_window.x >= -10
@number_window.x = -10
@number_window.contents_opacity = 255
end
if @number_window.visible == false
@number_window.x = -300
end
if @number_window.active == false
if Input.trigger?(Input.dir4) or Input.trigger?(Input::C) or
Input.trigger?(Input::L) or Input.trigger?(Input::R)
@help_window.x = -200
@help_window.contents_opacity = 0
end
end
@help_window.update
@command_window.update
@gold_window.update
@dummy_window.update
@buy_window.update
@sell_window.update
@number_window.update
@status_window.update
case @command_window.index
when 0
@mshop_com.bitmap = RPG::Cache.picture("Shop_Com01")
when 1
@mshop_com.bitmap = RPG::Cache.picture("Shop_Com02")
when 2
@mshop_com.bitmap = RPG::Cache.picture("Shop_Com03")
end
if @command_window.active
update_command
return
end
if @buy_window.active
update_buy
return
end
if @sell_window.active
update_sell
return
end
if @number_window.active
update_number
return
end
end
def update_command
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
case @command_window.index
when 0
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
@status_window.visible = true
when 1
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@dummy_window.visible = false
@sell_window.active = true
@sell_window.visible = true
@sell_window.refresh
when 2
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
end
return
end
end
def update_buy
@status_window.item = @buy_window.item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @buy_window.item
if @item == nil or @item.price > $game_party.gold
$game_system.se_play($data_system.buzzer_se)
return
end
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
if number == 99
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number].min
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, @item.price)
@number_window.active = true
@number_window.visible = true
end
end
def update_sell
@status_window.item = @sell_window.item
@status_window.visible = true
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@dummy_window.visible = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @sell_window.item
@status_window.item = @item
if @item == nil or @item.price == 0
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
max = number
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@item, max, @item.price / 2)
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
end
end
def update_number
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0
@buy_window.active = true
@buy_window.visible = true
when 1
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.shop_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0
$game_party.lose_gold(@number_window.number * @item.price)
case @item
when RPG::Item
$game_party.gain_item(@item.id, @number_window.number)
when RPG::Weapon
$game_party.gain_weapon(@item.id, @number_window.number)
when RPG::Armor
$game_party.gain_armor(@item.id, @number_window.number)
end
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
@buy_window.active = true
@buy_window.visible = true
when 1
$game_party.gain_gold(@number_window.number * (@item.price / 2))
case @item
when RPG::Item
$game_party.lose_item(@item.id, @number_window.number)
when RPG::Weapon
$game_party.lose_weapon(@item.id, @number_window.number)
when RPG::Armor
$game_party.lose_armor(@item.id, @number_window.number)
end
@gold_window.refresh
@sell_window.refresh
@status_window.refresh
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
end
end
end
It’s geared at showing currently equipped items on party members. However it only returns four party members and not five – I can’t seem to find a way to change this! I believe this is controlled by the section:
Window_ShopStatus – but I could be wrong – any help would be appreciated!
RE: Help with Shop Menu [RPG Maker XP] - DerVVulfman - 12-12-2012
May take some time.
Moghunter never geared his scripts toward anything other than 'default' systems, not allowing for any new additions like extra party members, additions to the item or skill systems, or the like. Beautiful in appearance, sloppy and overwroght in coding. He tends to re-invent the wheel when it's not needed.
Look up Moghunter in a search here. You may find some rewritten versions I posted. But I didn't do a shop script as yet.
RE: Help with Shop Menu [RPG Maker XP] - MechanicalPen - 12-12-2012
The 'for i in 0...$game_party.actors.size' line should correctly loop through all actors, so the problem may be the fifth actor is being drawn out of the window.
RE: Help with Shop Menu [RPG Maker XP] - JackMonty - 12-14-2012
Hello
At DerVVulfman - that's a sahme that it is tied down to four characters but would also explain why I couldn't seem to chang it to work!
At MechanicalPen - if the 'for i in 0...$game_party.actors.size' is working then hopefully I should be able to see the text by changing the text draw parameters to try and push all the text up - no luck with this so far though...
RE: Help with Shop Menu [RPG Maker XP] - MechanicalPen - 05-21-2013
Okay, this is silly, you'll laugh. Find Code: class Window_ShopStatus < Window_Base
and you'll see Code: super(300, 128, 350, 300)
All you need to do is make the window taller and move it up a bit! All the actors are being drawn, except the last actor is being drawn off the window frame.
RE: Help with Shop Menu [RPG Maker XP] - JackMonty - 05-22-2013
No way! Something as simple as that!
I will have a play with this later on and I'll let you know how I get on.
Thanks again for your help.
RE: Help with Shop Menu [RPG Maker XP] - JackMonty - 05-23-2013
Hi MechanicanPen
Just to let you know changing the window parameters did the trick - all five characters now display!
Many Thanks!
|