Advertisement
TheSixth

Battle Use Limits Addon

Nov 2nd, 2020
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.13 KB | None | 0 0
  1. =begin
  2.  
  3. - Battle Use Limits Addon v1.0
  4. - Made by: Sixth
  5. - Requires: Tsukihime's Battle Use Limits
  6.  
  7. - Description:
  8.  
  9. This short script will let you make features that will restrict the amount of
  10. uses for the specified skills and items in battle.
  11.  
  12. - Note-tags:
  13.  
  14. To set a battle use limit feature to your actors, classes, equipment and states,
  15. you can use this note-tag:
  16.  
  17.   <battle use limit: typeID, max_uses>
  18.  
  19. The type part must be replaced by i or s.
  20.   i - For items.
  21.   s - For skills.
  22.  
  23. The ID part must be replaced by the database ID of the skill/item.
  24.  
  25. And the max_uses part will be the maximum uses allowed for the skill/item
  26. in battles.
  27.  
  28. You can use multiples of this note-tag on the same database object if needed to
  29. limit more than one skill/item.
  30.  
  31.   Examples:
  32.  
  33.   <battle use limit: s45, 3>
  34.   <battle use limit: i70, 1>
  35.  
  36. - Important note:
  37.  
  38. While this script will limit the usage of skills/items even if the note-tag is
  39. used on a state, it will NOT reset the usage count of skills/items when a state
  40. with battle use limit restriction is expired/removed.
  41. What does this mean? Well, imagine this scenario:
  42.  
  43. 1. Actor got inflicted by a state that restricts the usage of Skill 30 to a
  44.    maximum of 3 uses per battle.
  45. 2. Actor used the skill 3 times in battle, can't use it anymore until the state
  46.    is expired/cured.
  47. 3. State expired/cured. Still in the same battle. Actor can now use Skill 30
  48.    again.
  49. 4. Actor got inflicted by the same state in the same battle again.
  50. 5. Skill 30 is now disabled again, because the skill has been used 3 times
  51.    already in this battle.
  52.    
  53. I may add a feature for a usage reset on states later if requested.
  54.  
  55. - Installation:
  56.  
  57. Place this script below Tsukihime's Battle Use Limits script!
  58.  
  59. =end
  60.  
  61. class RPG::BaseItem
  62.  
  63.   attr_accessor :battle_use_l
  64.  
  65.   def battle_use_l
  66.     init_battle_use_l if @battle_use_l.nil?
  67.     return @battle_use_l
  68.   end
  69.  
  70.   def init_battle_use_l
  71.     @battle_use_l = []
  72.     cnote = @note.clone
  73.     while cnote =~ /<battle use limit:(?:\s*)(i|s)(\d+)(?:\s*),(?:\s*)(\d+)>/i
  74.       @battle_use_l << [$1, $2.to_i, $3.to_i]
  75.       cnote.sub!(/<battle use limit:(?:\s*)(i|s)(\d+)(?:\s*),(?:\s*)(\d+)>/i,"")
  76.     end
  77.   end
  78.  
  79. end
  80.  
  81. class Game_BattlerBase
  82.  
  83.   def battle_use_l(tp,iid)
  84.     b_use_l = []
  85.     feature_objects.each do |ft|
  86.       bul = ft.battle_use_l
  87.       bul.each do |bl|
  88.         next unless bl[0] == tp && bl[1] == iid
  89.         b_use_l << bl
  90.       end
  91.     end
  92.     return -1 if b_use_l.empty?
  93.     return b_use_l.min_by {|bl| bl[2] }[2]
  94.   end
  95.  
  96.   alias add_bul9921 battle_skill_use_exceeded?
  97.   def battle_skill_use_exceeded?(sk)
  98.     return true if use_exceeded?('s',sk.id,@skill_use_counts[sk.id])
  99.     return add_bul9921(sk)
  100.   end
  101.  
  102.   alias add_bul2961 battle_item_use_exceeded?
  103.   def battle_item_use_exceeded?(it)
  104.     return true if use_exceeded?('i',it.id,@item_use_counts[it.id])
  105.     return add_bul2961(it)
  106.   end
  107.  
  108.   def use_exceeded?(tp,sid,use_num)
  109.     return false unless $game_party.in_battle
  110.     bsl = battle_use_l('s',sid)
  111.     return false if bsl < 0
  112.     return use_num >= bsl
  113.   end
  114.  
  115. end
  116. # End of script!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement