Advertisement
roninator2

Szyu's Item Class Restriction mod

Dec 5th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.84 KB | None | 0 0
  1. #==============================================================================
  2. # Szyu's Item's Class Restriction
  3. # Version 1.3       # Mod by Roninator2
  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. #   * Game_BattlerBase
  45. #==============================================================
  46. class Game_BattlerBase
  47.   alias sz_iucr_equippable? equippable?
  48.  
  49.   def equippable?(item)
  50.     return false unless item.is_a?(RPG::EquipItem)
  51.     return false if self.is_a?(Game_Actor) &&
  52.       (item.forbid_classes.include?(self.class_id) || item.forbid_actors.include?(self.id))
  53.     return sz_iucr_equippable?(item)
  54.   end
  55. end
  56. #==============================================================
  57. #   * Game_Battler
  58. #==============================================================
  59. class Game_Battler < Game_BattlerBase
  60.   alias sz_iucr_item_test item_test
  61.  
  62.   def item_test(user, item)
  63.   return sz_iucr_item_test(user, item) if self.is_a?(Game_Enemy)
  64.   if SceneManager.scene_is?(Scene_Battle)
  65.     return false if item.is_a?(RPG::Item) &&
  66.      (item.forbid_classes.include?(user.class_id) || item.forbid_actors.include?(user.id))
  67.    else
  68.      return false if item.is_a?(RPG::Item) &&
  69.      (item.forbid_classes.include?(self.class_id) || item.forbid_actors.include?(self.id))
  70.    end
  71.    return sz_iucr_item_test(user, item)
  72.     end
  73. end
  74.  
  75. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76.  
  77. #==============================================================
  78. #   * Initialize BaseItems
  79. #==============================================================
  80. module DataManager
  81.   class << self
  82.     alias load_db_iucr_sz load_database
  83.   end
  84.  
  85.   def self.load_database
  86.     load_db_iucr_sz
  87.     load_iucr_items
  88.   end
  89.  
  90.   def self.load_iucr_items
  91.     groups = [$data_items, $data_weapons, $data_armors]
  92.     for group in groups
  93.       for obj in group
  94.         next if obj.nil?
  95.         obj.load_iucr_notetags_sz
  96.       end
  97.     end
  98.   end
  99. end
  100.  
  101. #==============================================================================
  102. # ** Window_BattleActor
  103. #------------------------------------------------------------------------------
  104. #  This window is for selecting an actor's action target on the battle screen.
  105. #==============================================================================
  106. class Window_BattleActor < Window_BattleStatus
  107.   #--------------------------------------------------------------------------
  108.   # * Get Activation State of Selection Item
  109.   #--------------------------------------------------------------------------
  110.   def current_item_enabled?
  111.     return false if !BattleManager.actor.input.item.is_a?(RPG::UsableItem) ||
  112.       BattleManager.actor.input.item.forbid_classes.include?(BattleManager.actor.input.subject.class_id) ||
  113.       BattleManager.actor.input.item.forbid_actors.include?(BattleManager.actor.input.subject.id)
  114.     return true
  115.   end
  116. end
  117.  
  118. #==============================================================================
  119. # ** Window_BattleActor
  120. #------------------------------------------------------------------------------
  121. #  This window is for selecting an actor's action target on the battle screen.
  122. #==============================================================================
  123. class Window_BattleEnemy < Window_Selectable
  124.   #--------------------------------------------------------------------------
  125.   # * Get Activation State of Selection Item
  126.   #--------------------------------------------------------------------------
  127.   def current_item_enabled?
  128.     return false if !BattleManager.actor.input.item.is_a?(RPG::UsableItem) ||
  129.       BattleManager.actor.input.item.forbid_classes.include?(BattleManager.actor.input.subject.class_id) ||
  130.       BattleManager.actor.input.item.forbid_actors.include?(BattleManager.actor.input.subject.id)
  131.     return true
  132.   end
  133. end
  134.  
  135. #==============================================================
  136. #   * Content of Recycling Items
  137. #==============================================================
  138. class RPG::BaseItem
  139.   attr_accessor :forbid_classes
  140.   attr_accessor :forbid_actors
  141.  
  142.   def load_iucr_notetags_sz
  143.     @forbid_classes = []
  144.     @forbid_actors = []
  145.     self.note.split(/[\r\n]+/).each do |line|
  146.       # Forbid Classes
  147.       if line =~ /<classes:([\d+,?\s*]+)>/i
  148.         $data_classes.each do |cl|
  149.           @forbid_classes.push(cl.id) if cl
  150.         end
  151.         $1.scan(/\s*,?\d+,?\s*/i).each do |cl|
  152.           @forbid_classes.delete(cl.to_i)
  153.         end
  154.       elsif line =~ /<!classes:([\d+,?\s*]+)>/i
  155.         $1.scan(/\s*,?\d+,?\s*/i).each do |cl|
  156.           @forbid_classes.push(cl.to_i)
  157.         end
  158.         # Forbid Actors
  159.       elsif line =~ /<actors:([\d+,?\s*]+)>/i
  160.         $data_actors.each do |ac|
  161.           @forbid_actors.push(ac.id) if ac
  162.         end
  163.         $1.scan(/\s*,?\d+,?\s*/i).each do |ac|
  164.           @forbid_actors.delete(ac.to_i)
  165.         end
  166.       elsif line =~ /<!actors:([\d+,?\s*]+)>/i
  167.         $1.scan(/\s*,?\d+,?\s*/i).each do |ac|
  168.           @forbid_actors.push(ac.to_i)
  169.         end
  170.       end
  171.     end
  172.   end  
  173.   def forbid_classes
  174.     load_iucr_notetags_sz unless @forbid_classes
  175.     return @forbid_classes
  176.   end
  177.   def forbid_actors
  178.     load_iucr_notetags_sz unless @forbid_actors
  179.     return @forbid_actors
  180.   end
  181. end
  182.  
  183. # you can not select a restricted actor to use the item on,
  184. class Scene_Battle < Scene_Base
  185.   def on_actor_ok
  186.     user = $game_party.members[@actor_window.index]
  187.     if @item.is_a?(RPG::Item) && (@item.forbid_classes.include?(user.class_id) || @item.forbid_actors.include?(user.id))
  188.       Sound.play_buzzer
  189.       @actor_window.activate
  190.       return
  191.     end
  192.     BattleManager.actor.input.target_index = @actor_window.index
  193.     @actor_window.hide
  194.     @skill_window.hide
  195.     @item_window.hide
  196.     next_command
  197.   end
  198. end
  199.  
  200. # actor's name be greyed out when using an item on them is forbidden
  201. module BattleManager
  202.   def self.item_disabled(item)
  203.     @actor_item = item
  204.   end
  205.   def self.actor_item_restrict
  206.     return @actor_item
  207.   end
  208. end
  209. class Window_BattleStatus < Window_Selectable
  210.   def draw_actor_name(actor, x, y, width = 112)
  211.     change_color(hp_color(actor))
  212.     if @greyed == true
  213.       change_color(Color.new(128, 128, 128, 255))
  214.     end
  215.     draw_text(x, y, width, line_height, actor.name)
  216.   end
  217.   def draw_basic_area(rect, actor)
  218.     @item = BattleManager.actor_item_restrict
  219.     if @item.is_a?(RPG::Item) &&
  220.       (@item.forbid_classes.include?(actor.class_id) || @item.forbid_actors.include?(actor.id))
  221.       @greyed = true
  222.     end
  223.     draw_actor_name(actor, rect.x + 0, rect.y, 100)
  224.     draw_actor_icons(actor, rect.x + 104, rect.y, rect.width - 104)
  225.     @greyed = false
  226.   end
  227. end
  228. class Scene_Battle < Scene_Base
  229.   def select_actor_selection
  230.     BattleManager.item_disabled(@item)
  231.     @actor_window.refresh
  232.     @actor_window.show.activate
  233.   end
  234. end
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement