Shop : Change Prices

Shop : Change Prices
Version: 3.5
By: Kain Nobel

Introduction

This script simply allows you to change prices on items, weapons and armors as well as save your changes in your save file. Also, you're able to reset these prices back to whats specified in the database on any/all items, weapons and armor easily.

Features

  • Change prices of items, armors and weapons
  • Price changes are saved/loaded with your save file
  • Can reset prices back to whats set in the database

Script

Shop : Change Prices Spoiler
  1. #===============================================================================
  2. # ** Shop : Change Prices
  3. #===============================================================================
  4.  
  5. if Object.const_defined?(:SDK)
  6.   SDK.log('Shop.ChangePrices', 'Kain Nobel ©', 3.5, '2009.09.01')
  7.   SDK.log_overwrite("RPG::Item".to_sym,   :price=)
  8.   SDK.log_overwrite("RPG::Armor".to_sym,  :price=)
  9.   SDK.log_overwrite("RPG::Weapon".to_sym, :price=)
  10. end
  11.  
  12. #===============================================================================
  13. # ** RPG::Item
  14. #===============================================================================
  15.  
  16. class RPG::Item
  17.   #-----------------------------------------------------------------------------
  18.   # * Alias Listings
  19.   #-----------------------------------------------------------------------------
  20.   alias_method :changeprices_rpgitm_priceget, :price
  21.   #-----------------------------------------------------------------------------
  22.   # * Price
  23.   #-----------------------------------------------------------------------------
  24.   def price
  25.     if $game_system.is_a?(Game_System) && $game_system.item_price.has_key?(id)
  26.       return $game_system.item_price[id]
  27.     end
  28.     changeprices_rpgitm_priceget
  29.   end
  30.   #-----------------------------------------------------------------------------
  31.   # * Price = (value)
  32.   #-----------------------------------------------------------------------------
  33.   def price=(value)
  34.     $game_system.item_price[id] = [value, 0].max
  35.   end
  36. end
  37.  
  38. #===============================================================================
  39. # ** RPG::Armor
  40. #===============================================================================
  41.  
  42. class RPG::Armor
  43.   #-----------------------------------------------------------------------------
  44.   # * Alias Listings
  45.   #-----------------------------------------------------------------------------
  46.   alias_method :changeprices_rpgarm_priceget, :price
  47.   #-----------------------------------------------------------------------------
  48.   # * Price
  49.   #-----------------------------------------------------------------------------
  50.   def price
  51.     if $game_system.is_a?(Game_System) && $game_system.armor_price.has_key?(id)
  52.       return $game_system.armor_price[id]
  53.     end
  54.     changeprices_rpgarm_priceget
  55.   end
  56.   #-----------------------------------------------------------------------------
  57.   # * Price = (value)
  58.   #-----------------------------------------------------------------------------
  59.   def price=(value)
  60.     $game_system.armor_price[id] = [value, 0].max
  61.   end
  62. end
  63.  
  64. #===============================================================================
  65. # ** RPG::Weapon
  66. #===============================================================================
  67.  
  68. class RPG::Weapon
  69.   #-----------------------------------------------------------------------------
  70.   # * Alias Listings
  71.   #-----------------------------------------------------------------------------
  72.   alias_method :changeprices_rpgwpn_price, :price
  73.   #-----------------------------------------------------------------------------
  74.   # * Price
  75.   #-----------------------------------------------------------------------------
  76.   def price
  77.     if $game_system.is_a?(Game_System) && $game_system.weapon_price.has_key?(id)
  78.       return $game_system.weapon_price[id]
  79.     end
  80.     changeprices_rpgwpn_price
  81.   end
  82.   #-----------------------------------------------------------------------------
  83.   # * Price = (value)
  84.   #-----------------------------------------------------------------------------
  85.   def price=(value)
  86.     $game_system.weapon_price[id] = [value, 0].max
  87.   end
  88. end
  89.  
  90. #===============================================================================
  91. # ** Game_System
  92. #===============================================================================
  93.  
  94. class Game_System
  95.   #-----------------------------------------------------------------------------
  96.   # * Public Instance Variables
  97.   #-----------------------------------------------------------------------------
  98.   attr_reader :item_price
  99.   attr_reader :armor_price
  100.   attr_reader :weapon_price
  101.   #-----------------------------------------------------------------------------
  102.   # * Alias Listings
  103.   #-----------------------------------------------------------------------------
  104.   alias_method :changeprices_gmsystem_initialize, :initialize
  105.   #-----------------------------------------------------------------------------
  106.   # * Object Initialization
  107.   #-----------------------------------------------------------------------------
  108.   def initialize
  109.     changeprices_gmsystem_initialize
  110.     @item_price = Hash.new
  111.     @armor_price = Hash.new
  112.     @weapon_price = Hash.new
  113.   end
  114.   #-----------------------------------------------------------------------------
  115.   # * Reset Prices
  116.   #-----------------------------------------------------------------------------
  117.   def reset_prices
  118.     reset_item_prices
  119.     reset_armor_prices
  120.     reset_weapon_prices
  121.   end
  122.   #-----------------------------------------------------------------------------
  123.   # * Reset Item Prices
  124.   #-----------------------------------------------------------------------------
  125.   def reset_item_prices(*args)
  126.     if args.empty?
  127.       $data_items.each {|item| next if item.nil? ; args << item.id}
  128.     end
  129.     args.each {|i| @item_price.delete(i)}
  130.   end
  131.   #-----------------------------------------------------------------------------
  132.   # * Reset Armor Prices
  133.   #-----------------------------------------------------------------------------
  134.   def reset_armor_prices(*args)
  135.     if args.empty?
  136.       $data_armors.each {|armor| next if armor.nil? ; args << armor.id}
  137.     end
  138.     args.each {|i| @armor_price.delete(i)}
  139.   end
  140.   #-----------------------------------------------------------------------------
  141.   # * Reset Weapon Prices
  142.   #-----------------------------------------------------------------------------
  143.   def reset_weapon_prices(*args)
  144.     if args.empty?
  145.       $data_weapons.each {|weapon| next if weapon.nil? ; args << weapon.id}
  146.     end
  147.     args.each {|i| @weapon_price.delete(i)}
  148.   end
  149. end
