Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

Code:
#===============================================================================

# ** Shop : Change Prices

#===============================================================================

 

if Object.const_defined?(:SDK)

  SDK.log('Shop.ChangePrices', 'Kain Nobel ©', 3.5, '2009.09.01')

  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.is_a?(Game_System) && $game_system.item_price.has_key?(id)

      return $game_system.item_price[id]

    end

    changeprices_rpgitm_priceget

  end

  #-----------------------------------------------------------------------------

  # * Price = (value)

  #-----------------------------------------------------------------------------

  def price=(value)

    $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.is_a?(Game_System) && $game_system.armor_price.has_key?(id)

      return $game_system.armor_price[id]

    end

    changeprices_rpgarm_priceget

  end

  #-----------------------------------------------------------------------------

  # * Price = (value)

  #-----------------------------------------------------------------------------

  def price=(value)

    $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.is_a?(Game_System) && $game_system.weapon_price.has_key?(id)

      return $game_system.weapon_price[id]

    end

    changeprices_rpgwpn_price

  end

  #-----------------------------------------------------------------------------

  # * Price = (value)

  #-----------------------------------------------------------------------------

  def price=(value)

    $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

    changeprices_gmsystem_initialize

    @item_price = Hash.new

    @armor_price = Hash.new

    @weapon_price = Hash.new

  end

  #-----------------------------------------------------------------------------

  # * Reset Prices

  #-----------------------------------------------------------------------------

  def reset_prices

    reset_item_prices

    reset_armor_prices

    reset_weapon_prices

  end

  #-----------------------------------------------------------------------------

  # * Reset Item Prices

  #-----------------------------------------------------------------------------

  def reset_item_prices(*args)

    if args.empty?

      $data_items.each {|item| next if item.nil? ; args << item.id}

    end

    args.each {|i| @item_price.delete(i)}

  end

  #-----------------------------------------------------------------------------

  # * Reset Armor Prices

  #-----------------------------------------------------------------------------

  def reset_armor_prices(*args)

    if args.empty?

      $data_armors.each {|armor| next if armor.nil? ; args << armor.id}

    end

    args.each {|i| @armor_price.delete(i)}

  end

  #-----------------------------------------------------------------------------

  # * Reset Weapon Prices

  #-----------------------------------------------------------------------------

  def reset_weapon_prices(*args)

    if args.empty?

      $data_weapons.each {|weapon| next if weapon.nil? ; args << weapon.id}

    end

    args.each {|i| @weapon_price.delete(i)}

  end

end

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

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

Code:
gs = $game_system

gs.item_price[1] = 1000

gs.armor_price[1] = 1000

gs.weapon_price[1] = 1000
In this example, I'm only gonna show you how to reset Item prices, you can do the same for armors and weapons...

Code:
gs = $game_system

# No argument will reset ALL item prices

gs.reset_item_prices

# An array of item IDs will only reset prices on these items

arr = [1, 2, 3, 4]

gs.reset_item_prices(*arr)

# You can also do it this way...

gs.reset_item_prices(1, 2, 3, 4)

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

Compatibility

This script WILL corrupt old save files!

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":3fj2a1mq said:
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.
 

Jason

Awesome Bro

... 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...

Code:
 

if Object.const_defined?(:SDK)

  SDK.log('Shop.ChangePrices', 'Kain Nobel ©', 3.5, '2009.06.17')

end

 

Kinda says it all... IF the SDK is there, it uses it.
 
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.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top