SHARE
TWEET

Fomar0153 - Multiple Inventories 1.1

Fomar0153 May 5th, 2012 4,913 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2. Multiple Inventories
  3. by Fomar0153
  4. Version 1.1
  5. ----------------------
  6. Notes
  7. ----------------------
  8. Allows you to easily handle multiple inventories in game.
  9. ----------------------
  10. Instructions
  11. ----------------------
  12. The default inventory is called "Main" you can change it below
  13. if you wish.
  14. To change inventory call:
  15. $game_party.change_inventory(name)
  16. To merge two inventories call:
  17. $game_party.merge_inventories(inv1, inv2)
  18. inv1 will recieve all the gold and items in inv2
  19. If ERASE_WHEN_MERGE is set to true then inv2 will be erased after
  20. the merge.
  21. ----------------------
  22. Change Log
  23. ----------------------
  24. 1.0 -> 1.1 Updated a glitch causing gold not to change when you change inventory.
  25. ----------------------
  26. Known bugs
  27. ----------------------
  28. None
  29. =end
  30. class Game_Party < Game_Unit
  31.   #--------------------------------------------------------------------------
  32.   # ● Set the name of your starting inventory here
  33.   #--------------------------------------------------------------------------
  34.   START_INVENTORY = "Main"
  35.   #--------------------------------------------------------------------------
  36.   # ● Set the name of your starting inventory here
  37.   #--------------------------------------------------------------------------
  38.   ERASE_WHEN_MERGE = true
  39.   #--------------------------------------------------------------------------
  40.   # ● Aliased
  41.   #--------------------------------------------------------------------------
  42.   alias mi_initialize initialize
  43.   def initialize
  44.     mi_initialize
  45.     @current_inventory = START_INVENTORY
  46.     @gold = {}
  47.     @gold[START_INVENTORY] = 0
  48.     @last_item = Game_BaseItem.new
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● New, example call $game_party.change_inventory(name)
  52.   #--------------------------------------------------------------------------
  53.   def change_inventory(name)
  54.     if @gold[name].nil?
  55.       @gold[name] = 0
  56.       @items[name] = {}
  57.       @weapons[name] = {}
  58.       @armors[name] = {}
  59.     end
  60.     @current_inventory = name
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # ● New, example call $game_party.merge_inventories(inv1, inv2)
  64.   #--------------------------------------------------------------------------
  65.   def merge_inventories(inv1, inv2)
  66.     return if @gold[inv1].nil? or @gold[inv2].nil?
  67.     @current_inventory = inv1
  68.     @gold[inv1] += @gold[inv2]
  69.     @gold[inv2] = nil if ERASE_WHEN_MERGE
  70.     for item in @items[inv2].keys
  71.       gain_item($data_items[item.to_i], @items[inv2][item])
  72.     end
  73.     @items[inv2] = nil if ERASE_WHEN_MERGE
  74.     for weapon in @weapons[inv2].keys
  75.       gain_item($data_weapons[weapon.to_i], @weapons[inv2][weapon])
  76.     end
  77.     @weapons[inv2] = nil if ERASE_WHEN_MERGE
  78.     for armor in @armors[inv2].keys
  79.       gain_item($data_armors[armor.to_i], @armors[inv2][armor])
  80.     end
  81.     @armors[inv2] = nil if ERASE_WHEN_MERGE
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● Aliased
  85.   #--------------------------------------------------------------------------
  86.   alias mi_init_all_items init_all_items
  87.   def init_all_items
  88.     mi_init_all_items
  89.     @items[START_INVENTORY] = {}
  90.     @weapons[START_INVENTORY] = {}
  91.     @armors[START_INVENTORY] = {}
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● New
  95.   #--------------------------------------------------------------------------
  96.   def gold
  97.     return @gold[@current_inventory]
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # ● Rewrites
  101.   #--------------------------------------------------------------------------
  102.   def items
  103.     @items[@current_inventory].keys.sort.collect {|id| $data_items[id] }
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # ● Rewrites
  107.   #--------------------------------------------------------------------------
  108.   def weapons
  109.     @weapons[@current_inventory].keys.sort.collect {|id| $data_weapons[id] }
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ● Rewrites
  113.   #--------------------------------------------------------------------------
  114.   def armors
  115.     @armors[@current_inventory].keys.sort.collect {|id| $data_armors[id] }
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # ● Rewrites
  119.   #--------------------------------------------------------------------------
  120.   def item_container(item_class)
  121.     return @items[@current_inventory]   if item_class == RPG::Item
  122.     return @weapons[@current_inventory] if item_class == RPG::Weapon
  123.     return @armors[@current_inventory]  if item_class == RPG::Armor
  124.     return nil
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ● Rewrites
  128.   #--------------------------------------------------------------------------
  129.   def gain_gold(amount)
  130.     @gold[@current_inventory] = [[@gold[@current_inventory] + amount, 0].max, max_gold].min
  131.   end
  132. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top