Demo – Version 1.1 >
#------------------------------------------------------------------------------#
# Galv's Pawn Shop
#------------------------------------------------------------------------------#
# For: RPGMAKER VX ACE
# Version 1.1
#------------------------------------------------------------------------------#
# 2012-10-01 - Version 1.1 - fixed a mistake that didn't change actual price.
# 2012-09-30 - Version 1.0 - release
#------------------------------------------------------------------------------#
# Creates a pawn shop that uses the shop processing event call item list to
# determine the ONLY items that the player can sell to that pawn shop.
#
# INSTRUCTIONS:
# Set a variable for the price pawns shops will buy goods at. (this variable is
# a percent of the item's cost. eg. if the variable is 75, a pawn shop will buy
# an item for 75% of it's cost. This of course can be changed anytime during
# the game.
# Notetags can be added to weapons, armor and actors that increase or decrease
# the variable's % by a number.
# Turn a switch ON to make event shop processing turn into a pawn shop instead.
# The item selling rate % can be seen in the pawn shop scene.
# This % turns green when players have a positive bonus from equips/actors and
# turns red when players have a negative bonus from them.
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# NOTETAG for Armors and Weapons:
#------------------------------------------------------------------------------#
# <pawn_bonus: x> # Adds x% to pawn shop selling rate when equipped
#
#------------------------------------------------------------------------------#
# NOTETAG for Actors:
#------------------------------------------------------------------------------#
# <pawn_bonus: x> # Adds x% to pawn shop selling rate when actor in party
#
#------------------------------------------------------------------------------#
$imported = {} if $imported.nil?
$imported["Pawn_Shop"] = true
module Pawn_Shop
#------------------------------------------------------------------------------#
# SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
SWAP_SWITCH = 1 # Switch ID that inverts the shop processing
# event to be the pawn shop while ON.
SALE_VALUE_VAR = 1 # Variable ID that controls the price of
# pawning goods. Set variable to a % (0-100)
# eg. If variable = 25 then price 25%
SELL_SE = ["", 100, 100] # SE for transaction ["SE Name", volume, pitch]
# Leave as "" to play default shop sound.
#------------------------------------------------------------------------------#
# SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
end
module Pawn_Shop_Notetags
def pawn_bonus
if @pawn_bonus.nil?
if @note =~ /<pawn_bonus: (.*)>/i
@pawn_bonus = $1.to_i
else
@pawn_bonus = 0
end
end
@pawn_bonus
end
end # Pawn_Shop_Notetags
class RPG::Armor
include Pawn_Shop_Notetags
end
class RPG::Weapon
include Pawn_Shop_Notetags
end
class RPG::Actor
include Pawn_Shop_Notetags
end
#--------------------------------------------------------------------------
# * Game Interpreter - Overwrite shop call method
#--------------------------------------------------------------------------
class Game_Interpreter
def command_302
return if $game_party.in_battle
goods = [@params]
while next_event_code == 605
@index += 1
goods.push(@list[@index].parameters)
end
if $game_switches[Pawn_Shop::SWAP_SWITCH]
SceneManager.call(Scene_PawnShop)
SceneManager.scene.prepare(goods)
else
SceneManager.call(Scene_Shop)
SceneManager.scene.prepare(goods, @params[4])
end
Fiber.yield
end
end
#--------------------------------------------------------------------------
# * New Window - Pawn Shop Sell
#--------------------------------------------------------------------------
class Window_PawnShopSell < Window_ItemList
def initialize(x, y, width, height, shop_goods)
super(x, y, width, height)
@shop_goods = shop_goods
end
def current_item_enabled?
enable?(@data[index])
end
def enable?(item)
item && $game_party.item_number(item) > 0
end
def make_item_list
@data = []
@price = {}
@shop_goods.each do |goods|
case goods[0]
when 0; item = $data_items[goods[1]]
when 1; item = $data_weapons[goods[1]]
when 2; item = $data_armors[goods[1]]
end
if item
@data.push(item)
end
end
end
end # Window_PawnShopSell < Window_ItemList
#--------------------------------------------------------------------------
# * New Scene - Pawn Shop
#--------------------------------------------------------------------------
class Scene_PawnShop < Scene_MenuBase
def prepare(goods)
@goods = goods
end
def start
super
create_help_window
create_gold_window
create_rate_window
create_command_window
create_dummy_window
create_number_window
create_status_window
create_sell_window
end
def create_gold_window
@gold_window = Window_Gold.new
@gold_window.viewport = @viewport
@gold_window.x = Graphics.width - @gold_window.width
@gold_window.y = @help_window.height
end
def create_rate_window
@rate_window = Window_Rate.new
@rate_window.viewport = @viewport
@rate_window.x = Graphics.width - @gold_window.width - @rate_window.width
@rate_window.y = @help_window.height
end
def create_command_window
@command_window = Window_PawnCommand.new(@gold_window.x, @purchase_only)
@command_window.viewport = @viewport
@command_window.y = @help_window.height
@command_window.width = Graphics.width - @gold_window.width - @rate_window.width
@command_window.set_handler(:sell, method(:command_sell))
@command_window.set_handler(:cancel, method(:return_scene))
end
def create_dummy_window
wy = @command_window.y + @command_window.height
wh = Graphics.height - wy
@dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
@dummy_window.viewport = @viewport
end
def create_number_window
wy = @dummy_window.y
wh = @dummy_window.height
@number_window = Window_ShopNumber.new(0, wy, wh)
@number_window.viewport = @viewport
@number_window.hide
@number_window.set_handler(:ok, method(:on_number_ok))
@number_window.set_handler(:cancel, method(:on_number_cancel))
end
def create_sell_window
wy = @dummy_window.y
wh = Graphics.height - wy
@sell_window = Window_PawnShopSell.new(0, wy, Graphics.width, wh, @goods)
@sell_window.viewport = @viewport
@sell_window.help_window = @help_window
@sell_window.hide
@sell_window.set_handler(:ok, method(:on_sell_ok))
@sell_window.set_handler(:cancel, method(:on_sell_cancel))
end
def create_status_window
wx = @number_window.width
wy = @dummy_window.y
ww = Graphics.width - wx
wh = @dummy_window.height
@status_window = Window_ShopStatus.new(wx, wy, ww, wh)
@status_window.viewport = @viewport
@status_window.hide
end
def activate_sell_window
@sell_window.refresh
@sell_window.show.activate
@status_window.hide
end
def command_sell
@dummy_window.hide
@sell_window.show
activate_sell_window
@sell_window.select(0)
@sell_window.refresh
end
def on_sell_ok
@item = @sell_window.item
@status_window.item = @item
@sell_window.hide
@number_window.set(@item, max_sell, selling_price, currency_unit)
@number_window.show.activate
@status_window.show
end
def on_sell_cancel
@command_window.activate
@dummy_window.show
@sell_window.hide
@sell_window.unselect
@status_window.item = nil
@help_window.clear
end
def on_number_ok
if Pawn_Shop::SELL_SE[0] == ""
Sound.play_shop
else
RPG::SE.new(Pawn_Shop::SELL_SE[0], Pawn_Shop::SELL_SE[1], Pawn_Shop::SELL_SE[2]).play
end
do_sell(@number_window.number)
end_number_input
@gold_window.refresh
@status_window.refresh
end
def on_number_cancel
Sound.play_cancel
end_number_input
end
def do_sell(number)
$game_party.gain_gold(number * selling_price)
$game_party.lose_item(@item, number)
end
def end_number_input
@number_window.hide
activate_sell_window
end
def max_sell
$game_party.item_number(@item)
end
def money
@gold_window.value
end
def currency_unit
@gold_window.currency_unit
end
def selling_price
((@item.price * 0.01) * ($game_variables[Pawn_Shop::SALE_VALUE_VAR] + equip_bonus + actor_bonus)).round
end
def equip_bonus
mem = 0
eqs = 0
equip_bonus = 0
no_equips = ($game_party.members.count) * ($game_party.members[0].equips.count)
no_equips.times { |i|
if $game_party.members[mem].equips[eqs] != nil
equip_bonus += $game_party.members[mem].equips[eqs].pawn_bonus
end
if eqs < 5
eqs += 1
else
eqs = 1
mem += 1
end
}
@equip_bonus = equip_bonus
end
def actor_bonus
actor_bonus = 0
no_actors = $game_party.members.count
no_actors.times { |i|
if $game_party.members[i] != nil
actor_bonus += $data_actors[$game_party.members[i].id].pawn_bonus
end
}
@actor_bonus = actor_bonus
end
end # Scene_PawnShop < Scene_MenuBase
#--------------------------------------------------------------------------
# * New Window - Rate %
#--------------------------------------------------------------------------
class Window_Rate < Window_Base
def initialize
super(0, 0, window_width, fitting_height(1))
refresh
end
def window_width
return 80
end
def refresh
contents.clear
draw_rate_value(value, rate_unit, 4, 0, contents.width - 8)
end
def draw_rate_value(value, unit, x, y, width)
cx = text_size(unit).width
change_color(bonus_color)
draw_text(x, y, width - cx - 2, line_height, value, 2)
change_color(bonus_color)
draw_text(x, y, width, line_height, unit, 2)
end
def bonus_color
if equip_bonus + actor_bonus == 0
text_color(0)
elsif equip_bonus + actor_bonus > 0
text_color(3)
else
text_color(2)
end
end
def value
$game_variables[Pawn_Shop::SALE_VALUE_VAR] + equip_bonus + actor_bonus
end
def equip_bonus
mem = 0
eqs = 0
equip_bonus = 0
no_equips = ($game_party.members.count) * ($game_party.members[0].equips.count)
no_equips.times { |i|
if $game_party.members[mem].equips[eqs] != nil
equip_bonus += $game_party.members[mem].equips[eqs].pawn_bonus
end
if eqs < 5
eqs += 1
else
eqs = 1
mem += 1
end
}
@equip_bonus = equip_bonus
end
def actor_bonus
actor_bonus = 0
no_actors = $game_party.members.count
no_actors.times { |i|
if $game_party.members[i] != nil
actor_bonus += $data_actors[$game_party.members[i].id].pawn_bonus
end
}
@actor_bonus = actor_bonus
end
def rate_unit
"%"
end
def open
refresh
super
end
end # Window_Rate < Window_Base
#--------------------------------------------------------------------------
# * New Window - Pawn Command
#--------------------------------------------------------------------------
class Window_PawnCommand < Window_HorzCommand
def initialize(window_width, purchase_only)
@window_width = window_width
@purchase_only = purchase_only
super(0, 0)
end
def window_width
@window_width - 80
end
def col_max
return 2
end
def make_command_list
add_command(Vocab::ShopSell, :sell)
add_command(Vocab::ShopCancel, :cancel)
end
end # Window_PawnCommand < Window_HorzCommand
While i was able to get the pawn shop itself to work, I was not able to set the variable for sell value. I tried placing it in the event and in the scripting. Any advice?
Are you using any other shops scripts that might be conflicting?
When I try this I get an error:
NoMethodError
undefined method ‘equips’ for nil:NilClass
def equip_bonus
mem = 0
eqs = 0
equip_bonus = 0
no_equips = ($game_party.members.count) * ($game_party.members[0].equips.count)
no_equips.times { |i|
if $game_party.members[mem].equips[eqs] != nil
equip_bonus += $game_party.members[mem].equips[eqs].pawn_bonus <— This line here
end
if eqs < 5
eqs += 1
else
eqs = 1
mem += 1
end
}
@equip_bonus = equip_bonus
end
No other shop scripts are being used, all I am using besides this is the Yanfly 'Core' and 'Battle' scripts.
Ok just remembered I have the Yanfly Equip Engine also, I may be able to fix this myself.
I had this problem too. I just #’ed out the two
if $game_party.members[mem].equips[eqs] != nil
equip_bonus += $game_party.members[mem].equips[eqs].pawn_bonus
end
at 314 and 391. and now it works with Yanfly’s Equip Engine