Advertisement
neutale

Item Destruction Rate

Jun 17th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.20 KB | None | 0 0
  1. =begin
  2. RGSS3 Item Destruction Rate Ver.1.11  2012/03/26 mo-to
  3.  
  4. TKOOL COOL
  5. http://mototkool.blog.fc2.com/
  6.  
  7. ★Usage★
  8. Paste this script above Main.
  9.  
  10. In the item's Note box, put <probability destroy n%> n = 1 to 99.
  11. Ex.) If <probability destroy 30%> in the Note box for the item "potion"
  12. When used, there is a 30% chance of using up a "potion".
  13.  
  14. ★Overview★
  15. You can create items that are used with probability.
  16.  
  17. ★Update history★
  18. Ver.1.00 Initial released
  19. Ver.1.10 Added a message for broken
  20. Ver.1.11 Item name can also be displayed
  21. =end
  22.  
  23. #↓Customization
  24. module MOTO
  25.   #Disrupted message displayed on the menu screen (control characters available)
  26.   MESSEGE = "\\C[2] is broken!"
  27.  
  28.   #Broken message displayed during battle
  29.   BATTLE_MESSEGE = "%s is broken!"
  30.  
  31. end
  32. #So far
  33.  
  34. class RPG::Item < RPG::UsableItem
  35.   #--------------------------------------------------------------------------
  36.   # ☆ Acquisition of memo field
  37.   #--------------------------------------------------------------------------
  38.   def item_break_rate_set
  39.     @item_break_rate = nil
  40.     self.note.each_line { |line|
  41.       case line
  42.       when /<probability destroy \s*(\d+)([%])?>/
  43.         @item_break_rate = $1.to_i
  44.       end
  45.     }
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ☆ Acquisition of destruction probability
  49.   #--------------------------------------------------------------------------
  50.   def item_break_rate
  51.     item_break_rate_set if @item_break_rate == nil
  52.     return @item_break_rate
  53.   end
  54. end
  55.  
  56. class Game_Party < Game_Unit
  57.   #--------------------------------------------------------------------------
  58.   # ☆ Public instance variable
  59.   #--------------------------------------------------------------------------
  60.   attr_accessor   :lose_item_window     # Item disruption window display flag
  61.   #--------------------------------------------------------------------------
  62.   # ○ Object initialization
  63.   #--------------------------------------------------------------------------
  64.   alias ori_moto_initialize initialize
  65.   def initialize
  66.     ori_moto_initialize
  67.    
  68.     @lose_item_window = false
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ○ Item consumption
  72.   #    If the specified item is consumed, reduce the number of possession.
  73.   #--------------------------------------------------------------------------
  74.   alias ori_moto_consume_item consume_item
  75.   def consume_item(item)
  76.     break_rate = rand(100) + 1
  77.     if item.item_break_rate != nil && item.item_break_rate < break_rate &&
  78.       item.is_a?(RPG::Item) && item.consumable
  79.       lose_item(item, 0)
  80.     elsif item.item_break_rate != nil && item.item_break_rate > break_rate &&
  81.       item.is_a?(RPG::Item) && item.consumable
  82.       lose_item(item, 1)
  83.       @lose_item_window= true
  84.     else
  85.       ori_moto_consume_item(item)
  86.     end
  87.   end  
  88. end
  89.  
  90. class Window_Mini_Messege < Window_Selectable
  91.   #--------------------------------------------------------------------------
  92.   # ☆ Object initialization
  93.   #--------------------------------------------------------------------------
  94.   def initialize
  95.     super(0, 0, window_width, window_height)
  96.     @item = nil
  97.     self.visible = false
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # ☆ Item, setting of maximum number
  101.   #--------------------------------------------------------------------------
  102.   def set(item)
  103.     @item = item
  104.     refresh
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ☆ Get window width
  108.   #--------------------------------------------------------------------------
  109.   def window_width
  110.     Graphics.width / 2
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ☆ Get window height
  114.   #--------------------------------------------------------------------------
  115.   def window_height
  116.     return 72
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # ☆ Refresh
  120.   #--------------------------------------------------------------------------
  121.   def refresh
  122.     self.x = (Graphics.width - width) / 2
  123.     self.y = (Graphics.height - height) / 2
  124.     self.z = 255
  125.     draw_item_name(@item, 0, 0)
  126.     draw_text_ex(0, 26, MOTO::MESSEGE)
  127.   end
  128. end
  129.  
  130. class Window_BattleLog < Window_Selectable
  131.   #--------------------------------------------------------------------------
  132.   # ● Display action results
  133.   #--------------------------------------------------------------------------
  134.   def display_action_results(target, item)
  135.     if target.result.used
  136.       last_line_number = line_number
  137.       display_critical(target, item)
  138.       display_damage(target, item)
  139.       display_affected_status(target, item)
  140.       display_failure(target, item)
  141.       display_lose_item(item)
  142.       wait if line_number > last_line_number
  143.       back_to(last_line_number)
  144.     end
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ☆ Display when item is broken
  148.   #--------------------------------------------------------------------------
  149.   def display_lose_item(item)
  150.     if $game_party.lose_item_window
  151.       add_text(sprintf(MOTO::BATTLE_MESSEGE, item.name))
  152.       $game_party.lose_item_window = false
  153.       wait
  154.     end
  155.   end
  156. end
  157.  
  158. class Scene_ItemBase < Scene_MenuBase
  159.   #--------------------------------------------------------------------------
  160.   # ○ Start process
  161.   #--------------------------------------------------------------------------
  162.   alias ori_moto_start start
  163.   def start
  164.     ori_moto_start
  165.    
  166.     create_mini_messege_window
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ☆ Create mini window
  170.   #--------------------------------------------------------------------------
  171.   def create_mini_messege_window
  172.     @mini_messege_window = Window_Mini_Messege.new
  173.     @mini_messege_window.set_handler(:ok,     method(:on_winclose_ok))
  174.     @mini_messege_window.set_handler(:cancel, method(:on_winclose_cancel))
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ☆ Mini window close [Ok]
  178.   #--------------------------------------------------------------------------
  179.   def on_winclose_ok
  180.     @mini_messege_window.hide
  181.     @actor_window.activate
  182.     @actor_window.refresh
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # ☆ Mini window close [cancel]
  186.   #--------------------------------------------------------------------------
  187.   def on_winclose_cancel
  188.     @mini_messege_window.hide
  189.     @actor_window.activate
  190.     @actor_window.refresh
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # ○ Use item
  194.   #--------------------------------------------------------------------------
  195.   alias ori_moto_use_item use_item
  196.   def use_item
  197.     ori_moto_use_item
  198.    
  199.     if $game_party.lose_item_window
  200.       @actor_window.deactivate
  201.       @mini_messege_window.set(item)
  202.       @mini_messege_window.show
  203.       @mini_messege_window.activate
  204.       $game_party.lose_item_window = false
  205.       Input.update
  206.     end
  207.   end
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement