Advertisement
Guest User

[RGSS3] Storage Boxes: Item Types

a guest
Jul 1st, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.73 KB | None | 0 0
  1. #==============================================================================
  2. # Storage Boxes Addon: Item Types
  3. #   by IMP1
  4. #------------------------------------------------------------------------------
  5. # THIS SCRIPT REQUIRES THE 'STORAGE BOXES' SCRIPT BY IMP1
  6. #
  7. # Now items can only be put in a box if that box allows that type of item.
  8. # You can give a type to an item with the notetag <item type: Clothing> in the
  9. # items notebox (replacing Clothing with whatever types you want).
  10. # To specify that a box can handle items of a type, or can handle all types
  11. # except a few, see below.
  12. #
  13. #------------------------------------------------------------------------------
  14. #   Compatability:
  15. #
  16. # Aliased Methods:
  17. #   IMP1_Game_Boxes.setup
  18. #   Scene_ItemStorage.can_move_item_to_box?
  19. #
  20. # New Methods/Fields:
  21. #   Scene_ItemStorage.item_goes_in_box?
  22. #
  23. # Overwritten Methods:
  24. #   none.
  25. #
  26. #------------------------------------------------------------------------------
  27. #   Version History:
  28. # v1.0 [2015/06/27] : Initial release.
  29. #==============================================================================
  30.  
  31. module IMP1_Storage_Boxes
  32. #------------------------------------------------------------------------------
  33. # CONFIGURATION BEGIN:
  34. #------------------------------------------------------------------------------
  35.  
  36.   # If this is set to true, and you haven't specified the allowed types for the
  37.   # box, all items will be allowed. If it is set to false, no items will be
  38.   # allowed.
  39.   ALLOWED_BY_DEFAULT = true
  40.  
  41.   BOX_TYPES = { # Do not remove.
  42.  
  43.     # To allow a box to take all items, have the following:
  44.     # id => :all,
  45.    
  46.     # To have a box accept ONLY the specified item types, have the following:
  47.     # id => [:only, "Item Type 1", "Item Type 2"],
  48.    
  49.     # To have a box accept all item types EXCEPT some, have the following:
  50.     # id => [:all_but, "Item Type 1", "Item Type 2"],
  51.    
  52.     # The first box will take everything
  53.     0 => :all,
  54.    
  55.     # The fourth will be a jewelery box (eg. and so only take jewelery)
  56.     3 => [:only, "Jewelery"],
  57.    
  58.     # The fourth will be a microwave (eg. and so can't take metal)
  59.     4 => [:all_but, "Metal"],
  60.  
  61.   } # Do not remove.
  62.  
  63. #------------------------------------------------------------------------------
  64. # CONFIGURATION END.
  65. #------------------------------------------------------------------------------
  66. end
  67. #==============================================================================
  68. # Game_Boxes
  69. #==============================================================================
  70. class IMP1_Game_Boxes
  71.   #--------------------------------------------------------------------------
  72.   # Returns box with the specified id, or returns a new, empty, default box.
  73.   #--------------------------------------------------------------------------
  74.   alias :non_type_setup :setup unless $@
  75.   def setup(box_id, name=DEFAULT_BOX_NAME, size=DEFAULT_BOX_SIZE,
  76.             open_sound=nil, close_sound=nil, type=nil)
  77.     non_type_setup(box_id, name, size, open_sound, close_sound)
  78.     if !type.nil?
  79.       BOX_TYPES[box_id] = type
  80.     end
  81.   end
  82.  
  83. end # IMP1_Game_Boxes
  84.  
  85. #==============================================================================
  86. # Scene_ItemStorage
  87. #==============================================================================
  88. class Scene_ItemStorage
  89.   #--------------------------------------------------------------------------
  90.   # Returns true if item can be moved from the inventory to the box.
  91.   #--------------------------------------------------------------------------
  92.   alias :non_type_check :can_move_item_to_box? unless $@
  93.   def can_move_item_to_box?(item)
  94.     return false if !non_type_check(item)
  95.     return item_goes_in_box?(item)
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # Returns true the item is of the right type for this box.
  99.   #--------------------------------------------------------------------------
  100.   def item_goes_in_box?(item)
  101.     if !IMP1_Storage_Boxes::BOX_TYPES.has_key?(@box_id)
  102.       return IMP1_Storage_Boxes::ALLOWED_BY_DEFAULT
  103.     end
  104.     box_types = IMP1_Storage_Boxes::BOX_TYPES[@box_id]
  105.     return true if box_types == :all
  106.     if box_types[0] == :only
  107.       looking_for = true
  108.     elsif box_types[0] == :all_but
  109.       looking_for = false
  110.     else
  111.       error = "You've not set the permissions for box number #{@box_id}" +
  112.               "correctly. The list must start with either :only or :all_but"
  113.       msgbox(error)
  114.       return IMP1_Storage_Boxes::ALLOWED_BY_DEFAULT
  115.     end
  116.     for item_type in item.note.scan(/<item type: (.+)>/).flatten
  117.       return looking_for if box_types.include?(item_type)
  118.     end
  119.     return !looking_for
  120.   end
  121.  
  122. end # Scene_ItemStorage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement