04-04-2022, 11:24 AM
Shop : Change Prices
Version: 3.5
Version: 3.5
Written by Kain Nobel
Introduction
This is a system which allows you to change shop prices.
Features
- Change prices of items in your shops.
- System automatically resets prices once the shop closes.
Script
Script
Code:
#===============================================================================
# ** Shop : Change Prices
#===============================================================================
if Object.const_defined?(:SDK)
SDK.log('Shop.ChangePrices', 'Kain Nobel ©', 3.5, '2009.09.09')
SDK.log_overwrite("RPG::Item".to_sym, :price=)
SDK.log_overwrite("RPG::Armor".to_sym, :price=)
SDK.log_overwrite("RPG::Weapon".to_sym, :price=)
end
#===============================================================================
# ** RPG::Item
#===============================================================================
class RPG::Item
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :changeprices_rpgitm_priceget, :price
#-----------------------------------------------------------------------------
# * Price
#-----------------------------------------------------------------------------
def price
# If game system defined and item assigned a price key
if $game_system.is_a?(Game_System) && $game_system.item_price.has_key?(id)
# Return custom item price
return $game_system.item_price[id]
end
# The usual
changeprices_rpgitm_priceget
end
#-----------------------------------------------------------------------------
# * Price = (value)
#-----------------------------------------------------------------------------
def price=(value)
# Set custom price
$game_system.item_price[id] = [value, 0].max
end
end
#===============================================================================
# ** RPG::Armor
#===============================================================================
class RPG::Armor
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :changeprices_rpgarm_priceget, :price
#-----------------------------------------------------------------------------
# * Price
#-----------------------------------------------------------------------------
def price
# If game system defined and armor assigned a price key
if $game_system.is_a?(Game_System) && $game_system.armor_price.has_key?(id)
# Return custom armor price
return $game_system.armor_price[id]
end
# The usual
changeprices_rpgarm_priceget
end
#-----------------------------------------------------------------------------
# * Price = (value)
#-----------------------------------------------------------------------------
def price=(value)
# Set custom price
$game_system.armor_price[id] = [value, 0].max
end
end
#===============================================================================
# ** RPG::Weapon
#===============================================================================
class RPG::Weapon
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :changeprices_rpgwpn_price, :price
#-----------------------------------------------------------------------------
# * Price
#-----------------------------------------------------------------------------
def price
# If game system defined and weapon assigned a price key
if $game_system.is_a?(Game_System) && $game_system.weapon_price.has_key?(id)
# Return custom weapon price
return $game_system.weapon_price[id]
end
# The usual
changeprices_rpgwpn_price
end
#-----------------------------------------------------------------------------
# * Price = (value)
#-----------------------------------------------------------------------------
def price=(value)
# Set custom price
$game_system.weapon_price[id] = [value, 0].max
end
end
#===============================================================================
# ** Game_System
#===============================================================================
class Game_System
#-----------------------------------------------------------------------------
# * Public Instance Variables
#-----------------------------------------------------------------------------
attr_reader :item_price
attr_reader :armor_price
attr_reader :weapon_price
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :changeprices_gmsystem_initialize, :initialize
#-----------------------------------------------------------------------------
# * Object Initialization
#-----------------------------------------------------------------------------
def initialize
# The usual
changeprices_gmsystem_initialize
# Reset prices
reset_prices
end
#-----------------------------------------------------------------------------
# * Reset Prices
#-----------------------------------------------------------------------------
def reset_prices
# Initialize price listings (if nil)
@item_price ||= Hash.new
@armor_price ||= Hash.new
@weapon_price ||= Hash.new
# Delete each price
@item_price.each_key {|price| @item_price.delete(price)}
@armor_price.each_key {|price| @armor_price.delete(price)}
@weapon_price.each_key {|price| @weapon_price.delete(price)}
end
end
#===============================================================================
# ** Scene_Shop
#===============================================================================
class Scene_Shop
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :changeprices_scnshop_main, :main
#-----------------------------------------------------------------------------
# * Main
#-----------------------------------------------------------------------------
def main
# The usual
changeprices_scnshop_main
# Reset prices
$game_system.reset_prices
end
end
Instructions
Place below Main and anything that modifies Shops in any major way.
Compatibility
This script was written for RMXP.
This script overwrites the following...
- RPG::Item#price=
- RPG::Armor#price=
- RPG::Weapon#price=
I do suppose these could be aliased. I forget if I had a good reason for an overwrite, this was written eons ago...
(NOTE: This script does call SDK.log_ovewrite if the SDK is in your project. It does not matter if you're using SDK or not, those lines shouldn't interfere with anything.)
Author's Notes
It may sound dangerous, but before you call your shop, you can simply do...
Code:
$data_items[id].price = 100
$data_armors[id].price = 4999
$data_weapons[id].price = 9999
Don't worry; once the shop closes, these prices are reverted back to their normal database values.
You can also do...
Code:
$game_system.item_price[id] = 100
$game_system.armor_price[id] = 4999
$game_system.weapon_price[id] = 9999
...which does the same exact thing. It's whatever you prefer.
Terms and Conditions
Free to use in commercial and non-commercial games. Credits optional, but I do like credits!
