#======================================================================
========
# Scene_ShopVariable [VX]
#------------------------------------------------------------------------------
# Introduces a shop in your game, but, instead of use money, the monetary
# unity is defined by a variable.
#------------------------------------------------------------------------------
# Site :
http://www.rpgrevolution.com/# Brazil's Site :
http://www.mundorpgmaker.com/# Author : Kyo Panda
# Release in : October 04 of 2010
# Version : 1.1
#==============================================================================
#==============================================================================
# Special Thanks:
#------------------------------------------------------------------------------
# • pedro_severo : For the idealization and improvements in script.
#==============================================================================
#==============================================================================
# How to use:
#------------------------------------------------------------------------------
#
# #--------------------------------------------------------------------------
# # Setup
# #--------------------------------------------------------------------------
#
# • Paste the script above of "▼ Main Proccess" below of "▼ Materials"
# in the Script Editor of RPG Maker VX.
#
# • Setup the script in guide "Configuration" right above.
#
# #--------------------------------------------------------------------------
# # Utilization
# #--------------------------------------------------------------------------
#
# Use these codes with the "Event Command" "Script" in any event:
#
# • To define the shop's variable:
# VShop.var = Variable ID
#
# • To turn on the function of shop by variables:
# VShop.on
#
# • To turn off the function of shop by variables:
# VShop.off
#
# • To change the symbol shown in the shop:
# VShop.symbol = "Symbol"
#
# • To change the text of buy in the shop:
# VShop.buy_string = "Text"
#
# • To change the text of sell in the shop:
# VShop.sell_string = "Text"
#
# • To change the text of exit in the shop:
# VShop.exit_string = "Text"
#
# • To show or not the symbol at side of the itens price when buying:
# Define true to show and false to not show.
# VShop.show_symbol = true / false
#
# • To hide the option of buying in shop:
# Define true to hide and false to not hide.
# VShop.hidden_buy = true / false
#
# • To hide the option of selling in shop:
# Define true to hide and false to not hide.
# VShop.hidden_sell = true / false
#
#==============================================================================
#==============================================================================
# Version History:
#------------------------------------------------------------------------------
# • Version 1.1: October 05 of 2010
# * Added the option of change the texts of buy, sell and exit.
# * Added the option of show or not the symbol at the itens side in the
# buying time.
# * Added the option of hide the options of buy and sell..
# • Version 1.0: October 04 of 2010
# * First script version..
#==============================================================================
#==============================================================================
# VShop_Config
#------------------------------------------------------------------------------
# Configuration class of the script Scene_ShopVariable.
#==============================================================================
module VShop_Config
#--------------------------------------------------------------------------
# Configuration
#--------------------------------------------------------------------------
# Define here the default variable ID of the shop by variables.
DEFAULT_VARIABLE = 1
# Define here the default symbol used by the script.
# The name must be between quotes ("") or apostrophes ('').
DEFAULT_SYMBOL = "P"
# Define here the default state of the shop, if is turned on or not.
# Define true to turned on and false to turned off.
DEFAULT_STATE = false
# Define here the default texts that will be shown in the shop.
# The texts must be between quotes ("") or apostrophes ('').
DEFAULT_BUY = "Buy" # Buy
DEFAULT_SELL = "Sell" # Sell
DEFAULT_EXIT = "Exit" # Exit
# Define here if you wish to show the symbol at the itens side in shop,
# by default.
# Define true to show and false to not show.
DEFAULT_SHOW_SYMBOL = true
# Define here if you wish to hide the options of buy or sell by default.
# Define true to hide and false to not hide.
DEFAULT_HIDDEN_BUY = false # Buy
DEFAULT_HIDDEN_SELL = false # Sell
#--------------------------------------------------------------------------
# End of the configuration
#--------------------------------------------------------------------------
end
#--------------------------------------------------------------------------
# Define the key "Scene_ShopVariable" in hash $kpanda_scripts as true
#--------------------------------------------------------------------------
$kpanda_scripts = {} if $kpanda_scripts.nil?
$kpanda_scripts["Scene_ShopVariable"] = true
#==============================================================================
# VShop
#------------------------------------------------------------------------------
# Operation class of the script Scene_ShopVariable.
#==============================================================================
module VShop
#--------------------------------------------------------------------------
# Definition of the variable of the variable shop
# variable_id : Variable's ID
#--------------------------------------------------------------------------
def self.var=(variable_id)
return $game_temp.vshop_variable = variable_id
end
#--------------------------------------------------------------------------
# Turn on the shop by variables
#--------------------------------------------------------------------------
def self.on
return $game_temp.vshop_active = true
end
#--------------------------------------------------------------------------
# Turn off the shop by variables
#--------------------------------------------------------------------------
def self.off
return $game_temp.vshop_active = false
end
#--------------------------------------------------------------------------
# Definition of the symbol of the shop by variables
# symbol : New symbol
#--------------------------------------------------------------------------
def self.symbol=(symbol)
return $game_temp.vshop_symbol = symbol
end
#--------------------------------------------------------------------------
# Change the text of buy in the shop by variables
# string : New String
#--------------------------------------------------------------------------
def self.buy_string=(string)
return $game_temp.vshop_buy_string = string
end
#--------------------------------------------------------------------------
# Change the text of sell in the shop by variables
# string : New String
#--------------------------------------------------------------------------
def self.sell_string=(string)
return $game_temp.vshop_sell_string = string
end
#--------------------------------------------------------------------------
# Change the text of exit in the shop by variables
# string : New String
#--------------------------------------------------------------------------
def self.exit_string=(string)
return $game_temp.vshop_exit_string = string
end
#--------------------------------------------------------------------------
# Show the symbol at itens side
# state : New state
#--------------------------------------------------------------------------
def self.show_symbol=(state)
return $game_temp.vshop_show_symbol = state
end
#--------------------------------------------------------------------------
# Hide the buy option at the shop by variable
# state : New state
#--------------------------------------------------------------------------
def self.hidden_buy=(state)
return $game_temp.vshop_hidden_buy = state
end
#--------------------------------------------------------------------------
# Hide the sell option at the shop by variable
# state : New state
#--------------------------------------------------------------------------
def self.hidden_sell=(state)
return $game_temp.vshop_hidden_sell = state
end
end
#==============================================================================
# Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# The instance of this class is referenced by $game_temp.
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# Public instance variables
#--------------------------------------------------------------------------
attr_accessor :vshop_active # Activity of the shop by variables
attr_accessor :vshop_symbol # Symbol of the shop by variables
attr_accessor :vshop_variable # Variable of the shop by variables
attr_accessor :vshop_buy_string # Buy text
attr_accessor :vshop_sell_string # Sell text
attr_accessor :vshop_exit_string # Exit text
attr_accessor :vshop_show_symbol # Exhibition of the symbol
attr_accessor :vshop_hidden_buy # Definition of the hide buy
attr_accessor :vshop_hidden_sell # Definition of the hide sell
#--------------------------------------------------------------------------
# Alias of object initialization
#--------------------------------------------------------------------------
alias kpnsvs0001_initialize initialize
#--------------------------------------------------------------------------
# Object initialization
#--------------------------------------------------------------------------
def initialize
@vshop_active = VShop_Config::DEFAULT_STATE
@vshop_symbol = VShop_Config::DEFAULT_SYMBOL
@vshop_variable = VShop_Config::DEFAULT_VARIABLE
@vshop_buy_string = VShop_Config::DEFAULT_BUY
@vshop_sell_string = VShop_Config::DEFAULT_SELL
@vshop_exit_string = VShop_Config::DEFAULT_EXIT
@vshop_show_symbol = VShop_Config::DEFAULT_SHOW_SYMBOL
@vshop_hidden_buy = VShop_Config::DEFAULT_HIDDEN_BUY
@vshop_hidden_sell = VShop_Config::DEFAULT_HIDDEN_SELL
kpnsvs0001_initialize
end
end
#==============================================================================
# Window_Base
#------------------------------------------------------------------------------
# This is a superclass of all windows in the game.
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# Draw number with currency unit
# value : Number (gold, etc)
# x : Draw spot x-coordinate
# y : Draw spot y-coordinate
# width : Width
# symbol : Monetary unity's symbol
#--------------------------------------------------------------------------
def draw_currency_value_ex(value, x, y, width, symbol = Vocab::gold)
cx = contents.text_size(symbol).width
self.contents.font.color = normal_color
self.contents.draw_text(x, y, width - cx - 2, WLH, value, 2)
self.contents.font.color = system_color
self.contents.draw_text(x, y, width, WLH, symbol, 2)
end
end
#==============================================================================
# Window_ShopVariable
#------------------------------------------------------------------------------
# Window responsable by the exhibition of the variable in possesion by party.
#==============================================================================
class Window_ShopVariable < Window_Base
#--------------------------------------------------------------------------
# Public instance variables
#--------------------------------------------------------------------------
attr_accessor :variable # Window variable
attr_accessor :symbol # Window symbol
#--------------------------------------------------------------------------
# Object Initialization
# x : Window x-coordinate
# y : Window y-coordinate
# variable : Variable that will be drawn
# symbol : Symbol that will be drawn
#--------------------------------------------------------------------------
def initialize(x, y, variable, symbol)
super(x, y, 160, WLH + 32)
@variable = variable
@symbol = symbol
refresh
end
#--------------------------------------------------------------------------
# Update
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_currency_value_ex(@variable, 4, 0, 120, @symbol)
end
end
#==============================================================================
# Window_ShopBuy
#------------------------------------------------------------------------------
# This window displays buyable goods on the shop screen.
#==============================================================================
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# Alias of draw item
#--------------------------------------------------------------------------
alias kpnsvs0001_draw_item draw_item
#--------------------------------------------------------------------------
# Desenho do item
# index : Item number
#--------------------------------------------------------------------------
def draw_item(index)
if $game_temp.vshop_active
item = @data[index]
number = $game_party.item_number(item)
enabled = (item.price <= $game_variables[$game_temp.vshop_variable] and
number < 99)
rect = item_rect(index)
self.contents.clear_rect(rect)
draw_item_name(item, rect.x, rect.y, enabled)
rect.width -= 4
if $game_temp.vshop_show_symbol
rect.width -= self.contents.text_size($game_temp.vshop_symbol).width
rect.width -= 4
end
self.contents.draw_text(rect, item.price, 2)
if $game_temp.vshop_show_symbol
rect.width += self.contents.text_size($game_temp.vshop_symbol).width
rect.width += 4
self.contents.font.color = system_color
self.contents.draw_text(rect, $game_temp.vshop_symbol, 2)
self.contents.font.color = normal_color
end
else
kpnsvs0001_draw_item(index)
end
end
end
#==============================================================================
# Window_ShopNumber
#------------------------------------------------------------------------------
# This window is for inputting quantity of items to buy or sell on the
# shop screen.
#==============================================================================
class Window_ShopNumber < Window_Base
#--------------------------------------------------------------------------
# Alias of update
#--------------------------------------------------------------------------
alias kpnsvs0001_refresh refresh
#--------------------------------------------------------------------------
# Update
#--------------------------------------------------------------------------
def refresh
if $game_temp.vshop_active
y = 96
self.contents.clear
draw_item_name(@item, 0, y)
self.contents.font.color = normal_color
self.contents.draw_text(212, y, 20, WLH, "×")
self.contents.draw_text(248, y, 20, WLH, @number, 2)
self.cursor_rect.set(244, y, 28, WLH)
draw_currency_value_ex(@price * @number, 4, y + WLH * 2, 264,
$game_temp.vshop_symbol)
else
kpnsvs0001_refresh
end
end
end
#==============================================================================
# Scene_Shop
#------------------------------------------------------------------------------
# This class performs shop screen processing.
#==============================================================================
class Scene_Shop < Scene_Base
#--------------------------------------------------------------------------
# Alias of object initialization
#--------------------------------------------------------------------------
alias kpnsvs0001_start start
#--------------------------------------------------------------------------
# Object initialization
#--------------------------------------------------------------------------
def start
kpnsvs0001_start
if $game_temp.vshop_active
@gold_window = Window_ShopVariable.new(384, 56,
$game_variables[$game_temp.vshop_variable], $game_temp.vshop_symbol)
end
end
#--------------------------------------------------------------------------
# Alias of create command window
#--------------------------------------------------------------------------
alias kpnsvs0001_create_command_window create_command_window
#--------------------------------------------------------------------------
# Create command window
#--------------------------------------------------------------------------
def create_command_window
if $game_temp.vshop_active
commands = []
s1 = $game_temp.vshop_buy_string
s2 = $game_temp.vshop_sell_string
s3 = $game_temp.vshop_exit_string
commands << s1 unless $game_temp.vshop_hidden_buy
commands << s2 unless $game_temp.vshop_hidden_sell
commands << s3
@command_window = Window_Command.new(384, commands, commands.size)
@command_window.y = 56
if $game_temp.shop_purchase_only
@command_window.commands.each_index do |i|
if @command_window.commands[i] == $game_temp.vshop_sell_string
@command_window.draw_item(i, false)
end
end
end
else
kpnsvs0001_create_command_window
end
end
#--------------------------------------------------------------------------
# Alias of update command selection
#--------------------------------------------------------------------------
alias kpnsvs0001_update_command_selection update_command_selection
#--------------------------------------------------------------------------
# Update command selection
#--------------------------------------------------------------------------
def update_command_selection
if $game_temp.vshop_active
if Input.trigger?(Input::

Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
case @command_window.commands[@command_window.index]
when $game_temp.vshop_buy_string # Buy
Sound.play_decision
@command_window.active = false
@dummy_window.visible = false
@buy_window.active = true
@buy_window.visible = true
@buy_window.refresh
@status_window.visible = true
when $game_temp.vshop_sell_string # Sell
if $game_temp.shop_purchase_only
Sound.play_buzzer
else
Sound.play_decision
@command_window.active = false
@dummy_window.visible = false
@sell_window.active = true
@sell_window.visible = true
@sell_window.refresh
end
when $game_temp.vshop_exit_string # Exit
Sound.play_decision
$scene = Scene_Map.new
end
end
else
kpnsvs0001_update_command_selection
end
end
#--------------------------------------------------------------------------
# Alias of update buy item selection
#--------------------------------------------------------------------------
alias kpnsvs0001_update_buy_selection update_buy_selection
#--------------------------------------------------------------------------
# Update buy item selection
#--------------------------------------------------------------------------
def update_buy_selection
if $game_temp.vshop_active
@status_window.item = @buy_window.item
if Input.trigger?(Input::

Sound.play_cancel
@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
number = $game_party.item_number(@item)
if @item == nil or @item.price >
$game_variables[$game_temp.vshop_variable] or number == 99
Sound.play_buzzer
else
Sound.play_decision
max = @item.price == 0 ? 99 :
$game_variables[$game_temp.vshop_variable] / @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
else
kpnsvs0001_update_buy_selection
end
end
#--------------------------------------------------------------------------
# Alias of update sell item selection
#--------------------------------------------------------------------------
alias kpnsvs0001_update_sell_selection update_sell_selection
#--------------------------------------------------------------------------
# Update sell item selection
#--------------------------------------------------------------------------
def update_sell_selection
if $game_temp.vshop_active
if Input.trigger?(Input::

Sound.play_cancel
@command_window.active = true
@dummy_window.visible = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
@help_window.set_text("")
elsif Input.trigger?(Input::C)
@item = @sell_window.item
@status_window.item = @item
if @item == nil or @item.price == 0
Sound.play_buzzer
else
Sound.play_decision
max = $game_party.item_number(@item)
@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
else
kpnsvs0001_update_sell_selection
end
end
#--------------------------------------------------------------------------
# Alias of confirm number input
#--------------------------------------------------------------------------
alias kpnsvs0001_decide_number_input decide_number_input
#--------------------------------------------------------------------------
# Confirm number input
#--------------------------------------------------------------------------
def decide_number_input
if $game_temp.vshop_active
Sound.play_shop
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0 # Buy
$game_variables[$game_temp.vshop_variable] -=
@number_window.number * @item.price
$game_party.gain_item(@item, @number_window.number)
@gold_window.variable = $game_variables[$game_temp.vshop_variable]
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
@buy_window.active = true
@buy_window.visible = true
when 1 # Sell
$game_variables[$game_temp.vshop_variable] +=
@number_window.number * (@item.price / 2)
$game_party.lose_item(@item, @number_window.number)
@gold_window.variable = $game_variables[$game_temp.vshop_variable]
@gold_window.refresh
@sell_window.refresh
@status_window.refresh
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
end
else
kpnsvs0001_decide_number_input
end
end
end