Expand to see the code.


Instructions

Place Above Main (and Below SDK, only if using). Don't try and modify the prices directly in the script, all that is handled via database and call scripts (see FAQ)

FAQ

Changing prices... Spoiler
In order to change your prices, you'll need to do it via call script. Here's how I would do it...

  1. gs = $game_system
  2. gs.item_price[1] = 1000
  3. gs.armor_price[1] = 1000
  4. gs.weapon_price[1] = 1000
Expand to see the code.

Resetting prices... Spoiler
In this example, I'm only gonna show you how to reset Item prices, you can do the same for armors and weapons...

  1. gs = $game_system
  2. # No argument will reset ALL item prices
  3. gs.reset_item_prices
  4. # An array of item IDs will only reset prices on these items
  5. arr = [1, 2, 3, 4]
  6. gs.reset_item_prices(*arr)
  7. # You can also do it this way...
  8. gs.reset_item_prices(1, 2, 3, 4)
Expand to see the code.


...This will reset prices back to whats set in the database.


Compatibility

This script WILL corrupt old save files!

This script aliases the following methods... Spoiler
RPG::Item.price
RPG::Armor.price
RPG::Weapon.price
Game_System.initialize


Credits and Thanks

Thanks to whoever origionally requested this feature a couple months ago, if you come forward I'll put your name here ;)

Terms and Conditions

Another "Free to use in commercial and non-commercial games" script, but please credit yours truely :thumb:
Very useful, man. I can see this used for shopkeepers that sell items for different prices depending on the area. I don't know why no one's made this before, it's a nice and simple script.
Regi wrote:
Very useful, man. I can see this used for shopkeepers that sell items for different prices depending on the area. I don't know why no one's made this before, it's a nice and simple script.
Except it requires the SDGay.
... No it doesn't...

Instructions

Place Above Main (and Below SDK, only if using). Don't try and modify the prices directly in the script, all that is handled via database and call scripts (see FAQ)

Learn2Read you Sephiroth Fanboy... :tongue:

And look at the code...

  1.  
  2. if Object.const_defined?(:SDK)
  3.   SDK.log('Shop.ChangePrices', 'Kain Nobel ©', 3.5, '2009.06.17')
  4. end
  5.  
Expand to see the code.


Kinda says it all... IF the SDK is there, it uses it.
Oh, well fuck. I thought you could only place it above main if using the SDGay. My b.
... Retard. I guess I shouldn't expect more from a Sephirth buttfuck fanboy :shades: 😀
Slightly updated script so that it'll work with my Shop : Don't Sell Certain Goods system.

That script should be available sometime tonight, I just barely posted it so its still awaiting moderator approval.
wait, i asked for this.

THANK YOU KAIN!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=66675