Advertisement
Szyu

Items Class Restriction

Aug 28th, 2014
1,774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.91 KB | None | 0 0
  1. #==============================================================================
  2. # Szyu's Item's Class Restriction
  3. # Version 1.2
  4. # By Szyu
  5. #
  6. # About:
  7. # Easily specify items, weapons and armors, which can only be used/equipped
  8. # by certain classes
  9. #
  10. # Instructions:
  11. # - Place below "▼ Materials" but above "▼ Main Process".
  12. #
  13. # How to Use:
  14. # - An item's note have to contain one of these:
  15. # <classes: x> # This will allow specified classes to use this item
  16. # <!classes: x> # This will forbit specified classes to use this item
  17. #
  18. # Seperate multiple classes with ','!
  19. # Allowed Database Items, which can be restricted by this script:
  20. # - Items
  21. # - Weapons
  22. # - Armors
  23. #
  24. # If There is none of those tags in the items note, every class is permitted to
  25. # use or equip this item
  26. #
  27. #
  28. # Requires:
  29. # - RPG Maker VX Ace
  30. #
  31. # Terms of Use:
  32. # - Free for commercal and non-commercial use. Please list me
  33. #   in the credits to support my work.
  34. #
  35. #
  36. # Changelog:
  37. # - Same syntax can now be used to restrict for actors:
  38. #   <actors: x>
  39. #   <!actors: x>
  40. # - Added Use Restriction for battles too. Restricted classes and actors can no
  41. #   longer use restricted items in battle
  42. #
  43. #
  44. #
  45. # Pastebin:
  46. # http://adf.ly/rYIZm
  47. #
  48. #
  49. #==============================================================
  50. #   * Game_BattlerBase
  51. #==============================================================
  52. class Game_BattlerBase
  53.   alias sz_iucr_equippable? equippable?
  54.  
  55.   def equippable?(item)
  56.     return false unless item.is_a?(RPG::EquipItem)
  57.     return false if self.is_a?(Game_Actor) &&
  58.       (item.forbid_classes.include?(self.class_id) || item.forbid_actors.include?(self.id))
  59.     return sz_iucr_equippable?(item)
  60.   end
  61. end
  62.  
  63. #==============================================================
  64. #   * Game_Battler
  65. #==============================================================
  66. class Game_Battler < Game_BattlerBase
  67.   alias sz_iucr_item_test item_test
  68.  
  69.   def item_test(user, item)
  70.     return false if item.is_a?(RPG::Item) &&
  71.       (item.forbid_classes.include?(self.class_id) || item.forbid_actors.include?(self.id))
  72.     return sz_iucr_item_test(user, item)
  73.   end
  74. end
  75.  
  76. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77.  
  78. #==============================================================
  79. #   * Initialize BaseItems
  80. #==============================================================
  81. module DataManager
  82.   class << self
  83.     alias load_db_iucr_sz load_database
  84.   end
  85.  
  86.   def self.load_database
  87.     load_db_iucr_sz
  88.     load_iucr_items
  89.   end
  90.  
  91.   def self.load_iucr_items
  92.     groups = [$data_items, $data_weapons, $data_armors]
  93.     for group in groups
  94.       for obj in group
  95.         next if obj.nil?
  96.         obj.load_iucr_notetags_sz
  97.       end
  98.     end
  99.   end
  100. end
  101.  
  102. #==============================================================================
  103. # ** Window_BattleActor
  104. #------------------------------------------------------------------------------
  105. #  This window is for selecting an actor's action target on the battle screen.
  106. #==============================================================================
  107. class Window_BattleActor < Window_BattleStatus
  108.   #--------------------------------------------------------------------------
  109.   # * Get Activation State of Selection Item
  110.   #--------------------------------------------------------------------------
  111.   def current_item_enabled?
  112.     return false if !BattleManager.actor.input.item.is_a?(RPG::UsableItem) ||
  113.       BattleManager.actor.input.item.forbid_classes.include?(BattleManager.actor.input.subject.class_id) ||
  114.       BattleManager.actor.input.item.forbid_actors.include?(BattleManager.actor.input.subject.id)
  115.     return true
  116.   end
  117. end
  118.  
  119. #==============================================================
  120. #   * Content of Recycling Items
  121. #==============================================================
  122. class RPG::BaseItem
  123.   attr_accessor :forbid_classes
  124.   attr_accessor :forbid_actors
  125.  
  126.   def load_iucr_notetags_sz
  127.     @forbid_classes = []
  128.     @forbid_actors = []
  129.     self.note.split(/[\r\n]+/).each do |line|
  130.       # Forbid Classes
  131.       if line =~ /<classes:([\d+,?\s*]+)>/i
  132.         $data_classes.each do |cl|
  133.           @forbid_classes.push(cl.id) if cl
  134.         end
  135.         $1.scan(/\s*,?\d+,?\s*/i).each do |cl|
  136.           @forbid_classes.delete(cl.to_i)
  137.         end
  138.       elsif line =~ /<!classes:([\d+,?\s*]+)>/i
  139.         $1.scan(/\s*,?\d+,?\s*/i).each do |cl|
  140.           @forbid_classes.push(cl.to_i)
  141.         end
  142.         # Forbid Actors
  143.       elsif line =~ /<actors:([\d+,?\s*]+)>/i
  144.         $data_actors.each do |ac|
  145.           @forbid_actors.push(ac.id) if ac
  146.         end
  147.         $1.scan(/\s*,?\d+,?\s*/i).each do |ac|
  148.           @forbid_actors.delete(ac.to_i)
  149.         end
  150.       elsif line =~ /<!actors:([\d+,?\s*]+)>/i
  151.         $1.scan(/\s*,?\d+,?\s*/i).each do |ac|
  152.           @forbid_actors.push(ac.to_i)
  153.         end
  154.       end
  155.     end
  156.   end  
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement