Advertisement
AngryPacman

[VXA] Price Changer

Feb 17th, 2012
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.41 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Price Changer (1.0)
  4. # 18/02/2012
  5. # By Pacman
  6. # This script allows you to change the price of items mid-game.
  7. # To do this, use the script call:
  8. # change_price(sym, id, [price])
  9. # Where sym is :item, :weapon or :armor (depending on what you're chaning the
  10. # price of), id is the database ID of the item, weapon or armor you're changing,
  11. # and price is the new price (integer). If you exclude the price argument, it
  12. # defaults to the original price of the item. Examples:
  13. # change_price(:item, 4, 20) - Will change the price of the fourth item in the
  14. #   database to 20.
  15. # change_price(:weapon, 2, 50) - Will change the price of the second weapon
  16. #   in the database to 50.
  17. # change_price(:armor, 3) - Will change the price of the third armor in the
  18. #   database to the original price.
  19. # You can also use :i, :w or :a as sym.
  20. #
  21. #===============================================================================
  22.  
  23. #==============================================================================
  24. # ■ Game_System
  25. #------------------------------------------------------------------------------
  26. #  システム周りのデータを扱うクラスです。セーブやメニューの禁止状態などを保存
  27. # します。このクラスのインスタンスは $game_system で参照されます。
  28. #==============================================================================
  29.  
  30. class Game_System
  31.   #--------------------------------------------------------------------------
  32.   # Public Instance Variables
  33.   #--------------------------------------------------------------------------
  34.   attr_accessor :new_price
  35.   #--------------------------------------------------------------------------
  36.   # * Get new prices
  37.   #--------------------------------------------------------------------------
  38.   def new_price
  39.     if @new_price.nil?
  40.       @new_price = {}
  41.       @new_price[:item] = []
  42.       @new_price[:weapon] = []
  43.       @new_price[:armor] = []
  44.     end
  45.     @new_price
  46.   end
  47. end
  48.  
  49. #==============================================================================
  50. # ■ Game_Interpreter
  51. #------------------------------------------------------------------------------
  52. #  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、
  53. # Game_Troop クラス、Game_Event クラスの内部で使用されます。
  54. #==============================================================================
  55.  
  56. class Game_Interpreter
  57.   #--------------------------------------------------------------------------
  58.   # * Adjust the price of items
  59.   #     sym   : type of item to alter
  60.   #     id    : id of the item to alter
  61.   #     price : new price of the item (defaults to original)
  62.   #--------------------------------------------------------------------------
  63.   def change_price(sym, id, price = nil)
  64.     if sym == :item || sym == :i      # Items
  65.       price ||= $data_items[id].orig_price
  66.       $game_system.new_price[:item][id] = price
  67.     elsif sym == :weapon || sym == :w # Weapons
  68.       price ||= $data_weapons[id].orig_price
  69.       $game_system.new_price[:weapon][id] = price
  70.     elsif sym == :armor || sym == :a  # Armours
  71.       price ||= $data_armors[id].orig_price
  72.       $game_system.new_price[:armor][id] = price
  73.     end
  74.   end
  75. end
  76.  
  77. #==============================================================================
  78. # *** RPG
  79. #------------------------------------------------------------------------------
  80. #  Module that holds data classes for all things in the game.
  81. #==============================================================================
  82.  
  83. module RPG
  84.   #--------------------------------------------------------------------------
  85.   # **  Classes Item, Weapon, Armor
  86.   #--------------------------------------------------------------------------
  87.   [["Item", "items"], ["Weapon", "weapons"], ["Armor", "armor"]].each { |klass|
  88.     # Create new methods
  89.     prcchg = %Q(class #{klass[0]}; def orig_price; @price; end
  90.     def price; return $game_system.new_price[:#{klass[1]}][@id].nil? ? @price :
  91.     $game_system.new_price[:#{klass[1]}][@id]; end; end)
  92.     eval(prcchg)
  93.   }
  94. end
  95.  
  96. $imported ||= {}
  97. $imported[:pac_price_changer]
  98.  
  99. #===============================================================================
  100. #
  101. # END OF SCRIPT
  102. #
  103. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement