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

Shop : Don't Sell Certain Goods Spoiler
  1. #===============================================================================
  2. # ** Shop : Don't Sell Certain Goods
  3. #===============================================================================
  4.  
  5. #-------------------------------------------------------------------------------
  6. # * SDK Log
  7. #-------------------------------------------------------------------------------
  8. if Object.const_defined?(:SDK)
  9.   SDK.log('Shop.Don\'tSellCertainGoods', 'Kain Nobel ©', 3.5, '2009.06.17')
  10. end
  11.  
  12. #===============================================================================
  13. # ** Game_Temp
  14. #===============================================================================
  15.  
  16. class Game_Temp
  17.   #-----------------------------------------------------------------------------
  18.   # * Place IDs of permanently unsellable Items here
  19.   #-----------------------------------------------------------------------------
  20.   Unsellable_Items   = []
  21.   #-----------------------------------------------------------------------------
  22.   # * Place IDs of permanently unsellable Armors here
  23.   #-----------------------------------------------------------------------------
  24.   Unsellable_Armors  = []
  25.   #-----------------------------------------------------------------------------
  26.   # * Place IDs of permanently unsellable Weapons here
  27.   #-----------------------------------------------------------------------------
  28.   Unsellable_Weapons = []
  29.   #-----------------------------------------------------------------------------
  30.   # * Public Instance Variables
  31.   #-----------------------------------------------------------------------------
  32.   attr_accessor :nosell_items       # Array of IDs for unsellable items
  33.   attr_accessor :nosell_armors      # Array of IDs for unsellable armors
  34.   attr_accessor :nosell_weapons     # Array of IDs for unsellable weapons
  35.   attr_accessor :cant_sell_items    # Flag meaning all Items are unsellable  
  36.   attr_accessor :cant_sell_armors   # Flag meaning all Armors are unsellable
  37.   attr_accessor :cant_sell_weapons  # Flag meaning all Weapons are unsellable
  38.   attr_accessor :stored_nosell_i    # Hash of prices for unsellable Items
  39.   attr_accessor :stored_nosell_a    # Hash of prices for unsellable Armors
  40.   attr_accessor :stored_nosell_w    # Hash of prices for unsellable Weapons
  41.   #-----------------------------------------------------------------------------
  42.   # * Alias Listings
  43.   #-----------------------------------------------------------------------------
  44.   alias_method :nosell_gmtemp_initialize, :initialize
  45.   #-----------------------------------------------------------------------------
  46.   # * Object Initialization
  47.   #-----------------------------------------------------------------------------
  48.   def initialize
  49.     nosell_gmtemp_initialize
  50.     reset_unsellables
  51.   end
  52.   #-----------------------------------------------------------------------------
  53.   # * Reset Unsellables
  54.   #-----------------------------------------------------------------------------
  55.   def reset_unsellables
  56.     @nosell_items       = Unsellable_Items.dup
  57.     @nosell_armors      = Unsellable_Armors.dup
  58.     @nosell_weapons     = Unsellable_Weapons.dup
  59.     @cant_sell_items    = false
  60.     @cant_sell_armors   = false
  61.     @cant_sell_weapons  = false
  62.   end
  63.   #-----------------------------------------------------------------------------
  64.   # * Reset Unsellable Inventory
  65.   #-----------------------------------------------------------------------------
  66.   def reset_unsellable_inventory(to_nil = false)
  67.     @stored_nosell_i = (to_nil ? nil : Hash.new)
  68.     @stored_nosell_a = (to_nil ? nil : Hash.new)
  69.     @stored_nosell_w = (to_nil ? nil : Hash.new)
  70.   end
  71. end
  72.  
  73. #===============================================================================
  74. # ** Game_Party
  75. #===============================================================================
  76.  
  77. class Game_Party
  78.   #-----------------------------------------------------------------------------
  79.   # * Public Instance Variables
  80.   #-----------------------------------------------------------------------------
  81.   attr_reader :show_unsellables
  82.   #-----------------------------------------------------------------------------
  83.   # * Show Unsellables = (boolean)
  84.   #-----------------------------------------------------------------------------
  85.   def show_unsellables=(boolean)
  86.     @show_unsellables = (boolean == true)
  87.     case boolean
  88.     when true  then reset_unsellables
  89.     when false then store_unsellables
  90.     end
  91.   end
  92.   #-----------------------------------------------------------------------------
  93.   # * Store Unsellables
  94.   #-----------------------------------------------------------------------------
  95.   def store_unsellables
  96.     $game_temp.stored_nosell_i = Hash.new
  97.     $game_temp.stored_nosell_a = Hash.new
  98.     $game_temp.stored_nosell_w = Hash.new
  99.     @items.each do |id, value|
  100.       unless $game_temp.cant_sell_items
  101.         next unless $game_temp.nosell_items.include?(id)
  102.       end
  103.       $game_temp.stored_nosell_i[id] = $data_items[id].price
  104.       $data_items[id].price = 0
  105.     end
  106.     @armors.each do |id, value|
  107.       unless $game_temp.cant_sell_armors
  108.         next unless $game_temp.nosell_armors.include?(id)
  109.       end
  110.       $game_temp.stored_nosell_a[id] = $data_armors[id].price
  111.       $data_armors[id].price = 0
  112.     end
  113.     @weapons.each do |id, value|
  114.       unless $game_temp.cant_sell_weapons
  115.         next unless $game_temp.nosell_weapons.include?(id)
  116.       end
  117.       $game_temp.stored_nosell_w[id] = $data_weapons[id].price
  118.       $data_weapons[id].price = 0
  119.     end
  120.   end
  121.   #-----------------------------------------------------------------------------
  122.   # * Reset Unsellables
  123.   #-----------------------------------------------------------------------------
  124.   def reset_unsellables(reset_temp = false, to_nil = false)
  125.     $game_temp.reset_unsellables if reset_temp
  126.     $game_temp.stored_nosell_i.each {|id, value| $data_items[id].price   = value}
  127.     $game_temp.stored_nosell_a.each {|id, value| $data_armors[id].price  = value}
  128.     $game_temp.stored_nosell_w.each {|id, value| $data_weapons[id].price = value}
  129.     $game_temp.reset_unsellable_inventory(to_nil)
  130.   end
  131. end
  132.  
  133. #===============================================================================
  134. # ** Interpreter
  135. #===============================================================================
  136.  
  137. class Interpreter
  138.   #-----------------------------------------------------------------------------
  139.   # * Can't Sell Items
  140.   #-----------------------------------------------------------------------------
  141.   def cant_sell_items
  142.     $game_temp.cant_sell_items = true
  143.   end
  144.   #-----------------------------------------------------------------------------
  145.   # * Can't Sell Armors
  146.   #-----------------------------------------------------------------------------
  147.   def cant_sell_armors
  148.     $game_temp.cant_sell_armors = true
  149.   end
  150.   #-----------------------------------------------------------------------------
  151.   # * Can't Sell Weapons
  152.   #-----------------------------------------------------------------------------
  153.   def cant_sell_weapons
  154.     $game_temp.cant_sell_weapons = true
  155.   end
  156.   #-----------------------------------------------------------------------------
  157.   # * No Sell Items
  158.   #-----------------------------------------------------------------------------
  159.   def nsI(*item_ids)
  160.     item_ids.each do |id|
  161.       next if $game_temp.nosell_items.include?(id)
  162.       $game_temp.nosell_items << id
  163.     end
  164.   end
  165.   #-----------------------------------------------------------------------------
  166.   # * No Sell Armors
  167.   #-----------------------------------------------------------------------------
  168.   def nsA(*armor_ids)
  169.     armor_ids.each do |id|
  170.       next if $game_temp.nosell_armors.include?(id)
  171.       $game_temp.nosell_armors << id
  172.     end
  173.   end
  174.   #-----------------------------------------------------------------------------
  175.   # * No Sell Weapons
  176.   #-----------------------------------------------------------------------------
  177.   def nsW(*weapon_ids)
  178.     weapon_ids.each do |id|
  179.       next if $game_temp.nosell_weapons.include?(id)
  180.       $game_temp.nosell_weapons << id
  181.     end
  182.   end
  183. end
  184.  
  185. #===============================================================================
  186. # ** Scene_Shop
  187. #===============================================================================
  188.  
  189. class Scene_Shop
  190.   #-----------------------------------------------------------------------------
  191.   # * Alias Listings
  192.   #-----------------------------------------------------------------------------
  193.   alias_method :nosell_snshop_main, :main
  194.   alias_method :nosell_snshop_updc, :update_command
  195.   #-----------------------------------------------------------------------------
  196.   # * Main
  197.   #-----------------------------------------------------------------------------
  198.   def main
  199.     $game_party.store_unsellables
  200.     nosell_snshop_main
  201.     $game_party.reset_unsellables(true, true)
  202.   end
  203. =begin
  204.  
  205.   # Use this version if you're using SDK, and your command order differs from
  206.   # the standard "Buy", "Sell", "Exit" command order, instead of the other
  207.   # update_command method. Otherwise the other method works for both SDK and non
  208.  
  209.   #-----------------------------------------------------------------------------
  210.   # * Update Command
  211.   #-----------------------------------------------------------------------------
  212.   def update_command
  213.     case @command_window.command
  214.     when SDK::Scene_Commands::Scene_Shop::Buy
  215.       unless $game_party.show_unsellables
  216.         $game_party.show_unsellables = true
  217.         @buy_window.refresh
  218.       end
  219.     when SDK::Scene_Commands::Scene_Shop::Sell
  220.       if $game_party.show_unsellables
  221.         $game_party.show_unsellables = false
  222.         @sell_window.refresh
  223.       end
  224.     end
  225.     nosell_snshop_updc
  226.   end
  227.  
  228. =end
  229.   #-----------------------------------------------------------------------------
  230.   # * Update Command
  231.   #-----------------------------------------------------------------------------
  232.   def update_command
  233.     case @command_window.index
  234.     when 0
  235.       unless $game_party.show_unsellables
  236.         $game_party.show_unsellables = true
  237.         @buy_window.refresh
  238.       end
  239.     when 1
  240.       if $game_party.show_unsellables
  241.         $game_party.show_unsellables = false
  242.         @sell_window.refresh
  243.       end
  244.     end
  245.     nosell_snshop_updc
  246.   end
  247. end
Expand to see the code.


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

Temporary Unsellable Goods... Spoiler
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...

  1. # nsI : Stands for "No Sell Items"
  2. nsI(1, 2, 3, 4, 5)
  3. # nsA : Stands for "No Sell Armors"
  4. nsA(1, 2, 3, 4, 5)
  5. # nsW : Stands for "No Sell Weapons"
  6. nsW(1, 2, 3, 4, 5)
Expand to see the code.


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

  1. $game_temp.nosell_items += [1, 2, 3, 4, 5]
  2. $game_temp.nosell_armors += [1, 2, 3, 4, 5]
  3. $game_temp.nosell_weapons += [1, 2, 3, 4, 5]
Expand to see the code.

Set it so all goods of this type are unsellable... Spoiler
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!

How does it work, exactly? Spoiler
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

Miscellaneous Notes Spoiler
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.

This system aliases the following methods... Spoiler
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!
Thank you so much I love you officially now!
:toot: :toot: :cheers: :cheers:
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 😉
Thank you very much, Kain, it's now working very well!

You rule =)
Thank you for the nice comment mining gast!

Goody Two-Shoes wrote:
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?
Ty kain, just what I needed!!!!
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!

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