Advertisement
roninator2

Item Limited Uses - mod

Dec 15th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.68 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Item Limited Uses v1.00
  4. # -- Last Updated: 2023.09.01
  5. # -- Level: Easy
  6. # -- Requires: n/a
  7. # -- Moded by Roninator2
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-ItemLimitUse"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2023.09.01 - Started Script and Finished.
  17. #
  18. #==============================================================================
  19. # ▼ Introduction
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # Sometimes good game balance depends on restriction mechanics. One of these
  22. # mechanics include the amount of times an item can be used (limited uses)
  23. # This is intented to be used with items that you only get one of.
  24. # Compatible with Instance Items (preferred)
  25. #==============================================================================
  26. # ▼ Instructions
  27. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  28. # To install this script, open up your script editor and copy/paste this script
  29. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  30. #
  31. # -----------------------------------------------------------------------------
  32. # Item Notetags - These notetags go in the items notebox in the database.
  33. # -----------------------------------------------------------------------------
  34. # <limit use: x>
  35. # This will allow the skill to only be usable x times throughout the course of
  36. # battle. Once the skill is used x times, it is disabled until the battle is
  37. # over. This effect only takes place during battle.
  38. #
  39. #==============================================================================
  40. # ▼ Compatibility
  41. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  42. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  43. # it will run with RPG Maker VX without adjusting.
  44. #
  45. #==============================================================================
  46.  
  47. module YEA
  48.   module ITEM_RESTRICT
  49.    
  50.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  51.     # - Limited Use Settings -
  52.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  53.     # Some skills have limited uses per battle. These limited uses are reset
  54.     # at the start and end of each battle and do not apply when used outside of
  55.     # battle. There are no effects that can affect limited uses.
  56.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  57.     LIMIT_COLOUR  = 8          # Colour used from "Window" skin.
  58.     LIMIT_SIZE    = 18         # Font size used
  59.     LIMIT_TEXT    = "%s uses"  # Text used
  60.     LIMIT_ICON    = 0          # Icon used. Set 0 to disable.
  61.    
  62.   end # SKILL_RESTRICT
  63. end # YEA
  64.  
  65. #==============================================================================
  66. # ▼ Editting anything past this point may potentially result in causing
  67. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  68. # halitosis so edit at your own risk.
  69. #==============================================================================
  70.  
  71. module YEA
  72.   module REGEXP
  73.     module ITEM
  74.       LIMIT_USE = /<(?:LIMIT_USE|limit use):[ ](\d+)>/i
  75.     end # ITEM
  76.   end # REGEXP
  77. end # YEA
  78.  
  79. #==============================================================================
  80. # ■ Icon
  81. #==============================================================================
  82.  
  83. module Icon
  84.  
  85.   #--------------------------------------------------------------------------
  86.   # self.itemlimit
  87.   #--------------------------------------------------------------------------
  88.   def self.itemlimit; return YEA::ITEM_RESTRICT::LIMIT_ICON; end
  89.    
  90. end # Icon
  91.  
  92. #==============================================================================
  93. # ■ DataManager
  94. #==============================================================================
  95.  
  96. module DataManager
  97.  
  98.   #--------------------------------------------------------------------------
  99.   # alias method: load_database
  100.   #--------------------------------------------------------------------------
  101.   class <<self; alias load_database_liu load_database; end
  102.   def self.load_database
  103.     load_database_liu
  104.     load_notetags_liu
  105.   end
  106.  
  107.   #--------------------------------------------------------------------------
  108.   # new method: load_notetags_srs
  109.   #--------------------------------------------------------------------------
  110.   def self.load_notetags_liu
  111.     for obj in $data_items
  112.       next if obj.nil?
  113.       obj.load_notetags_liu
  114.     end
  115.   end
  116.  
  117. end # DataManager
  118.  
  119. #==============================================================================
  120. # ■ RPG::Item
  121. #==============================================================================
  122.  
  123. class RPG::UsableItem
  124.  
  125.   #--------------------------------------------------------------------------
  126.   # public instance variables
  127.   #--------------------------------------------------------------------------
  128.   attr_accessor :limit_use
  129.  
  130.   #--------------------------------------------------------------------------
  131.   # common cache: load_notetags_liu
  132.   #--------------------------------------------------------------------------
  133.   def load_notetags_liu
  134.     @limit_use = 0
  135.     #---
  136.     self.note.split(/[\r\n]+/).each { |line|
  137.       case line
  138.       #---
  139.       when YEA::REGEXP::ITEM::LIMIT_USE
  140.         @limit_use = $1.to_i
  141.       end
  142.     } # self.note.split
  143.     #---
  144.   end
  145.  
  146. end # RPG::Items
  147.  
  148. #==============================================================================
  149. # ■ Game_BattlerBase
  150. #==============================================================================
  151.  
  152. class Game_Battler
  153.  
  154.   #--------------------------------------------------------------------------
  155.   # * Consume Items
  156.   #--------------------------------------------------------------------------
  157.   def consume_item(item)
  158.     if item.limit_use >= 1
  159.       item.limit_use -= 1
  160.     end
  161.     $game_party.consume_item(item) if item.limit_use == 0
  162.   end
  163.    
  164. end # Game_BattlerBase
  165.  
  166. #==============================================================================
  167. # ■ Window_Base
  168. #==============================================================================
  169.  
  170. class Window_Base < Window
  171.  
  172.   def limit_colour; text_color(YEA::ITEM_RESTRICT::LIMIT_COLOUR); end;
  173.  
  174. end # Window_Base
  175.  
  176. #==============================================================================
  177. # ■ Window_SkillList
  178. #==============================================================================
  179.  
  180. class Window_ItemList < Window_Selectable
  181.  
  182.   #--------------------------------------------------------------------------
  183.   # alias method: draw_item
  184.   #--------------------------------------------------------------------------
  185.   alias window_itemlist_draw_item_liu draw_item
  186.   def draw_item(index)
  187.     if item_limit_restrict?(index)
  188.       draw_item_restriction(index)
  189.     else
  190.       window_itemlist_draw_item_liu(index)
  191.     end
  192.   end
  193.  
  194.   #--------------------------------------------------------------------------
  195.   # new method: limit_restricted?
  196.   #--------------------------------------------------------------------------
  197.   def item_limit_restrict?(index)
  198.     item = @data[index]
  199.     return true if item.limit_use >= 1
  200.   end
  201.  
  202.   #--------------------------------------------------------------------------
  203.   # new method: draw_item
  204.   #--------------------------------------------------------------------------
  205.   def draw_item_restriction(index)
  206.     item = @data[index]
  207.     rect = item_rect(index)
  208.     rect.width -= 4
  209.     draw_item_name(item, rect.x, rect.y, enable?(item))
  210.     draw_item_limited(rect, item)
  211.   end
  212.  
  213.   #--------------------------------------------------------------------------
  214.   # new method: draw_skill_limited
  215.   #--------------------------------------------------------------------------
  216.   def draw_item_limited(rect, item)
  217.     change_color(limit_colour, enable?(item))
  218.     icon = Icon.itemlimit
  219.     if icon > 0
  220.       draw_icon(icon, rect.x + rect.width-24, rect.y, enable?(item))
  221.       rect.width -= 24
  222.     end
  223.     contents.font.size = YEA::ITEM_RESTRICT::LIMIT_SIZE
  224.     text = sprintf(YEA::ITEM_RESTRICT::LIMIT_TEXT, item.limit_use)
  225.     draw_text(rect, text, 2)
  226.     reset_font_settings
  227.   end
  228.  
  229. end # Window_SkillList
  230.  
  231. #==============================================================================
  232. #
  233. # ▼ End of File
  234. #
  235. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement