Improved Shop v2

This script add a lost feature from old rpgmakers: the option to select if you
wanted to buy, sell or both.

Also adds the option of modifing the price based in %. Buy and sell discount are
separated, so you can make any combination.

In 2.0, you can define any currency to use for shop(exp, gold, variable...) and
add items that if you cant add to your inventory and that modifiy a switch,
variable or call a common event.

Using this feature you can create easily any set of shops that tells skills or sells
specialized things, or whatever you need, with autocalled common events and
custom currencys, and some extra features.

-------FULL FEATURES-------------

Classic feature: the option to select if you wanted to buy, sell or both.
Prices modifications for selling and buying

Shops interfaces: You can make any number of different shops interface and
a default one, and then changue all values for they:
-Gold type by total exp, gold or variable.
-Gold name.
-Customizte the used commands buy, sell, exit and his names.
-Option to not show numbers or select item number
-Option to exit when a buy is done
-Windowskin
-Title/Introduction

Special things: These items are special exceptions, where you can define
some unique behaviors:
-Actor & class buy restrictions
-Active switch, modifiy variable or call common evenet when buyed
-Switch that define if can buy or not a thing and other for things that when
adquired cant be used more.

Capture:
Image

Demo(example and divided):
http://www.megaupload.com/?d=DW5CMJ16

Script code(all in one):

  1. =begin
  2. #==============================================================================
  3. # Improved Shop
  4. # By gerkrt/gerrtunk
  5. # Version: 2.0
  6. # License: GPL, credits
  7. #==============================================================================
  8.  
  9. This script add a lost feature from old rpgmakers: the option to select if you
  10. wanted to buy, sell or both.
  11.  
  12. Also adds the option of modifing the price based in %. Buy and sell discount are
  13. separated, so you can make any combination.
  14.  
  15. In 2.0, you can define any currency to use for shop(exp, gold, variable...) and
  16. add items that if you cant add to your inventory and that modifiy a switch,
  17. variable or call a common event.
  18.  
  19. Using this feature you can create easily any set of shops that tells skills or sells
  20. specialized things, or whatever you need, with autocalled common events and
  21. custom currencys, and some extra features.
  22.  
  23. -------FULL FEATURES-------------
  24.  
  25. Classic feature: the option to select if you wanted to buy, sell or both.
  26. Prices modifications for selling and buying
  27.  
  28. Shops interfaces: You can make any number of different shops interface and
  29. a default one, and then changue all values for they:
  30.   -Gold type by total exp, gold or variable.
  31.   -Gold name.
  32.   -Customizte the used commands buy, sell, exit and his names.
  33.   -Option to not show numbers or select item number
  34.   -Option to exit when a buy is done
  35.   -Windowskin
  36.   -Title/Introduction
  37.  
  38. Special things: These items are special exceptions, where you can define
  39. some unique behaviors:
  40.   -Actor & class buy restrictions
  41.   -Active switch, modifiy variable or call common evenet when buyed
  42.   -Switch that define if can buy or not a thing and other for things that when
  43.     adquired cant be used more.
  44.  
  45. --------DISCOUNTS, TYPE AND GOLD TYPE---------
  46.  
  47. Before calling a shop, call this script:
  48.  
  49. $game_temp.type = 1
  50. $game_temp.buy_discount = 1.2
  51. $game_temp.sell_discount = 0.8
  52. $game_temp.gold_type = :gold
  53.  
  54. These is a call example.
  55. $game_temp.type : When 2 player can only sell.  When 1 player can only buy. When 0
  56. can do both. Note that this ONLY works with default interface or the interfaces
  57. that have the 3 commands.
  58. $game_temp.buy_discount : When you buy items the price is multiplied with this number.
  59. $game_temp.sell_discount : When you sell items the price is multiplied with this number.
  60.  
  61. Note that 0.2 , the . is like a ,.
  62.  
  63. After the sop call, these values are restored to default ones. This means that
  64. you can call a shop wiyhout adding the script call and that it will use:
  65.  
  66. Type = Buy & Sell
  67. Buy & Sell discounts = 1
  68.  
  69. As a final option, you can put the discount or type using the values of
  70. a event variable calling this script:
  71.  
  72. v = $game_variables[1]
  73. $game_temp.sell_discount = v
  74.  
  75. or whatever type, buy, etc. This way its settled the value of the var 1 to that
  76.  
  77. --------CUSTOM SHOPS---------
  78. The main idea of these options is that you can create or configurate the normal
  79. shop to do some special things, for example:
  80.  
  81. -A travel shop that when you exit, you travel automatically. You have the code
  82. in the configuration already. Just call a shop with items 5,6,7,8 and changuing
  83. the interface to :travel
  84.  
  85.  
  86. -----INTERFACES------
  87. A shop interface defines some basic things used in some shop. For example, the
  88. currency type used, the vocabulary of the commands, etc. In this way, you can use
  89. a different interface for each thing.
  90.  
  91. To add a interface paste the code each time:
  92.     :travel => {
  93.       :gold_type => [:var, 6],
  94.       :gold_word => 'Potatos',
  95.       :commands_used => [[:buy, 'Travel'], [:exit, 'Exit']],
  96.       :dont_show_number => true,
  97.       :exit_when_buy => false,    
  98.       :windowskin => 'greenieskin',
  99.       :title => 'Travel merchant: Where you want to go?'
  100.     },
  101.  
  102. Where the :travel is a unique code used each time, and just respect the sintax
  103. with the , {}, etc.
  104.  
  105. gold type: The currency used. Can be :gold, normal gold, :exp, will sum all party
  106. actors exp and use it as his gold, and :var. var means that the gold value is
  107. setted using a event variable you control, so, you can create any custom gold.
  108.  
  109. Note that for variables the syntax is different: [:var, 6], where 6 is the variable
  110. id.
  111.  
  112. gold word: The word used in the money window of the shop.
  113.  
  114. commands used: Using this you can customitze a shop to be what you want. What you
  115. do here is define the commands of the shop and the name thats drawn in the game.
  116. The posibles commands codes to configure are :buy, :sell, :exit.  
  117. Then what you have to do is to add any of the three to the list, thats limited
  118. in the []:
  119.   [[:code, 'name'], [:code2, 'name2'], [:code3, 'name3'], ]
  120.  
  121.  
  122. dont_show_number: Use this if you dont want to show or select the item number and
  123. it will buy automatically 1. It cant be used when selling.
  124.  
  125. :exit_when_buy: This make than when you buy the first item, the shop automatically
  126. closes, so, you can only buy or active a single thing.
  127.  
  128. windowskin : special windowskin used for all the windows
  129.  
  130. title  : text used for the description or introduction of a shop
  131.  
  132. To call a interface just use this call script:
  133. $game_temp.shop_interface = :travel
  134. Where travel is the interface name you write, that have to be new each time.
  135. After the shop call, interface selection is reseted to default.
  136.  
  137. Note that exist a default interface. This is called always when no explicit interface
  138. has been declared.
  139.  
  140. Finally you can desactive any option making they => false
  141.  
  142. -----SPECIAL THINGS----
  143. Special things are items that are a exception from normal ones, that will work like
  144. always. You have to use special things in order to create for example a skill learn
  145. shop where each of his items call a common event and that event have a 'learn X skill'
  146. in it.
  147.  
  148. Note althought that exist A LOT of options that you can use to create your custom.  
  149.  
  150. Finally, you can use special things only with buy options.
  151.  
  152. shops:
  153.     # South Amband
  154.     5 => {
  155.       # variable di, valor
  156.       :variable => [2,10],
  157.       :switch => 1,
  158.       :switch_can_buy => 5,
  159.       :common_event => 1,
  160.       :switch_adquired => nil,
  161.       :can_be_adquired_by_class => false,
  162.       :can_be_adquired_by_actor => [1],
  163.       },
  164.      
  165. variable: this makes that when you buy that item, the variable X its added the Z
  166. value, where: [X,Z],
  167.  
  168. switch: active switch of id 1 when buyed
  169.  
  170. switch_can_buy: the switch that have to be active to can buy the item
  171.  
  172. common_event: common event id called when buy. Using this you can call a script
  173. call in it or whatever you want!
  174.  
  175. switch_adquired: when this switch is active, the thing cant be buyed more. Use it
  176. for things that you want to buy only 1 time.
  177.  
  178. can_be_adquired_by_class: List of classes that can buy this item. Note that
  179. it will search for a all the party actors. [id1, id2, id3]
  180.  
  181. can_be_adquired_by_actor: List of actors that can buy this item. Note that
  182. it will search for a all the party actors. [id1, id2, id3]
  183.  
  184. Desactivating that options: Put they to  => false. Then they wont do a thing.
  185.  
  186. The syntax to add more things is:
  187.  
  188.     # New comment
  189.     23 => {
  190.       # variable di, valor
  191.       :variable => [2,10],
  192.       :switch => 1,
  193.       :switch_can_buy => 5,
  194.       :common_event => 1,
  195.  
  196.       :switch_adquired => nil,
  197.       :can_be_adquired_by_class => false,
  198.       :can_be_adquired_by_actor => [1],
  199.       },
  200.  
  201. Where the 23 is the item id you want to use as a special thing, and the
  202. # New comment the textthat you can modify to organitze the configuration(just dont
  203. erase the #!).
  204.  
  205. Each time copy paste this, using a , as a separator and mantaining the starting
  206. and final {] of the general and each thing config.
  207.  
  208.  
  209. =end
  210.  
  211.  
  212.  
  213. module Wep
  214.  
  215.   # Custom interfaces
  216.   Shop_interfaces = {
  217.     :travel => {
  218.       :gold_type => [:var, 6],
  219.       :gold_word => 'Potatos',
  220.       :commands_used => [[:buy, 'Travel'], [:exit, 'Exit']],
  221.       :dont_show_number => true,
  222.       :exit_when_buy => true,
  223.       :windowskin => false,
  224.       :title => 'Travel merchant: Where you want to go?'
  225.     },
  226.    
  227.      # Its called when no interface specified. Traditional one.
  228.     :default => {
  229.       :gold_type => :gold,
  230.       :gold_word => 'Gold',
  231.       :commands_used => [[:buy, 'Buy'], [:sell, 'Sell'], [:exit, 'Exit']],
  232.       :dont_show_number => false,
  233.       :exit_when_buy => false,
  234.       :windowskin => false,
  235.       :title => false
  236.    
  237.    }
  238.    
  239.   }
  240.  
  241.   # Things to use
  242.   Things = {
  243.  
  244.     # South Amband
  245.     5 => {
  246.  
  247.       :variable => [2,10],
  248.       :switch => 1,
  249.       :switch_can_buy => 5,
  250.       :common_event => 1,
  251.       :switch_adquired => false,
  252.       :can_be_adquired_by_class => false,
  253.       :can_be_adquired_by_actor => [1],
  254.       },
  255.      
  256.     # Fantastica  
  257.     6 => {
  258.       :variable => [2,10],
  259.       :switch => 1,
  260.       :switch_can_buy => 5,
  261.       :common_event => 1,
  262.       :switch_adquired => false,
  263.       :can_be_adquired_by_class => [1],
  264.       :can_be_adquired_by_actor => [1],
  265.       },
  266.      
  267.     # Ridinia
  268.     7 => {
  269.       :variable => [2,10],
  270.       :switch => 1,
  271.       :switch_can_buy => 5,
  272.       :common_event => 1,
  273.       :switch_adquired => false,
  274.       :can_be_adquired_by_class => [1],
  275.       :can_be_adquired_by_actor => [1],
  276.       },
  277.      
  278.     # Wepcondia
  279.     8 => {
  280.       :variable => [2,10],
  281.       :switch => 1,
  282.       :switch_can_buy => 5,
  283.       :common_event => 1,
  284.       :switch_adquired => false,
  285.       :can_be_adquired_by_class => [1],
  286.       :can_be_adquired_by_actor => [1],
  287.       },
  288.     }
  289.    
  290. end
  291.  
  292.  
  293. #==============================================================================
  294. # ** Window_ShopBuy
  295. #------------------------------------------------------------------------------
  296. #  This window displays buyable goods on the shop screen.
  297. #==============================================================================
  298.  
  299. class Window_ShopBuy < Window_Selectable
  300.  
  301.   #--------------------------------------------------------------------------
  302.   # * Refresh
  303.   #--------------------------------------------------------------------------
  304.   def refresh
  305.     if self.contents != nil
  306.       self.contents.dispose
  307.       self.contents = nil
  308.     end
  309.     @data = []
  310.     for goods_item in @shop_goods
  311.       case goods_item[0]
  312.       when 0
  313.         item = $data_items[goods_item[1]]
  314.       when 1
  315.         item = $data_weapons[goods_item[1]]
  316.       when 2
  317.         item = $data_armors[goods_item[1]]
  318.       end
  319.      
  320.       if item != nil
  321.         # Only push the ones that arent adquired and if item
  322.         if item.is_a? RPG::Item and Wep::Things[item.id] != nil and
  323.           Wep::Things[item.id][:switch_adquired] != false and
  324.             $game_switches[Wep::Things[item.id][:switch_adquired]]
  325.        
  326.         # Or if the switch to buy isnt active
  327.         elsif item.is_a? RPG::Item and Wep::Things[item.id] != nil and
  328.           Wep::Things[item.id][:switch_can_buy] != false and not
  329.             $game_switches[Wep::Things[item.id][:switch_can_buy]]
  330.        
  331.         else
  332.           @data.push(item)
  333.         end
  334.       end
  335.     end
  336.    
  337.     # If item count is not 0, make a bit map and draw all items
  338.     @item_max = @data.size
  339.     if @item_max > 0
  340.       self.contents = Bitmap.new(width - 32, row_max * 32)
  341.       for i in 0...@item_max
  342.         draw_item(i)
  343.       end
  344.     end
  345.   end
  346.  
  347.   #--------------------------------------------------------------------------
  348.   # * Draw Item
  349.   #     index : item number
  350.   #--------------------------------------------------------------------------
  351.   def draw_item(index)
  352.     item = @data[index]
  353.     # Get items in possession
  354.     case item
  355.     when RPG::Item
  356.       number = $game_party.item_number(item.id)
  357.     when RPG::Weapon
  358.       number = $game_party.weapon_number(item.id)
  359.     when RPG::Armor
  360.       number = $game_party.armor_number(item.id)
  361.     end
  362.     # If price is less than money in possession, and amount in possession is
  363.     # not 99, then set to normal text color. Otherwise set to disabled color
  364.     if item.price * $game_temp.buy_discount  <= $game_party.shop_gold and number < 99
  365.       self.contents.font.color = normal_color
  366.     else
  367.       self.contents.font.color = disabled_color
  368.     end
  369.    
  370.    
  371.     rebajado = item.price * $game_temp.buy_discount
  372.     rebajado = rebajado.to_i
  373.    
  374.  
  375.     x = 4
  376.     y = index * 32
  377.     rect = Rect.new(x, y, self.width - 32, 32)
  378.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  379.     bitmap = RPG::Cache.icon(item.icon_name)
  380.     opacity = self.contents.font.color == normal_color ? 255 : 128
  381.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  382.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  383.    
  384.  
  385.     # When dont show numbers, number more to the right
  386.     if $game_temp.act_shop_interface[:dont_show_number]
  387.       self.contents.draw_text(x + 480, y, 88, 32, rebajado.to_s, 2)
  388.     else
  389.       self.contents.draw_text(x + 240, y, 88, 32, rebajado.to_s, 2)
  390.     end
  391.    
  392.   end
  393. end
  394.  
  395.  
  396.  
  397. #==============================================================================
  398. # ** Window_ShopCommand
  399. #------------------------------------------------------------------------------
  400. #  This window is used to choose your business on the shop screen.
  401. #==============================================================================
  402.  
  403. class Window_ShopCommand < Window_Selectable
  404.   #--------------------------------------------------------------------------
  405.   # * Object Initialization
  406.   #--------------------------------------------------------------------------
  407.   def initialize
  408.     super(0, 64, 480, 64)
  409.     self.contents = Bitmap.new(width - 32, height - 32)
  410.    
  411.     @column_max = 3
  412.     #Excepciones de tipo
  413.     cums = Wep::Shop_interfaces[$game_temp.shop_interface][:commands_used]
  414.  
  415.     # Make custom commmands
  416.     @commands = []
  417.     for cu in cums
  418.       @commands.push cu[1]
  419.     end
  420.    
  421.     @item_max = @commands.size
  422.    
  423.     refresh
  424.     self.index = 0
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # * Refresh
  428.   #--------------------------------------------------------------------------
  429.   def refresh
  430.     self.contents.clear
  431.     for i in 0...@item_max
  432.       draw_item(i)
  433.     end
  434.   end
  435.   #--------------------------------------------------------------------------
  436.   # * Draw Item
  437.   #     index : item number
  438.   #--------------------------------------------------------------------------
  439.   def draw_item(index)
  440.     x = 4 + index * 160
  441.       #Excepciones de tipo
  442.     case $game_temp.type
  443.       when 1
  444.         #Canvio de color de fuente y retorno de la misma
  445.         if index == 1
  446.           self.contents.font.color = disabled_color
  447.         end
  448.        
  449.         if index == 2
  450.           self.contents.font.color = normal_color
  451.         end
  452.          
  453.        
  454.       when 2
  455.         #Canvio de color de fuente y retorno de la misma
  456.         if index == 0
  457.           self.contents.font.color = disabled_color
  458.         end
  459.         if index == 1...2
  460.           self.contents.font.color = normal_color
  461.         end
  462.     end
  463.    #p @commands, index
  464.     self.contents.draw_text(x, 0, 128, 32, @commands[index])
  465.   end
  466. end
  467.  
  468.  
  469.  
  470. class Scene_Shop
  471.  
  472.   #--------------------------------------------------------------------------
  473.   # * Main Processing
  474.   #--------------------------------------------------------------------------
  475.   def main
  476.     # Make help window
  477.     @help_window = Window_Help.new
  478.     # Make command window
  479.     @command_window = Window_ShopCommand.new
  480.     # Make gold window
  481.     @gold_window = Window_GoldShop.new
  482.     @gold_window.x = 480
  483.     @gold_window.y = 64
  484.     # Make dummy window
  485.     @dummy_window = Window_Base.new(0, 128, 640, 352)
  486.     # Make buy window
  487.     @buy_window = Window_ShopBuy.new($game_temp.shop_goods)
  488.     @buy_window.active = false
  489.     @buy_window.visible = false
  490.     @buy_window.help_window = @help_window
  491.     # Make sell window
  492.     @sell_window = Window_ShopSell.new
  493.     @sell_window.active = false
  494.     @sell_window.visible = false
  495.     @sell_window.help_window = @help_window
  496.     # Make quantity input window
  497.     @number_window = Window_ShopNumber.new
  498.     @number_window.active = false
  499.     @number_window.visible = false
  500.     # Make status window
  501.     @status_window = Window_ShopStatus.new
  502.     @status_window.visible = false
  503.     # If dont show number
  504.     if Wep::Shop_interfaces[$game_temp.shop_interface][:dont_show_number]
  505.       @number_window.visible = false
  506.       @status_window.visible = false
  507.       @buy_window.width = 640
  508.       @buy_window.z = @status_window.z + 80
  509.     end
  510.    
  511.     # Windoskin
  512.     if Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin]
  513.       @sell_window.windowskin = RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  514.       @number_window.windowskin = RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  515.       @status_window.windowskin = RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  516.       @buy_window.windowskin = RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  517.       @help_window.windowskin =  RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  518.       @gold_window.windowskin =  RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  519.       @command_window.windowskin =  RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  520.       @dummy_window .windowskin =  RPG::Cache.windowskin( Wep::Shop_interfaces[$game_temp.shop_interface][:windowskin])
  521.     end
  522.    
  523.     # Execute transition
  524.     Graphics.transition
  525.     # Main loop
  526.     loop do
  527.       # Update game screen
  528.       Graphics.update
  529.       # Update input information
  530.       Input.update
  531.       # Frame update
  532.       update
  533.       # Abort loop if screen is changed
  534.       if $scene != self
  535.         break
  536.       end
  537.     end
  538.     # Prepare for transition
  539.     Graphics.freeze
  540.     # Dispose of windows
  541.     @help_window.dispose
  542.     @command_window.dispose
  543.     @gold_window.dispose
  544.     @dummy_window.dispose
  545.     @buy_window.dispose
  546.     @sell_window.dispose
  547.     @number_window.dispose
  548.     @status_window.dispose
  549.   end
  550.  
  551.   #--------------------------------------------------------------------------
  552.   # * Frame Update (when command window is active)
  553.   #--------------------------------------------------------------------------
  554.   def update_command
  555.     # Set title
  556.     if Wep::Shop_interfaces[$game_temp.shop_interface][:title]
  557.       @help_window.set_text (Wep::Shop_interfaces[$game_temp.shop_interface][:title])
  558.     end
  559.     # If B button was pressed
  560.     if Input.trigger?(Input::B)
  561.       # Play cancel SE
  562.       $game_system.se_play($data_system.cancel_se)
  563.         # Reset shop variables
  564.         $game_temp.type = 0
  565.         $game_temp.buy_discount = 1
  566.         $game_temp.sell_discount = 1
  567.         $game_temp.shop_interface = :default
  568.       # Switch to map screen
  569.       $scene = Scene_Map.new
  570.       return
  571.     end
  572.     # If C button was pressed
  573.     if Input.trigger?(Input::C)
  574.       # Trasnlate command index as command code used
  575.       case $game_temp.act_shop_interface[:commands_used][@command_window.index][0]
  576.      
  577.         when :buy
  578.           command_buy
  579.         when :sell
  580.           command_sell
  581.         when :exit
  582.           command_exit
  583.        
  584.       return
  585.      end
  586.     end
  587.   end
  588.  
  589.   #--------------------------------------------------------------------------
  590.   # * Command buy: execute command buy
  591.   #--------------------------------------------------------------------------
  592.   def command_buy
  593.         if $game_temp.type== 0 or $game_temp.type== 1
  594.           # Play decision SE
  595.           $game_system.se_play($data_system.decision_se)
  596.           # Change windows to buy mode
  597.           @command_window.active = false
  598.           @dummy_window.visible = false
  599.           @buy_window.active = true
  600.           @buy_window.visible = true
  601.           @buy_window.refresh
  602.           @status_window.visible = true
  603.         else
  604.           $game_system.se_play($data_system.cancel_se)
  605.           return
  606.         end  
  607.   end
  608.      
  609.   #--------------------------------------------------------------------------
  610.   # * Command sell: execute command sell
  611.   #--------------------------------------------------------------------------  
  612.   def command_sell
  613.       if $game_temp.type== 0 or $game_temp.type== 2
  614.         # Play decision SE
  615.         $game_system.se_play($data_system.decision_se)
  616.         # Change windows to sell mode
  617.         @command_window.active = false
  618.         @dummy_window.visible = false
  619.         @sell_window.active = true
  620.         @sell_window.visible = true
  621.         @sell_window.refresh
  622.       else
  623.         $game_system.se_play($data_system.cancel_se)
  624.         return
  625.       end
  626.   end
  627.  
  628.   #--------------------------------------------------------------------------
  629.   # * Command exit: execute command exit
  630.   #--------------------------------------------------------------------------
  631.   def command_exit
  632.         # Play decision SE
  633.         $game_system.se_play($data_system.decision_se)
  634.         # Reset shop variables
  635.         $game_temp.type = 0
  636.         $game_temp.buy_discount = 1
  637.         $game_temp.sell_discount = 1
  638.         $game_temp.shop_interface = :default
  639.         # Switch to map screen
  640.         $scene = Scene_Map.new
  641.   end
  642.      
  643.   #--------------------------------------------------------------------------
  644.   # * Check item class restriction
  645.   #--------------------------------------------------------------------------  
  646.   def item_class_restriction
  647.       # If its special one and cant be purchased by actors or classes
  648.       if Wep::Things[@item.id] != nil
  649.          class_valid = true
  650.  
  651.          if Wep::Things[@item.id][:can_be_adquired_by_class]
  652.            for adq_class in Wep::Things[@item.id][:can_be_adquired_by_class]
  653.              class_valid = false unless $game_party.include_class?(adq_class)
  654.            end
  655.          end
  656.          
  657.          unless class_valid
  658.            # Play buzzer SE
  659.            $game_system.se_play($data_system.buzzer_se)
  660.            return false
  661.          end
  662.          
  663.        end
  664.        return true
  665.   end
  666.  
  667.   #--------------------------------------------------------------------------
  668.   # * Check item actor restriction
  669.   #--------------------------------------------------------------------------    
  670.   def item_actor_restriction
  671.       # If its special one and cant be purchased by actors or classes
  672.       if Wep::Things[@item.id] != nil
  673.          actor_valid = true
  674.          if Wep::Things[@item.id][:can_be_adquired_by_actor]
  675.            for adq_actor in Wep::Things[@item.id][:can_be_adquired_by_actor]
  676.              actor_valid = false unless $game_party.include_actor?(adq_actor)
  677.            end
  678.          end
  679.        
  680.          unless actor_valid
  681.            # Play buzzer SE
  682.            $game_system.se_play($data_system.buzzer_se)
  683.            return false
  684.          end
  685.          
  686.        
  687.       end
  688.        return true
  689.   end
  690.  
  691.   #--------------------------------------------------------------------------
  692.   # * Frame Update (when buy window is active)
  693.   #--------------------------------------------------------------------------
  694.   def update_buy
  695.     # Set status window item
  696.     @status_window.item = @buy_window.item
  697.     # If B button was pressed
  698.     if Input.trigger?(Input::B)
  699.       # Play cancel SE
  700.       $game_system.se_play($data_system.cancel_se)
  701.       # Change windows to initial mode
  702.       @command_window.active = true
  703.       @dummy_window.visible = true
  704.       @buy_window.active = false
  705.       @buy_window.visible = false
  706.       @status_window.visible = false
  707.       @status_window.item = nil
  708.       # Erase help text
  709.       @help_window.set_text("")
  710.       return
  711.     end
  712.     # If C button was pressed
  713.     if Input.trigger?(Input::C)
  714.       # Get item
  715.       @item = @buy_window.item
  716.       # If item is invalid, or price is higher than money possessed
  717.       if @item == nil or @item.price > $game_party.shop_gold
  718.         # Play buzzer SE
  719.         $game_system.se_play($data_system.buzzer_se)
  720.         return
  721.       end
  722.      
  723.       # If dont show number, automatically gain 1 item and skip number
  724.       if Wep::Shop_interfaces[$game_temp.shop_interface][:dont_show_number]
  725.  
  726.         # Buy process only if normal
  727.           unless Wep::Things[@item.id] != nil
  728.             modificado = @item.price * $game_temp.buy_discount
  729.             $game_party.shop_lose_gold(modificado.to_i)
  730.             case @item
  731.               when RPG::Item
  732.                 $game_party.gain_item(@item.id, 1)
  733.               when RPG::Weapon
  734.                 $game_party.gain_weapon(@item.id, 1)
  735.               when RPG::Armor
  736.                 $game_party.gain_armor(@item.id, 1)
  737.               end
  738.              
  739.           # Special items
  740.           else
  741.  
  742.  
  743.             # Check items restrictions
  744.             return unless item_actor_restriction
  745.             return unless item_class_restriction
  746.              
  747.             modificado = @item.price * $game_temp.buy_discount
  748.             $game_party.shop_lose_gold(modificado.to_i)
  749.            
  750.             # Modifiy var
  751.             if Wep::Things[@item.id][:variable]
  752.               $game_variables[Wep::Things[@item.id][:variable][0]] += Wep::Things[@item.id][:variable][1]
  753.             end
  754.             # Mod sw
  755.             if Wep::Things[@item.id][:switch]
  756.               $game_switches[Wep::Things[@item.id][:switch]] = true
  757.             end
  758.             # Call comm ev
  759.             if Wep::Things[@item.id][:common_event]
  760.               $game_temp.common_event_id = Wep::Things[@item.id][:common_event]
  761.             end
  762.           end
  763.          
  764.           # Refresh each window
  765.           @gold_window.refresh
  766.           @buy_window.refresh
  767.           @status_window.refresh
  768.           # End execution and play se
  769.           # Play decision SE
  770.           $game_system.se_play($data_system.decision_se)
  771.          
  772.           # Or exit if configurated
  773.           if Wep::Shop_interfaces[$game_temp.shop_interface][:exit_when_buy]
  774.             $scene = Scene_Map.new
  775.           end
  776.           return
  777.       end
  778.      
  779.  
  780.       # Get items in possession count
  781.       case @item
  782.       when RPG::Item
  783.         number = $game_party.item_number(@item.id)
  784.       when RPG::Weapon
  785.         number = $game_party.weapon_number(@item.id)
  786.       when RPG::Armor
  787.         number = $game_party.armor_number(@item.id)
  788.       end
  789.       # If 99 items are already in possession
  790.       if number == 99
  791.         # Play buzzer SE
  792.         $game_system.se_play($data_system.buzzer_se)
  793.         return
  794.       end
  795.      
  796.       # Play decision SE
  797.       $game_system.se_play($data_system.decision_se)
  798.       # Calculate maximum amount possible to buy
  799.       rebaja = @item.price*$game_temp.buy_discount
  800.       max = @item.price == 0 ? 99 : $game_party.shop_gold / rebaja.to_i
  801.       max = [max, 99 - number].min
  802.       # Change windows to quantity input mode
  803.       @buy_window.active = false
  804.       @buy_window.visible = false
  805.       descuento = @item.price * $game_temp.buy_discount
  806.       @number_window.set(@item, max, descuento.to_i)
  807.       @number_window.active = true
  808.       @number_window.visible = true
  809.     end
  810.   end
  811.  
  812.   #--------------------------------------------------------------------------
  813.   # * Frame Update (when sell window is active)
  814.   #--------------------------------------------------------------------------
  815.   def update_sell
  816.     # If B button was pressed
  817.     if Input.trigger?(Input::B)
  818.       # Play cancel SE
  819.       $game_system.se_play($data_system.cancel_se)
  820.       # Change windows to initial mode
  821.       @command_window.active = true
  822.       @dummy_window.visible = true
  823.       @sell_window.active = false
  824.       @sell_window.visible = false
  825.       @status_window.item = nil
  826.       # Erase help text
  827.       @help_window.set_text("")
  828.       return
  829.     end
  830.     # If C button was pressed
  831.     if Input.trigger?(Input::C)
  832.       # Get item
  833.       @item = @sell_window.item
  834.       # Set status window item
  835.       @status_window.item = @item
  836.       # If item is invalid, or item price is 0 (unable to sell)
  837.       if @item == nil or @item.price == 0
  838.         # Play buzzer SE
  839.         $game_system.se_play($data_system.buzzer_se)
  840.         return
  841.       end
  842.       # Play decision SE
  843.       $game_system.se_play($data_system.decision_se)
  844.       # Get items in possession count
  845.       case @item
  846.       when RPG::Item
  847.         number = $game_party.item_number(@item.id)
  848.       when RPG::Weapon
  849.         number = $game_party.weapon_number(@item.id)
  850.       when RPG::Armor
  851.         number = $game_party.armor_number(@item.id)
  852.       end
  853.       # Maximum quanitity to sell = number of items in possession
  854.       max = number
  855.       # Change windows to quantity input mode
  856.       @sell_window.active = false
  857.       @sell_window.visible = false
  858.       descuento = (@item.price * $game_temp.vend_desc) / 2
  859.       @number_window.set(@item, max, descuento.to_i)
  860.       @number_window.active = true
  861.       @number_window.visible = true
  862.       @status_window.visible = true
  863.     end
  864.   end
  865.  
  866.   #--------------------------------------------------------------------------
  867.   # * Frame Update (when quantity input window is active)
  868.   #--------------------------------------------------------------------------
  869.   def update_number
  870.     # If B button was pressed
  871.     if Input.trigger?(Input::B)
  872.       # Play cancel SE
  873.       $game_system.se_play($data_system.cancel_se)
  874.       # Set quantity input window to inactive / invisible
  875.       @number_window.active = false
  876.       @number_window.visible = false
  877.       # Branch by command window cursor position
  878.       case @command_window.index
  879.       when 0  # buy
  880.         # Change windows to buy mode
  881.         @buy_window.active = true
  882.         @buy_window.visible = true
  883.       when 1  # sell
  884.         # Change windows to sell mode
  885.         @sell_window.active = true
  886.         @sell_window.visible = true
  887.         @status_window.visible = false
  888.       end
  889.       return
  890.     end
  891.     # If C button was pressed
  892.     if Input.trigger?(Input::C)
  893.       # Play shop SE
  894.       $game_system.se_play($data_system.shop_se)
  895.       # Set quantity input window to inactive / invisible
  896.       @number_window.active = false
  897.       @number_window.visible = false
  898.       # Branch by command window cursor position
  899.       case @command_window.index
  900.       when 0  # buy
  901.        
  902.         # Buy process only if normal
  903.         unless Wep::Things[@item.id] != nil
  904.           modificado = @number_window.number * @item.price * $game_temp.buy_discount
  905.           $game_party.shop_lose_gold(modificado.to_i)
  906.           case @item
  907.             when RPG::Item
  908.               $game_party.gain_item(@item.id, @number_window.number)
  909.             when RPG::Weapon
  910.               $game_party.gain_weapon(@item.id, @number_window.number)
  911.             when RPG::Armor
  912.               $game_party.gain_armor(@item.id, @number_window.number)
  913.             end
  914.            
  915.         # Special items
  916.         else
  917.      
  918.           # Check items restrictions
  919.           return unless item_actor_restriction
  920.           return unless item_class_restriction
  921.            
  922.           modificado = @number_window.number * @item.price * $game_temp.buy_discount
  923.           $game_party.shop_lose_gold(modificado.to_i)
  924.          
  925.           # Modifiy var
  926.           if Wep::Things[@item.id][:variable]
  927.             $game_variables[Wep::Things[@item.id][:variable][0]] += Wep::Things[@item.id][:variable][1]
  928.           end
  929.           # Mod sw
  930.           if Wep::Things[@item.id][:switch]
  931.             $game_switches[Wep::Things[@item.id][:switch]] = true
  932.           end
  933.           # Call comm ev
  934.           if Wep::Things[@item.id][:common_event]
  935.             $game_temp.common_event_id = Wep::Things[@item.id][:common_event]
  936.           end
  937.         end
  938.        
  939.         # Refresh each window
  940.         @gold_window.refresh
  941.         @buy_window.refresh
  942.         @status_window.refresh
  943.         # Change windows to buy mode
  944.         @buy_window.active = true
  945.         @buy_window.visible = true
  946.        
  947.         # Or exit if configurated
  948.         if Wep::Shop_interfaces[$game_temp.shop_interface][:exit_when_buy]
  949.           $scene = Scene_Map.new
  950.         end
  951.       when 1  # sell
  952.         # Sell process
  953.         modificado = (@item.price * $game_temp.vend_desc) / 2
  954.         $game_party.shop_gain_gold(@number_window.number * modificado.to_i)
  955.         case @item
  956.         when RPG::Item
  957.           $game_party.lose_item(@item.id, @number_window.number)
  958.         when RPG::Weapon
  959.           $game_party.lose_weapon(@item.id, @number_window.number)
  960.         when RPG::Armor
  961.           $game_party.lose_armor(@item.id, @number_window.number)
  962.         end
  963.         # Refresh each window
  964.         @gold_window.refresh
  965.         @sell_window.refresh
  966.         @status_window.refresh
  967.         # Change windows to sell mode
  968.         @sell_window.active = true
  969.         @sell_window.visible = true
  970.         @status_window.visible = false
  971.       end
  972.       return
  973.     end
  974.   end
  975.  
  976. end
  977.  
  978.  
  979. class Game_Temp
  980.   attr_accessor :type                        # 2: Sell/1: Buy/0: Both
  981.   attr_accessor :buy_discount                # Buy discount +- %
  982.   attr_accessor :sell_discount               # Sell discount +- %
  983.   attr_accessor :shop_interface                  # Sell discount +- %  
  984.   alias gt_init initialize
  985.   def initialize
  986.       gt_init
  987.       @type = 0
  988.       @shop_interface = :default
  989.       @buy_discount = 1
  990.       @sell_discount = 1
  991.   end
  992.  
  993.   # Return shop interface
  994.   def act_shop_interface
  995.     Wep::Shop_interfaces[$game_temp.shop_interface]
  996.   end
  997. end
  998.  
  999. class Game_Actor
  1000.   attr_reader     :actor_id
  1001. end
  1002.  
  1003. class Game_Party
  1004.    
  1005.   #--------------------------------------------------------------------------
  1006.   # * Seeks if at least a actor in the party have the actor id
  1007.   #--------------------------------------------------------------------------
  1008.     def include_actor?(id)
  1009.       f=false
  1010.       for a in @actors
  1011.         f=true if a.actor_id == id
  1012.       end
  1013.       f
  1014.     end
  1015.    
  1016.   #--------------------------------------------------------------------------
  1017.   # * Seeks if at least a actor in the party have the class id
  1018.   #--------------------------------------------------------------------------  
  1019.     def include_class?(id)
  1020.       f=false
  1021.       for a in @actors
  1022.         f=true if a.class_id == id
  1023.       end
  1024.       f
  1025.     end
  1026.  
  1027.   #--------------------------------------------------------------------------
  1028.   # * Shop gold
  1029.   #     gold method used only in shop
  1030.   #--------------------------------------------------------------------------
  1031.   def shop_gold
  1032.     type = Wep::Shop_interfaces[$game_temp.shop_interface][:gold_type]
  1033.     # Normal gold
  1034.     if type == :gold
  1035.       return @gold
  1036.     # Experience
  1037.     elsif type == :exp
  1038.       v = 0
  1039.       @actors.each {|a| v += a.exp}
  1040.       return v
  1041.     # Event variable
  1042.     else
  1043.       return $game_variables[Wep::Shop_interfaces[$game_temp.shop_interface][:gold_type][1]]
  1044.     end
  1045.   end
  1046.  
  1047.   #--------------------------------------------------------------------------
  1048.   # * Shop Gain Gold (or lose)
  1049.   #     n : amount of gold
  1050.   #--------------------------------------------------------------------------
  1051.   def shop_gain_gold(n)
  1052.     type = Wep::Shop_interfaces[$game_temp.shop_interface][:gold_type]
  1053.     # Normal gold
  1054.     if type == :gold
  1055.       @gold = [[@gold + n, 0].max, 9999999].min
  1056.      
  1057.     # Experience
  1058.     elsif type == :exp
  1059.       # Divide actor number by n
  1060.       ratio = (n/@actors.size).to_i
  1061.       # Modify each exp
  1062.       @actors.each {|a| a.exp += ratio}
  1063.      
  1064.     # Event variable
  1065.     else
  1066.       vid = Wep::Shop_interfaces[$game_temp.shop_interface][:gold_type][1]
  1067.       $game_variables[vid] = [[$game_variables[vid] + n, 0].max, 9999999].min
  1068.     end
  1069.    
  1070.    
  1071.   end
  1072.  
  1073.   #--------------------------------------------------------------------------
  1074.   # * Shop Lose Gold
  1075.   #     n : amount of gold
  1076.   #--------------------------------------------------------------------------
  1077.   def shop_lose_gold(n)
  1078.     # Reverse the numerical value and call it gain_gold
  1079.     shop_gain_gold(-n)
  1080.   end
  1081.  
  1082. end
  1083.  
  1084.  
  1085.  
  1086. #==============================================================================
  1087. # ** Window_GoldShop
  1088. #------------------------------------------------------------------------------
  1089. #  This window displays amount of gold in shops
  1090. #==============================================================================
  1091.  
  1092. class Window_GoldShop < Window_Base
  1093.   #--------------------------------------------------------------------------
  1094.   # * Object Initialization
  1095.   #--------------------------------------------------------------------------
  1096.   def initialize
  1097.     super(0, 0, 160, 64)
  1098.     self.contents = Bitmap.new(width - 32, height - 32)
  1099.     refresh
  1100.   end
  1101.  
  1102.   #--------------------------------------------------------------------------
  1103.   # * Refresh
  1104.   #--------------------------------------------------------------------------
  1105.   def refresh
  1106.     self.contents.clear
  1107.       word = Wep::Shop_interfaces[$game_temp.shop_interface][:gold_word].to_s
  1108.       cx = contents.text_size(word).width
  1109.       self.contents.font.color = normal_color
  1110.       self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.shop_gold.to_s, 2)
  1111.      
  1112.       self.contents.font.color = system_color
  1113.       self.contents.draw_text(124-cx, 0, cx, 32, word, 2)
  1114.  
  1115.   end
  1116. end
  1117.  
  1118.  
  1119.  
  1120. module Wep
  1121.   Scripts_list = [] unless defined? Scripts_list
  1122.   Scripts_list.push ('Improved Shop')
  1123. end
Expand to see the code.


FAQ

I will listen for any crtic, suggerence, bug, feature, etc...
Hey that's pretty cool! And again another heavily requested thing... a few years ago.

The newbies don't know what they're missing :thumb:
There are a couple of scripts that deal with the price percentage, so it's not as new as it seems to be at first sight. The idea of just selling or buying stuff isn't new at all, I think someone else already thought about that but since many scripts are buried among a lot of other scripts, it's a bit difficult to find those I'm talking about. One could make a few slight changes in the default shop script to achieve the same purpose.

Now that he's gaining self confidence, he should pursue higher goals, these ones are still a little bit too basic IMHO.
kyonides wrote:
There are a couple of scripts that deal with the price percentage, so it's not as new as it seems to be at first sight. The idea of just selling or buying stuff isn't new at all, I think someone else already thought about that but since many scripts are buried among a lot of other scripts, it's a bit difficult to find those I'm talking about. One could make a few slight changes in the default shop script to achieve the same purpose.

Now that he's gaining self confidence, he should pursue higher goals, these ones are still a little bit too basic IMHO.


Sorry but i dont understand your attitude. First of all, read what i write:

Quote:
pd: I think this is the first script i created, you will see that didnt know about disabling commands...


Im posting this now because i have ordering all the code i created for a project like 2 years ago(write instructions and compile in one script)

Its normal that my first script was so easy. Also, who talked about nothing new? me? mouse? No, only you.

But its just that i dont understand why are you posting things like this in all my scripts threads. You are correcting all, what people say,etc. I like feedback but you arent posting ideas or something for this script. If you tell me that using \v[x] is better than $game_variables, ok, but i dont see the purpose of this style of comments.

And i already have higher goals. I have a hiper complex item menu and system with 3000 lines of code. Im 100% sure that a good scripter had done that in less time or code: well, that was my first hard thing to create.

Now im making one skill system(not that complex,but...), and two addons for the atoa battlesystem.

Ah yes, and have in final testing a complex save system. Anyway, im not going to do something that already exist, or for the sake of challengue, im just creating what i need for my games(the exception is the save script). Now my true last project with RGSS is a enemy IA system for my large project... the rest is small skill system and a few litlle scripts...

Then i will start withh other engines. I already done something in pygame and C, now im learning c# and i want to know xna..

pd: this isnt an argument, and i want to beat anbody. Its just you arent understanding me or something.
Quote:
im just creating what i need for my games(the exception is the save script).

That's exactly why I said what I said, it was kind of obvious to me and that's why I was suggesting here you could do more complex scripts if you want to and have the time to go for them. I don't care if you think my attitude is negative or positive as long as you got the right message at the end, to go for more complex scripts, it doesn't matter if you post them or not, that's up to you as it've always been the case.

Quote:
And i already have higher goals. I have a hiper complex item menu and system with 3000 lines of code

Remember that it's not the number of lines of code what makes it a well coded script but how efficiently it was coded. No, this isn't an evil comment, I'm just telling you that you'd not believe something is good enough for something just because it's a large script.

Oh, I almost forgot to tell you that some part of my previous post wasn't really addressed to you as you may have already noticed.
kyonides wrote:
Quote:
im just creating what i need for my games(the exception is the save script).

That's exactly why I said what I said, it was kind of obvious to me and that's why I was suggesting here you could do more complex scripts if you want to and have the time to go for them. I don't care if you think my attitude is negative or positive as long as you got the right message at the end, to go for more complex scripts, it doesn't matter if you post them or not, that's up to you as it've always been the case.

Quote:
And i already have higher goals. I have a hiper complex item menu and system with 3000 lines of code

Remember that it's not the number of lines of code what makes it a well coded script but how efficiently it was coded. No, this isn't an evil comment, I'm just telling you that you'd not believe something is good enough for something just because it's a large script.

Oh, I almost forgot to tell you that some part of my previous post wasn't really addressed to you as you may have already noticed.


I know that. Maybe a good practice exercicie will be in thinking how to improve the code of that system(but not actually coding it,just planning).

About complex things, wait for the save system. Anyway, i have reduced to 60% the aspirations for the first version and i thing it wont take too long.

pd: here is a description i wrote for the item system:


Image

The esthetics are temporal.

The reason to create it was my need of a limited item system based on weight with a bag for every actor. I created it with old DW experiencies in mind, where shopping/moving/using items was a painful experiencie that make you lose like 20m everytime.

Tool bar with this functions:
-Exchangue all the items betwen two actors.
-Send a bag to the temporal.
-Erase bag.
-Empty the temporal.
-Send all bags to the temporal.
-Two sort algorithms.
-Open selection window.

Math bar
-Selected item number
-Selected items total weight.
-A relationn betwin selection weight and the bag in wich the cursor is.

Wastepaper: Neutral icon. One of the ways of deleting items.

Item window: Face, actual weight/max. It shows the actor equipment, and you can changue it. Anyway you cant see the item description or effects, iys just for quick andknow changues.

Temporal window: This window dont have max weight and itsfunction is to be used for some functions and to give to the plyer some flexibility.
The items you erase are puted here, and before quiitting it will show a
warning checking for confirmation.

Selection window: It shows all the selected items merged. With this you can recolocate the tem number with a few seconds.

Move betwen windows: Two keys for that. Anyway exist a system that make that all the windows are treated like a one. This make that if you move to a window border the index willlbe traspased to the next with the more logic position posible.

Selection mode: With this you can select a group of items. There arent any restrictions, you can select from any actor. Then you can move or erase it all. When you select a item, you can also select it number.
Update to 2.0
I posted in your support thread, hopefully it'll be of some help to you. While I'm not active much anymore, I've been watching your progress, you've been making some good improvement in the short time I've seen you around. Anyways, cheers mate :cheers:

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