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 : Don't Sell Certain Goods

Shop : Don't Sell Certain Goods
Version: 3.5
By: Kain Nobel

Introduction

This system allows you to specify certain goods to be unsellable in shops, either permanently or temporarily. Alternatively, you can specify that a shop isn't to sell certain good types such as not selling items, armors and/or weapons altogether.

Features

  • Items, armors and weapons can be dubbed permanently unsellable
  • Items, armors and weapons can be dubbed temporarily unsellable
  • Easily make shops that don't buy Item goods
  • Easily make shops that don't buy Armor goods
  • Easily make shops that don't buy Weapon goods
  • Not to mention, easy to use =P

Screenshots

I'd post one but it probably wouldn't help...

Script

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

# ** Shop : Don't Sell Certain Goods

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

 

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

# * SDK Log

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

if Object.const_defined?(:SDK)

  SDK.log('Shop.Don\'tSellCertainGoods', 'Kain Nobel ©', 3.5, '2009.06.17')

end

 

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

# ** Game_Temp

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

 

class Game_Temp

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

  # * Place IDs of permanently unsellable Items here

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

  Unsellable_Items   = []

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

  # * Place IDs of permanently unsellable Armors here

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

  Unsellable_Armors  = []

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

  # * Place IDs of permanently unsellable Weapons here

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

  Unsellable_Weapons = []

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

  # * Public Instance Variables

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

  attr_accessor :nosell_items       # Array of IDs for unsellable items

  attr_accessor :nosell_armors      # Array of IDs for unsellable armors

  attr_accessor :nosell_weapons     # Array of IDs for unsellable weapons

  attr_accessor :cant_sell_items    # Flag meaning all Items are unsellable  

  attr_accessor :cant_sell_armors   # Flag meaning all Armors are unsellable

  attr_accessor :cant_sell_weapons  # Flag meaning all Weapons are unsellable

  attr_accessor :stored_nosell_i    # Hash of prices for unsellable Items

  attr_accessor :stored_nosell_a    # Hash of prices for unsellable Armors

  attr_accessor :stored_nosell_w    # Hash of prices for unsellable 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

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

  # * Reset Unsellable Inventory

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

  def reset_unsellable_inventory(to_nil = false)

    @stored_nosell_i = (to_nil ? nil : Hash.new)

    @stored_nosell_a = (to_nil ? nil : Hash.new)

    @stored_nosell_w = (to_nil ? nil : Hash.new)

  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

    when false then store_unsellables

    end

  end

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

  # * Store Unsellables

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

  def store_unsellables

    $game_temp.stored_nosell_i = Hash.new

    $game_temp.stored_nosell_a = Hash.new

    $game_temp.stored_nosell_w = Hash.new

    @items.each do |id, value|

      unless $game_temp.cant_sell_items

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

      end

      $game_temp.stored_nosell_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

      $game_temp.stored_nosell_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

      $game_temp.stored_nosell_w[id] = $data_weapons[id].price

      $data_weapons[id].price = 0

    end

  end

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

  # * Reset Unsellables

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

  def reset_unsellables(reset_temp = false, to_nil = false)

    $game_temp.reset_unsellables if reset_temp

    $game_temp.stored_nosell_i.each {|id, value| $data_items[id].price   = value}

    $game_temp.stored_nosell_a.each {|id, value| $data_armors[id].price  = value}

    $game_temp.stored_nosell_w.each {|id, value| $data_weapons[id].price = value}

    $game_temp.reset_unsellable_inventory(to_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_updc, :update_command

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

  # * Main

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

  def main

    $game_party.store_unsellables

    nosell_snshop_main

    $game_party.reset_unsellables(true, true)

  end

<span style="color:#000080; font-style:italic;">=begin

<span style="color:#000080; font-style:italic;">  

<span style="color:#000080; font-style:italic;">  # Use this version if you're using SDK, and your command order differs from

<span style="color:#000080; font-style:italic;">  # the standard "Buy", "Sell", "Exit" command order, instead of the other

<span style="color:#000080; font-style:italic;">  # update_command method. Otherwise the other method works for both SDK and non

<span style="color:#000080; font-style:italic;">  

<span style="color:#000080; font-style:italic;">  #-----------------------------------------------------------------------------

<span style="color:#000080; font-style:italic;">  # * Update Command

<span style="color:#000080; font-style:italic;">  #-----------------------------------------------------------------------------

<span style="color:#000080; font-style:italic;">  def update_command

<span style="color:#000080; font-style:italic;">    case @command_window.command

<span style="color:#000080; font-style:italic;">    when SDK::Scene_Commands::Scene_Shop::Buy

<span style="color:#000080; font-style:italic;">      unless $game_party.show_unsellables

<span style="color:#000080; font-style:italic;">        $game_party.show_unsellables = true

<span style="color:#000080; font-style:italic;">        @buy_window.refresh

<span style="color:#000080; font-style:italic;">      end

<span style="color:#000080; font-style:italic;">    when SDK::Scene_Commands::Scene_Shop::Sell

<span style="color:#000080; font-style:italic;">      if $game_party.show_unsellables

<span style="color:#000080; font-style:italic;">        $game_party.show_unsellables = false

<span style="color:#000080; font-style:italic;">        @sell_window.refresh

<span style="color:#000080; font-style:italic;">      end

<span style="color:#000080; font-style:italic;">    end

<span style="color:#000080; font-style:italic;">    nosell_snshop_updc

<span style="color:#000080; font-style:italic;">  end

<span style="color:#000080; font-style:italic;"> 

<span style="color:#000080; font-style:italic;">=end

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

  # * Update Command

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

  def update_command

    case @command_window.index

    when 0

      unless $game_party.show_unsellables

        $game_party.show_unsellables = true

        @buy_window.refresh

      end

    when 1

      if $game_party.show_unsellables

        $game_party.show_unsellables = false

        @sell_window.refresh

      end

    end

    nosell_snshop_updc

  end

end

Instructions

Place Above Main, Below Scene_Debug (and Below SDK, only if using). Please see the FAQ as far as usage and how the system works.

FAQ

Permanently unsellable goods can be placed in the Unsellable_<type> constants within Game_Temp class. What you do is place the item, armor or weapons' IDs as specified in your database in the appropriate arrays. Please refer to the following Game_Temp constants, their headers explain it...

Unsellable_Items
Unsellable_Armors
Unsellable_Weapons


When you specify IDs in these constants, that means you'll never be able to sell those items and you won't have to call the ID when specifying the otherwise temporary unsellables.
There are two ways to set temporarily unsellable goods, and their IDs are stacked along with the Permanent unsellable goods, so you don't have to specify the same IDs all the time. Anyways, to do it, you simply open up your Call Script box right before your shop is called and 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)

You can also do this (but its not recommended for a Call Script box), please note its the same as doing what I showed you above...

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]
You don't want your Weapon shop to buy Items? You don't want your Armor shop to buy Weapons? Easy enough, one of the 3 following methods can be called and it'll make all Items, Armors and/or Weapons unsellable. All you have to do is put whatever appropriate method calls in the Call Script box before your shop is opened through the event...

cant_sell_items
cant_sell_armors
cant_sell_weapons


...and thats it!
In accordance to default shop system, you can't sell goods which have the price of 0. So, in the case that you're on the Sell window, prices of all unsellable goods are set to 0 which (by normal shop system standards) will dub the goods in question to be unsellable. However, when you revisit the Buy window, these prices will be set back to their *real* prices. Please read Compatibility notes...

Also, you never have to manually reset the temp or anything when your close your shop, because it is automatically reset when you exit the shop scene.

Compatibility

This is SDK compatible but not required at all!! Most likely compatible with 99% of custom shop systems, so long as they still use the instances of @window_buy and @window_sell within the Scene_Shop scene.

Also important to note, I made it according to how the default shop system works; if an item has a price of 0, then it is dubbed 'unsellable'. If you're using a custom shop which allows you to sell items with 0 as their price, this script probably won't work with that particular system, I'll write a different version in this case if needed.

Compatible with the latest version of my Shop : Change Prices script. If you're using a version with a date older than "2009.09.01" (Sept 1, 2009), please replace the script with the latest version or you're likely to encounter pricing problems.

Also compatible with my Custom Shop System from my CMS, which I don't think has been posted publically yet since the current SDK version is too low.
Game_Temp.initialize
Scene_Shop.main
Scene_Shop.update_command

Credit & Thanks

Thanks to mining gast and Goody Two-Shoes for pointing out a bug I overlooked ;)

Terms and Conditions

Another "Free to use in commercial and non-commercial games" script, so long as you credit yours truely!
 
Yes it's useful, except that it gives me an error when I buy something, and then close the shop window:

DSCG is my name for your script.

Script 'DSCG' line 115: NoMethodError occured.
undefined method 'each' for nil:NilClass

:( just when I started to like this script...
 
One more thing Kain Nobel, can you add categories like in the item description you scripted?

As in like, more than just armor, item, or weapons type.

EDIT: Oh wait, i had that error too. :(
 
Updated! It was because I set @stored_i, @stored_a and @stored_w to nil during the reset, instead of them each being Hash classes (saves a tiny bit on memory). They still get set to nil when you exit the shop scene though but now it should work without the error, those variables are only set to nil now when you exit the shop.

Another small update was I moved the enabling/disabling of the 'unsellable' items from update_buy/update_sell to update_command; it remedied the brief 'flicker' from the windows refreshing when they first become active/visible, however it may cause a small lag if your shops happen to have alot of items (slow Ruby, meh)

The most important note is that it works now, thanks for your feedback guys! :thumb:

EDIT : I'm making more minor changes to the script, please check back in 30 mins and refresh the page

EDIT2: **Okay, updates finished go ahead and click refresh and replace the other version with this one. Last problem I had to fix was it was corrupting old save files, I try to avoid this issue whenever possible so players can carry over their old save files when new versions of existing games are released :wink:
 
Thank you for the nice comment mining gast!

Goody Two-Shoes":1ksbq4tn said:
One more thing Kain Nobel, can you add categories like in the item description you scripted?

As in like, more than just armor, item, or weapons type.

I don't think I understand what you're trying to tell me, can you explain a little further what you're talking about?

Come to think of it (maybe its along the lines of what you're talking about), I wonder if Seph/Atoa's Materia system has a Materia shop with it? I'm putting it on my to-do's list to look at the Materia system, and make an optional plugin for unsellable Materias if it is needed. If you happen to have anything, like maybe a Skill shop that allows you to sell your skills or something of that nature, post a link/demo and I'll see about making an optional plugin for that as well.
 
Kain Nobel, I simply meant that, in the Item Description script you made, you can add more types of shop.

As in like, instead of generic armor, weapons, and other item shops, I can add more.

Is there any way to add more types of "classes" for the equipments?
 
You're welcome, I'm glad everybody is liking this :)

Goody Two-Shoes, I remember what we talked about in IRC and yes I'm still going to eventually create that shop categories system. For now I'm resting my head from RGSS and reviving my pixel skills but I'll remember to work on it when I am back.

Thanks you guys for your comments! See ya in a few weeks!
 

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