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.

Price Changing

I remember I saw one topic in a forum ( Can't remember which) that gives me a call script code to change prices. Can anyone either give me the code or have another alternative? Cause I want different prices for different towns. :cheers:
 
Try this...

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

# ** RPG::Item

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

 

class RPG::Item

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

  # * Alias Listings

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

  alias_method :changeprices_rpgitm_price,   :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_price

  end

end

 

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

# ** RPG::Armor

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

 

class RPG::Armor

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

  # * Alias Listings

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

  alias_method :changeprices_rpgarm_price, :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_price

  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

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

  def initialize

    changeprices_gmsystem_initialize

    @item_price = Hash.new

    @armor_price = Hash.new

    @weapon_price = Hash.new

  end

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

  # * Reset Item Prices

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

  def reset_item_prices(arr = nil)

    unless arr.is_a?(Array)

      arr = Array.new

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

    end

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

  end

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

  # * Reset Armor Prices

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

  def reset_armor_prices(arr = nil)

    unless arr.is_a?(Array)

      arr = Array.new

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

    end

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

  end

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

  # * Reset Weapon Prices

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

  def reset_weapon_prices(arr = nil)

    unless arr.is_a?(Array)

      arr = Array.new

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

    end

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

  end

end

Using a simple call script, I tested it so it works fine, it aliases the price method of RPG Item, Armor and Weapon and is saved through $game_system. You can also reset your prices too. I've made a couple call scripts to test the system, here's how you do it.

To change prices of things...

Code:
gs = $game_system

gs.item_price[1] = 420

gs.armor_price[1] = 420

gs.weapon_price[1] = 420

To reset prices to default (whats defined in database), do...

Code:
gs = $game_system

gs.reset_item_prices

gs.reset_armor_prices

gs.reset_weapon_prices

Note, when resetting prices to items or other, you can use an array of numbers (ie, [1, 2, 3, 9, 11]) to reset only those items to their default prices specified in the database, same for armors and weapons. If you don't specify an array, it'll automatically clear ALL custom prices set in game back to the default database prices.

This will corrupt saved games (which means just don't try to load any old save files), meaning these prices will be saved and loaded from your save file.

Enjoy :thumb:
 
MCsephiroth13":3t2k294o said:
But if your item is in your inventory, then it will still have the same item for the same price. Why is everyone here so against using a script for this?
Not to mention that you'll have multiple copies of items in your inventory.
 
surengin":1q1c4a2r said:
MCsephiroth13":1q1c4a2r said:
But if your item is in your inventory, then it will still have the same item for the same price. Why is everyone here so against using a script for this?
Maybe becouse we don't know scripts ... Unlike you.
You think I know scripts!? Ha! If there was one person in the whole world who didn't know scripts, it would be me. I just said that because scripts indeed make your life easier sometimes and can be much cleaner than eventing.
 

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