Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- ===============================================================================
- Custom Prices Version 1.0
- by KK20 [11/25/2013]
- ===============================================================================
- _______________________________________________________________________________
- + Introduction
- RPG Maker only allows items to have one set of prices. The sell price of items
- is half the price set in the database. With this script, you can modify the
- prices of items, weapons, and armors to whatever you want. The change is only
- temporary, so you can have shops sell certain items at unique prices. You can
- also change the sell price to anything. Make an item cost a high amount, but
- make it unavailable to sell. Have shops buy specific kinds of items. The
- choice is up to you!
- _______________________________________________________________________________
- + Instructions
- Place this script below any custom scripts that rely on item prices.
- To change the prices of items, use one of these script calls:
- price(TYPE, ID, BUY_PRICE)
- price(TYPE, ID, BUY_PRICE, SELL_PRICE)
- where TYPE can be 0 (Item), 1 (Weapon), or 2 (Armor)
- ID refers to the item's ID in the database
- BUY_PRICE is the new price of the item
- SELL_PRICE is the new sell price of the item
- SELL_PRICE is optional. If you do not put a sell price, items will
- default to being half the BUY_PRICE.
- If you ever need to reset the price changes, use the script call:
- reset_prices
- This is only needed if using custom scripts that rely on item prices
- but are not considered shops (e.g. ForeverZer0's Blacksmith Shop).
- -------------
- Examples:
- -------------
- price(0, 1, 300) # Potion prices: BUY = 300, SELL = 150
- price(1, 1, 5000, 100) # Bronze Sword prices: BUY = 5000, SELL = 100
- price(2, 25, 9001, 0) # Ring of Strength prices: BUY = 9001, SELL = Can't sell at this shop
- _______________________________________________________________________________
- + Notes
- It is recommended to put these script calls just before the 'Shop Processing'
- command. Immediately after the player exits the shop, the item prices WILL
- revert back to their original database prices.
- This script may be compatible with some Custom Shop Systems. The more complex
- the script, the less likely.
- _______________________________________________________________________________
- + Credits
- KK20 - for writing the script
- firevenge007 - requester
- ===============================================================================
- =end
- #==============================================================================
- # ** Interpreter
- #------------------------------------------------------------------------------
- # This interpreter runs event commands. This class is used within the
- # Game_System class and the Game_Event class.
- #==============================================================================
- class Interpreter
- #--------------------------------------------------------------------------
- # * Set new item prices temporarily
- #--------------------------------------------------------------------------
- def price(type, id, buyp, sellp=buyp/2)
- case type
- when 0
- $game_temp.changed_prices.push([$data_items[id], $data_items[id].price])
- $data_items[id].price = [buyp, sellp]
- when 1
- $game_temp.changed_prices.push([$data_weapons[id], $data_weapons[id].price])
- $data_weapons[id].price = [buyp, sellp]
- when 2
- $game_temp.changed_prices.push([$data_armors[id], $data_armors[id].price])
- $data_armors[id].price = [buyp, sellp]
- else
- return false
- end
- return true
- end
- #--------------------------------------------------------------------------
- # * Revert items back to their original database prices
- #--------------------------------------------------------------------------
- def reset_prices
- $game_temp.changed_prices.each{|item|
- item[0].price = item[1]
- }
- $game_temp.changed_prices.clear
- end
- end
- #==============================================================================
- # ** Game_Temp
- #------------------------------------------------------------------------------
- # This class handles temporary data that is not included with save data.
- # Refer to "$game_temp" for the instance of this class.
- #==============================================================================
- class Game_Temp
- attr_accessor :changed_prices, :sell_flag
- #--------------------------------------------------------------------------
- # * Initialize two more variables
- #--------------------------------------------------------------------------
- alias init_changed_item_prices initialize
- def initialize
- init_changed_item_prices
- @changed_prices = []
- @sell_flag = false
- end
- end
- #==============================================================================
- # ** Various RPG classes
- #------------------------------------------------------------------------------
- # Redefine item prices to have individual buy and sell prices.
- #==============================================================================
- class RPG::Item
- def price
- if @price.is_a?(Array)
- return ($game_temp.sell_flag ? @price[1]*2 : @price[0])
- else
- return @price
- end
- end
- end
- class RPG::Weapon
- def price
- if @price.is_a?(Array)
- return ($game_temp.sell_flag ? @price[1]*2 : @price[0])
- else
- return @price
- end
- end
- end
- class RPG::Armor
- def price
- if @price.is_a?(Array)
- return ($game_temp.sell_flag ? @price[1]*2 : @price[0])
- else
- return @price
- end
- end
- end
- #==============================================================================
- # ** Scene_Shop
- #------------------------------------------------------------------------------
- # This class performs shop screen processing.
- #==============================================================================
- class Scene_Shop
- #--------------------------------------------------------------------------
- # * Main Processing
- # Reverts item prices back to their database amounts when closed
- #--------------------------------------------------------------------------
- alias revert_item_prices_after main
- def main
- # Calls main/default method
- revert_item_prices_after
- # Revert all items back to their original prices
- $game_temp.changed_prices.each{|item|
- item[0].price = item[1]
- }
- $game_temp.changed_prices.clear
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when command window is active)
- #--------------------------------------------------------------------------
- alias update_sell_flag update_command
- def update_command
- # If C button was pressed
- if Input.trigger?(Input::C) && !Input.trigger?(Input::B)
- # Branch by command window cursor position
- case @command_window.index
- when 0 # buy
- $game_temp.sell_flag = false
- when 1 # sell
- $game_temp.sell_flag = true
- end
- end
- update_sell_flag
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement