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.

Preventing selling

So erm. I searched the support forum and I still hadn't found any about preventing selling.

You see, I find people selling cakes to a blacksmith is stupid. Because of that, is there any way to prevent people from selling certain items to certain stores?
Thanks in advance.
 
I think that this might need to go in "Script Requests," as the engine doesn't really cover this. I can visualize the kinds of coding that you'd need, but I'm not anywhere near good enough with RGSS to actually make this work.

Then again, standard RPG economics don't make any sense. Why do items that you sell not stay in the shop? Why will merchants pay the same price for Iron Swords that you sell back, regardless of how many you sell? Making a realistic economy for such a game would be interesting, but a lot of work, especially if you took into account all the factors that you'd logically have to consider-- demand, supply, competition from neighbors, depreciation of equipment, etc.

(Of course, if you ask me, a blacksmith might very well want to buy some cakes. Maybe they're for his children, or maybe he wants them to court the mayor's daughter, or maybe he just has a sweet tooth. Pounding on a forge all day can really give you an appetite.)
 
I'm sure there is some way you could do it with events, but if you wanted to do this for alot of different shops it'd be a pain in the arse. Conveniently, I do have a script I wrote for this kind of thing and its flexible so there is more than one way to use it...

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

# ** Shop : Do Not Sell Certain Goods

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

 

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

# * SDK Log

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

if Object.const_defined?(:SDK)

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

end

 

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

# ** Game_Temp

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

 

class Game_Temp

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

  # * Place IDs of permanently unsellable Items here

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

  Unsellable_Items   = [1]

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

  # * Place IDs of permanently unsellable Armors here

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

  Unsellable_Armors  = [1]

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

  # * Place IDs of permanently unsellable Weapons here

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

  Unsellable_Weapons = [1]

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

  # * Public Instance Variables

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

  attr_accessor :nosell_items

  attr_accessor :nosell_armors

  attr_accessor :nosell_weapons

  attr_accessor :cant_sell_items

  attr_accessor :cant_sell_armors

  attr_accessor :cant_sell_weapons

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

  # * Alias Listings

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

  alias_method :nosell_gmtemp_initialize, :initialize

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

  # * Object Initialization

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

  def initialize

    nosell_gmtemp_initialize

    reset_unsellables

  end

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

  # * Reset Unsellables

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

  def reset_unsellables

    @nosell_items       = Unsellable_Items.dup

    @nosell_armors      = Unsellable_Armors.dup

    @nosell_weapons     = Unsellable_Weapons.dup

    @cant_sell_items    = false

    @cant_sell_armors   = false

    @cant_sell_weapons  = false

  end

end

 

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

# ** Game_Party

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

 

class Game_Party

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

  # * Public Instance Variables

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

  attr_reader :show_unsellables

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

  # * Show Unsellables = (boolean)

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

  def show_unsellables=(boolean)

    @show_unsellables = (boolean == true)

    case boolean

    when true  then reset_unsellables(false)

    when false then store_unsellables

    end

  end

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

  # * Store Unsellables

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

  def store_unsellables

    @stored_i = Hash.new

    @stored_a = Hash.new

    @stored_w = Hash.new

    @items.each do |id, value|

      unless $game_temp.cant_sell_items

        next unless $game_temp.nosell_items.include?(id)

      end

      @stored_i[id] = $data_items[id].price

      $data_items[id].price = 0

    end

    @armors.each do |id, value|

      unless $game_temp.cant_sell_armors

        next unless $game_temp.nosell_armors.include?(id)

      end

      @stored_a[id] = $data_armors[id].price

      $data_armors[id].price = 0

    end

    @weapons.each do |id, value|

      unless $game_temp.cant_sell_weapons

        next unless $game_temp.nosell_weapons.include?(id)

      end

      @stored_w[id] = $data_weapons[id].price

      $data_weapons[id].price = 0

    end

  end

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

  # * Reset Unsellables

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

  def reset_unsellables(reset_temp = false)

    $game_temp.reset_unsellables if reset_temp

    @stored_i.each {|id, value| $data_items[id].price   = value}

    @stored_a.each {|id, value| $data_armors[id].price  = value}

    @stored_w.each {|id, value| $data_weapons[id].price = value}

    @stored_i = @stored_a = @stored_w = nil

  end

end

 

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

# ** Interpreter

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

 

class Interpreter

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

  # * Can't Sell Items

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

  def cant_sell_items

    $game_temp.cant_sell_items = true

  end

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

  # * Can't Sell Armors

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

  def cant_sell_armors

    $game_temp.cant_sell_armors = true

  end

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

  # * Can't Sell Weapons

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

  def cant_sell_weapons

    $game_temp.cant_sell_weapons = true

  end

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

  # * No Sell Items

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

  def nsI(*item_ids)

    item_ids.each do |id|

      next if $game_temp.nosell_items.include?(id)

      $game_temp.nosell_items << id

    end

  end

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

  # * No Sell Armors

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

  def nsA(*armor_ids)

    armor_ids.each do |id|

      next if $game_temp.nosell_armors.include?(id)

      $game_temp.nosell_armors << id

    end

  end

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

  # * No Sell Weapons

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

  def nsW(*weapon_ids)

    weapon_ids.each do |id|

      next if $game_temp.nosell_weapons.include?(id)

      $game_temp.nosell_weapons << id

    end

  end

end

 

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

# ** Scene_Shop

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

 

class Scene_Shop

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

  # * Alias Listings

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

  alias_method :nosell_snshop_main,       :main

  alias_method :nosell_snshop_updatebuy,  :update_buy

  alias_method :nosell_snshop_updatesell, :update_sell

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

  # * Main

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

  def main

    $game_party.store_unsellables

    nosell_snshop_main

    $game_party.reset_unsellables(true)

  end

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

  # * Update Buy

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

  def update_buy

    unless $game_party.show_unsellables

      $game_party.show_unsellables = true

      @buy_window.refresh

      return

    end

    nosell_snshop_updatebuy

  end

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

  # * Update Sell

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

  def update_sell

    if $game_party.show_unsellables

      $game_party.show_unsellables = false

      @sell_window.refresh

      return

    end

    nosell_snshop_updatesell

  end

end

 

First off, in Game_Temp class there are 3 constants, Unsellable_Items, Unsellable_Armors and Unsellable_Weapons; with these, you put ID's of goods you never want to sell, EVER! This prevents you from having to repeatedly put the same IDs in the temporary unsellables over and over, if its something you don't ever want sold period.

As far as setting temporarily unsellable goods (only this shop or that shop can't buy these), its again all handled through Game_Temp, but I made shortcut methods in Interpreter so call scripts for these things will fit.

Esentially, you can do...

Code:
$game_temp.nosell_items += [1, 2, 3, 4, 5, ...]

$game_temp.nosell_armors += [1, 2, 3, 4, 5, ...]

$game_temp.nosell_weapons += [1, 2, 3, 4, 5, ...]

...but that is cumbersome in a call script box, so (recommended) you can also do...

Code:
# nsI : Stands for "No Sell Items"

nsI(1, 2, 3, 4, 5, ...)

# nsA : Stands for "No Sell Armors"

nsA(1, 2, 3, 4, 5, ...)

# nsW : Stands for "No Sell Weapons"

nsW(1, 2, 3, 4, 5, ...)

Lastly, if you don't want to sell ANY items, weapons and/or armors, you can put this in a call script box...

Code:
cant_sell_items

cant_sell_armors

cant_sell_weapons

Don't put an = true, the Interpreter knows what you're talking about because they're just shortcut methods for $game_temp.cant_sell_<goods> = true
What it does, for the items, armors and weapons you specify, it basically sets their price temporarily to 0. With the default shop system concept, you can't sell items which have 0 as their price, so the item will be blacked out on the Sell window. However, when you visit the Buy window the origional prices are restored so you can still buy these items at their normal price, but you can't sell them

When I find time, I'll delete this from your post and try and make an 'official' topic for the script, but if you have any questions or issues please PM me because I might not remember this topic.

Enjoy :thumb:
 

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