=begin
____________________________
| J::BUY/SELL via variables! |
| Author: Jragyn |
| Inspiration: Yanfly(wong) |
|____________________________|
This script allows the maker to edit buying and selling prices globally
via the use of ingame variables.
Just change the variables indicated by:
BUY = ## and SELL = ##
while ingame, and the prices will be impacted in a percentual manner.
--------------------------------------------------------------------------------
ie:
change the variable value of BUY ingame to 70,
and items will have a new pricetag of 70% its database price.
change the variable value of SELL ingame to 100,
and items you sell will be sold for their full price in the database.
--------------------------------------------------------------------------------
The default pricing as suggested by RMXP is you buy at 100% of an items
database price, and you sell it back for half-price. If you want to change
this, just alter the value of the Variables designated below.
Lastly, I give credit to Yanfly. He created a script that replicates this effect
for RMVX, and now I present my version of it for RMXP.
v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^
::Aliased [Scene_Title] ----- command_new_game
::Overwrote [Scene_Shop] ------ update_buy & update_sell & update_number
::Overwrote [Window_Shopbuy] -- draw_item
v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^
=end
module J
#========================================#
# BUY = Variable ## in the database. #
# DEFAULT_BUY = The default buy pricing #
#
BUY = 11 #
DEFAULT_BUY = 100 #
#========================================#
# SELL = Variable ## in the database. #
# DEFAULT_BUY = The default sell pricing #
#
SELL = 12 #
DEFAULT_SELL = 50 #
#========================================#
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
class Scene_Title
alias purple_uber_sonic_goose command_new_game
def command_new_game
purple_uber_sonic_goose
#==============================================#
# These are the default prices that #
# are setup upon a new game. #
#==============================================#
$game_variables[J::BUY] = J::DEFAULT_BUY #
$game_variables[J::SELL] = J::DEFAULT_SELL #
#==============================================#
end
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# altered 1 line to allow for price alterations.
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
# Get items in possession
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 price is less than money in possession, and amount in possession is
# not 99, then set to normal text color. Otherwise set to disabled color
if ((item.price * $game_variables[J::BUY]) / 100) <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4
y = index * 32
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, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 88, 32, ((item.price * $game_variables[J::BUY]) / 100).to_s, 2)
end
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
class Scene_Shop
#--------------------------------------------------------------------------
# * Frame Update (when buy window is active)
# altered 3 lines to allow for price alterations.
#--------------------------------------------------------------------------
def update_buy
# Set status window item
@status_window.item = @buy_window.item
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Change windows to initial mode
@command_window.active = true
@dummy_window.visible = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
# Erase help text
@help_window.set_text("")
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get item
@item = @buy_window.item
# If item is invalid, or price is higher than money possessed
if @item == nil or ((@item.price * $game_variables[J::BUY]) / 100) > $game_party.gold
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Get items in possession count
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 99 items are already in possession
if number == 99
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Calculate maximum amount possible to buy
max = ((@item.price * $game_variables[J::BUY]) / 100) == 0 ? 99 : $game_party.gold / ((@item.price * $game_variables[J::BUY]) / 100)
max = [max, 99 - number].min
# Change windows to quantity input mode
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, ((@item.price * $game_variables[J::BUY]) / 100))
@number_window.active = true
@number_window.visible = true
end
end
#--------------------------------------------------------------------------
# * Frame Update (when sell window is active)
# altered 2 lines to allow for price alterations.
#--------------------------------------------------------------------------
def update_sell
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Change windows to initial mode
@command_window.active = true
@dummy_window.visible = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
# Erase help text
@help_window.set_text("")
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get item
@item = @sell_window.item
# Set status window item
@status_window.item = @item
# If item is invalid, or item price is 0 (unable to sell)
if @item == nil or ((@item.price * $game_variables[J::SELL]) / 100) == 0
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Get items in possession count
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
# Maximum quanitity to sell = number of items in possession
max = number
# Change windows to quantity input mode
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@item, max, ((@item.price * $game_variables[J::SELL]) / 100))
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
end
end
#--------------------------------------------------------------------------
# * Frame Update (when quantity input window is active)
# altered 2 lines to allow for price alterations.
#--------------------------------------------------------------------------
def update_number
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Set quantity input window to inactive / invisible
@number_window.active = false
@number_window.visible = false
# Branch by command window cursor position
case @command_window.index
when 0 # buy
# Change windows to buy mode
@buy_window.active = true
@buy_window.visible = true
when 1 # sell
# Change windows to sell mode
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Play shop SE
$game_system.se_play($data_system.shop_se)
# Set quantity input window to inactive / invisible
@number_window.active = false
@number_window.visible = false
# Branch by command window cursor position
case @command_window.index
when 0 # buy
# Buy process
$game_party.lose_gold(@number_window.number * ((@item.price * $game_variables[J::BUY]) / 100))
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
# Refresh each window
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
# Change windows to buy mode
@buy_window.active = true
@buy_window.visible = true
when 1 # sell
# Sell process
$game_party.gain_gold(@number_window.number * ((@item.price * $game_variables[J::SELL]) / 100))
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
# Refresh each window
@gold_window.refresh
@sell_window.refresh
@status_window.refresh
# Change windows to sell mode
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
return
end
end
end