Advertisement
FlipelyFlip

FFS - Actor Restrict Item Use

Aug 7th, 2024 (edited)
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.76 KB | None | 0 0
  1. #==============================================================
  2. #
  3. #               RESTRICT ITEM FOR ACTOR
  4. #
  5. # Mit diesem Script kann man bestimmte Items für bestimmte
  6. # Helden im Kampf nicht auswählbar machen. Man muss lediglich
  7. # bei dem entsprechenden Item einen Notetag mit der ID des
  8. # Helden einfügen.
  9. #
  10. # <restrict actor: id>
  11. #
  12. # Wenn man ein Item nur dann aus dem Menü heraus nutzen kann,
  13. # wenn ein bestimmter Held in der Gruppe ist, kann man hierfür
  14. # diesen Notetag nutzen:
  15. #
  16. # <needed actor: id>
  17. #
  18. # Falls ein Item nur auf einen bestimmten Helden genutzt werden
  19. # kann, dann wird dieser Notetag verwendet. ID Entspricht dem
  20. # Helden in der Datenbank:
  21. #
  22. # <only actor: id>
  23. #
  24. #==============================================================
  25.  
  26.  
  27. #==============================================================
  28. #   * Initialize BaseItems
  29. #==============================================================
  30. module DataManager
  31.   class << self
  32.     alias :load_ffs_db_ri :load_database
  33.   end
  34.  
  35.   def self.load_database
  36.     load_ffs_db_ri
  37.     load_ffsri_items
  38.   end
  39.  
  40.   def self.load_ffsri_items
  41.     groups = [$data_items]
  42.     for group in groups
  43.       for obj in group
  44.         next if obj.nil?
  45.         obj.load_ffs_notetags_ri
  46.       end
  47.     end
  48.   end
  49. end
  50.  
  51. #==============================================================
  52. #   * Content of Recycling Items
  53. #==============================================================
  54. class RPG::BaseItem
  55.   attr_accessor :restricted_actors
  56.   attr_accessor :needed_actors
  57.   attr_accessor :only_actors
  58.  
  59.   def load_ffs_notetags_ri
  60.     @restricted_actors = []
  61.     @needed_actors = []
  62.     @only_actors = []
  63.     self.note.split(/[\r\n]+/).each do |line|
  64.       # Restricts the Actor
  65.       if line =~ /<restrict actor:([\d+,?\s*]+)>/i
  66.         @restricted_actors.push($1.to_i)
  67.       # Requires the Actor
  68.       elsif line =~ /<needed actor:([\d+,?\s*]+)>/i
  69.         @needed_actors.push($1.to_i)
  70.       elsif line =~ /<only actor:([\d+,?\s*]+)>/i
  71.         @only_actors.push($1.to_i)
  72.       end
  73.     end
  74.   end  
  75. end
  76.  
  77. #==============================================================================
  78. # ** Window_ItemList
  79. #------------------------------------------------------------------------------
  80. #  This window displays a list of party items on the item screen.
  81. #==============================================================================
  82. class Window_ItemList < Window_Selectable
  83.   #--------------------------------------------------------------------------
  84.   # * Display in Enabled State?
  85.   #--------------------------------------------------------------------------
  86.   alias :flip_itemList_enable :enable?
  87.   def enable?(item)
  88.     return true if item != nil && $game_party.members.include?(item.needed_actors)
  89. #~     return false if item != nil && !item.restricted_actors != [] && !$game_party.members.include?(item.needed_actors)
  90.     return flip_itemList_enable(item)
  91.   end
  92. end
  93.  
  94. #==============================================================================
  95. # ** Window_BattleActor
  96. #------------------------------------------------------------------------------
  97. #  This window is for selecting an actor's action target on the battle screen.
  98. #==============================================================================
  99. class Game_BattlerBase
  100.   #--------------------------------------------------------------------------
  101.   # * Determine Skill/Item Usability
  102.   #--------------------------------------------------------------------------
  103.   alias :usable_ffs_restrict_actor :usable?
  104.   def usable?(item)
  105.     return false if item.is_a?(RPG::Item) && item.restricted_actors.include?(@actor_id)
  106.     return usable_ffs_restrict_actor(item)
  107.   end
  108. end
  109.  
  110. #==============================================================================
  111. # ** Game_Battler
  112. #------------------------------------------------------------------------------
  113. #  A battler class with methods for sprites and actions added. This class
  114. # is used as a super class of the Game_Actor class and Game_Enemy class.
  115. #==============================================================================
  116. class Game_Battler < Game_BattlerBase
  117.   #--------------------------------------------------------------------------
  118.   # * Test Skill/Item Application
  119.   #    Used to determine, for example, if a character is already fully healed
  120.   #   and so cannot recover anymore.
  121.   #--------------------------------------------------------------------------
  122.   def item_test(user, item)
  123.     if item.for_dead_friend?
  124.       return hp == 0 if SceneManager.scene_is?(Scene_Item)
  125.       return true
  126.     end
  127.     if item.is_a?(RPG::Item)
  128.       return false if item.only_actors != [] && !item.only_actors.include?(self.id)
  129.     end
  130.     return true if $game_party.in_battle
  131.     return true if item.for_opponent?
  132.     return true if item.damage.recover? && item.damage.to_hp? && hp < mhp
  133.     return true if item.damage.recover? && item.damage.to_mp? && mp < mmp
  134.     return true if item_has_any_valid_effects?(user, item)
  135.     return false
  136.   end
  137. end
  138.  
  139. #==============================================================================
  140. # ** Window_BattleItem
  141. #------------------------------------------------------------------------------
  142. #  This window is for selecting items to use in the battle window.
  143. #==============================================================================
  144. class Window_BattleItem < Window_ItemList
  145.   #--------------------------------------------------------------------------
  146.   # * Include in Item List?
  147.   #--------------------------------------------------------------------------
  148.   def include?(item)
  149.     return false if !item.is_a?(RPG::Item)
  150.     return false if item != nil && (item.restricted_actors.include?(BattleManager.actor.id))
  151.     $game_party.usable?(item)
  152.   end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement