Advertisement
mjshi

Consume After Battle v1.0b

Sep 23rd, 2015
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.11 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Consume After Battle v1.0b
  3. #-- Automatically consume designated restorative items after battle.
  4. #-- By mjshi
  5. #-------------------------------------------------------------------------------
  6. # Installation:
  7. # Put above Main, preferably below any custom battle scripts that you have.
  8. #
  9. # There may be some conflicts as this script overwrites on_battle_end.
  10. # To solve that issue, locate where "def on_battle_end" is in the script
  11. # then add the line
  12. # consume_ab
  13. # somewhere under it.
  14. #-------------------------------------------------------------------------------
  15. # Future updates:
  16. #- Configure amount of times an item can be used.
  17. #-------------------------------------------------------------------------------
  18.  
  19. module ConsumeAB
  20.  
  21.   #-----------------------------------------------------------------------------
  22.   # **CONFIGURATION**
  23.   #-----------------------------------------------------------------------------
  24.   # The switch number to turn Consume After Battle on/off with.
  25.   # Set to true to not use a switch
  26.   #
  27.   AUTOCONSUME_ON = true
  28.   #
  29.   #-----------------------------------------------------------------------------
  30.   # Format:
  31.   # [ID, 'HP' or 'MP' or 'Both', Decimal% or Constant],
  32.   #-----------------------------------------------------------------------------
  33.   # If you have multiple items that restore varying degrees of HP/MP:
  34.   #
  35.   # It is recommended that you group items by largest increments first. The
  36.   # script will check for, and use, the FIRST thing it finds. Make sure the
  37.   # items are ordered in the order you want to use them.
  38.   #-----------------------------------------------------------------------------
  39.   # Example:
  40.   # CONSUME_ITEM = [
  41.   # [1, 'HP', 0.15], # Restores 15% HP. Used before the 10% restore.
  42.   # [2, 'HP', 0.10], # Restores 10% HP. Used before the 250 point restore.
  43.   # [3, 'HP', 250], # Restores 250 HP. Used before restoring 100 HP.
  44.   # [4, 'HP', 100], # ..and so on.
  45.   # [5, 'MP', 0.25], # This is an example of an MP restore item.
  46.   # [6, 'Both', 0.25], # This item will restore both HP and MP. Neat, eh?
  47.   # ]
  48.   #-----------------------------------------------------------------------------
  49.   # **Don't forget the comma after each entry!**
  50.   #
  51.   CONSUME_ITEM = [
  52.   [1, 'HP', 50],
  53.   ]
  54.   #-----------------------------------------------------------------------------
  55. end
  56.  
  57. #--------------------------------------------------------------------#
  58. # !!! Beware of crashes and errors if you edit beyond this point !!! #
  59. #--------------------------------------------------------------------#
  60.  
  61. class Game_Battler
  62.   def on_battle_end
  63.     @result.clear
  64.    
  65.     # add consume_ab method
  66.     if ConsumeAB::AUTOCONSUME_ON or $game_switches[ConsumeAB::AUTOCONSUME_ON]
  67.       consume_ab
  68.     end
  69.    
  70.     remove_battle_states
  71.     remove_all_buffs
  72.     clear_actions
  73.     clear_tp unless preserve_tp?
  74.     appear
  75.   end
  76.  
  77.   def consume_ab
  78.   $game_party.members.each do |a|
  79.     for i in ConsumeAB::CONSUME_ITEM
  80.       # if player does not have item, do nothing
  81.       if $game_party.item_number($data_items[i[0]]) == 0
  82.         nil
  83.      
  84.       # else, if item restores a percentage
  85.       elsif i[2] < 1
  86.         if a.hp <= (a.mhp * (1 - i[2])).to_i or a.mp <= (a.mmp * (1 - i[2])).to_i
  87.           a.hp += (a.mhp * i[2]).to_i if i[1] == 'HP'
  88.           a.mp += (a.mmp * i[2]).to_i if i[1] == 'MP'
  89.           if i[1] == 'Both'
  90.             a.hp += (a.mhp * i[2]).to_i
  91.             a.mp += (a.mmp * i[2]).to_i
  92.           end
  93.           # remove the item from the inventory
  94.           $game_party.lose_item($data_items[i[0]], 1)
  95.         end
  96.       # else, if the item restores a constant
  97.       elsif i[2] > 1
  98.         if a.hp <= a.mhp - i[2] or a.mp <= a.mmp - i[2]
  99.           a.hp += i[2] if i[1] == 'HP'
  100.           a.mp += i[2] if i[1] == 'MP'
  101.           if i[1] == 'Both'
  102.             a.hp += i[2]
  103.             a.mp += i[2]
  104.           end
  105.           # remove the item from the inventory
  106.           $game_party.lose_item($data_items[i[0]], 1)
  107.         end
  108.       end
  109.      
  110.     end
  111.   end
  112.   end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement