Advertisement
KK20

Custom Prices v1

Aug 23rd, 2016
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.32 KB | None | 0 0
  1. =begin
  2. ===============================================================================
  3. Custom Prices                                                     Version 1.0
  4. by KK20                                                           [11/25/2013]
  5. ===============================================================================
  6. _______________________________________________________________________________
  7. + Introduction
  8.  
  9.  RPG Maker only allows items to have one set of prices. The sell price of items
  10.  is half the price set in the database. With this script, you can modify the
  11.  prices of items, weapons, and armors to whatever you want. The change is only
  12.  temporary, so you can have shops sell certain items at unique prices. You can
  13.  also change the sell price to anything. Make an item cost a high amount, but
  14.  make it unavailable to sell. Have shops buy specific kinds of items. The
  15.  choice is up to you!
  16. _______________________________________________________________________________
  17. + Instructions
  18.  
  19.  Place this script below any custom scripts that rely on item prices.
  20.  
  21.  To change the prices of items, use one of these script calls:
  22.  
  23.         price(TYPE, ID, BUY_PRICE)
  24.         price(TYPE, ID, BUY_PRICE, SELL_PRICE)
  25.        
  26.   where TYPE can be 0 (Item), 1 (Weapon), or 2 (Armor)
  27.         ID refers to the item's ID in the database
  28.         BUY_PRICE is the new price of the item
  29.         SELL_PRICE is the new sell price of the item
  30.         SELL_PRICE is optional. If you do not put a sell price, items will
  31.           default to being half the BUY_PRICE.
  32.  
  33.   If you ever need to reset the price changes, use the script call:
  34.  
  35.         reset_prices
  36.  
  37.   This is only needed if using custom scripts that rely on item prices
  38.   but are not considered shops (e.g. ForeverZer0's Blacksmith Shop).
  39.        
  40.   -------------      
  41.   Examples:
  42.   -------------
  43.  
  44.   price(0, 1, 300)              # Potion prices: BUY = 300, SELL = 150
  45.   price(1, 1, 5000, 100)        # Bronze Sword prices: BUY = 5000, SELL = 100
  46.   price(2, 25, 9001, 0)         # Ring of Strength prices: BUY = 9001, SELL = Can't sell at this shop
  47. _______________________________________________________________________________  
  48. + Notes
  49.  
  50.  It is recommended to put these script calls just before the 'Shop Processing'
  51.  command. Immediately after the player exits the shop, the item prices WILL
  52.  revert back to their original database prices.
  53.  
  54.  This script may be compatible with some Custom Shop Systems. The more complex
  55.  the script, the less likely.
  56. _______________________________________________________________________________
  57. + Credits
  58.  
  59.  KK20 - for writing the script
  60.  firevenge007 - requester
  61.  
  62. ===============================================================================
  63. =end
  64.  
  65. #==============================================================================
  66. # ** Interpreter
  67. #------------------------------------------------------------------------------
  68. #  This interpreter runs event commands. This class is used within the
  69. #  Game_System class and the Game_Event class.
  70. #==============================================================================
  71. class Interpreter
  72.   #--------------------------------------------------------------------------
  73.   # * Set new item prices temporarily
  74.   #--------------------------------------------------------------------------
  75.   def price(type, id, buyp, sellp=buyp/2)
  76.     case type
  77.     when 0
  78.       $game_temp.changed_prices.push([$data_items[id], $data_items[id].price])
  79.       $data_items[id].price = [buyp, sellp]
  80.     when 1
  81.       $game_temp.changed_prices.push([$data_weapons[id], $data_weapons[id].price])
  82.       $data_weapons[id].price = [buyp, sellp]
  83.     when 2
  84.       $game_temp.changed_prices.push([$data_armors[id], $data_armors[id].price])
  85.       $data_armors[id].price = [buyp, sellp]
  86.     else
  87.       return false
  88.     end
  89.     return true
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * Revert items back to their original database prices
  93.   #--------------------------------------------------------------------------
  94.   def reset_prices
  95.     $game_temp.changed_prices.each{|item|
  96.       item[0].price = item[1]
  97.     }
  98.     $game_temp.changed_prices.clear
  99.   end
  100.  
  101. end
  102.  
  103. #==============================================================================
  104. # ** Game_Temp
  105. #------------------------------------------------------------------------------
  106. #  This class handles temporary data that is not included with save data.
  107. #  Refer to "$game_temp" for the instance of this class.
  108. #==============================================================================
  109. class Game_Temp
  110.   attr_accessor :changed_prices, :sell_flag
  111.   #--------------------------------------------------------------------------
  112.   # * Initialize two more variables
  113.   #--------------------------------------------------------------------------
  114.   alias init_changed_item_prices initialize
  115.   def initialize
  116.     init_changed_item_prices
  117.     @changed_prices = []
  118.     @sell_flag = false
  119.   end
  120.  
  121. end
  122.  
  123. #==============================================================================
  124. # ** Various RPG classes
  125. #------------------------------------------------------------------------------
  126. #  Redefine item prices to have individual buy and sell prices.
  127. #==============================================================================
  128. class RPG::Item
  129.   def price
  130.     if @price.is_a?(Array)
  131.       return ($game_temp.sell_flag ? @price[1]*2 : @price[0])
  132.     else
  133.       return @price
  134.     end
  135.   end
  136. end
  137.  
  138. class RPG::Weapon
  139.   def price
  140.     if @price.is_a?(Array)
  141.       return ($game_temp.sell_flag ? @price[1]*2 : @price[0])
  142.     else
  143.       return @price
  144.     end
  145.   end
  146. end
  147.  
  148. class RPG::Armor
  149.   def price
  150.     if @price.is_a?(Array)
  151.       return ($game_temp.sell_flag ? @price[1]*2 : @price[0])
  152.     else
  153.       return @price
  154.     end
  155.   end
  156. end
  157.  
  158. #==============================================================================
  159. # ** Scene_Shop
  160. #------------------------------------------------------------------------------
  161. #  This class performs shop screen processing.
  162. #==============================================================================
  163.  
  164. class Scene_Shop
  165.   #--------------------------------------------------------------------------
  166.   # * Main Processing
  167.   # Reverts item prices back to their database amounts when closed
  168.   #--------------------------------------------------------------------------
  169.   alias revert_item_prices_after main
  170.   def main
  171.     # Calls main/default method
  172.     revert_item_prices_after
  173.     # Revert all items back to their original prices
  174.     $game_temp.changed_prices.each{|item|
  175.       item[0].price = item[1]
  176.     }
  177.     $game_temp.changed_prices.clear
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # * Frame Update (when command window is active)
  181.   #--------------------------------------------------------------------------
  182.   alias update_sell_flag update_command
  183.   def update_command
  184.     # If C button was pressed
  185.     if Input.trigger?(Input::C) && !Input.trigger?(Input::B)
  186.       # Branch by command window cursor position
  187.       case @command_window.index
  188.       when 0  # buy
  189.         $game_temp.sell_flag = false
  190.       when 1  # sell
  191.         $game_temp.sell_flag = true
  192.       end
  193.     end
  194.     update_sell_flag
  195.   end
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement