#-------------------------------------------------------------------------------
# Consume After Battle v1.0b
#-- Automatically consume designated restorative items after battle.
#-- By mjshi
#-------------------------------------------------------------------------------
# Installation:
# Put above Main, preferably below any custom battle scripts that you have.
#
# There may be some conflicts as this script overwrites on_battle_end.
# To solve that issue, locate where "def on_battle_end" is in the script
# then add the line
# consume_ab
# somewhere under it.
#-------------------------------------------------------------------------------
# Future updates:
#- Configure amount of times an item can be used.
#-------------------------------------------------------------------------------
module ConsumeAB
#-----------------------------------------------------------------------------
# **CONFIGURATION**
#-----------------------------------------------------------------------------
# The switch number to turn Consume After Battle on/off with.
# Set to true to not use a switch
#
AUTOCONSUME_ON = true
#
#-----------------------------------------------------------------------------
# Format:
# [ID, 'HP' or 'MP' or 'Both', Decimal% or Constant],
#-----------------------------------------------------------------------------
# If you have multiple items that restore varying degrees of HP/MP:
#
# It is recommended that you group items by largest increments first. The
# script will check for, and use, the FIRST thing it finds. Make sure the
# items are ordered in the order you want to use them.
#-----------------------------------------------------------------------------
# Example:
# CONSUME_ITEM = [
# [1, 'HP', 0.15], # Restores 15% HP. Used before the 10% restore.
# [2, 'HP', 0.10], # Restores 10% HP. Used before the 250 point restore.
# [3, 'HP', 250], # Restores 250 HP. Used before restoring 100 HP.
# [4, 'HP', 100], # ..and so on.
# [5, 'MP', 0.25], # This is an example of an MP restore item.
# [6, 'Both', 0.25], # This item will restore both HP and MP. Neat, eh?
# ]
#-----------------------------------------------------------------------------
# **Don't forget the comma after each entry!**
#
CONSUME_ITEM = [
[1, 'HP', 50],
]
#-----------------------------------------------------------------------------
end
#--------------------------------------------------------------------#
# !!! Beware of crashes and errors if you edit beyond this point !!! #
#--------------------------------------------------------------------#
class Game_Battler
def on_battle_end
@result.clear
# add consume_ab method
if ConsumeAB::AUTOCONSUME_ON or $game_switches[ConsumeAB::AUTOCONSUME_ON]
consume_ab
end
remove_battle_states
remove_all_buffs
clear_actions
clear_tp unless preserve_tp?
appear
end
def consume_ab
$game_party.members.each do |a|
for i in ConsumeAB::CONSUME_ITEM
# if player does not have item, do nothing
if $game_party.item_number($data_items[i[0]]) == 0
nil
# else, if item restores a percentage
elsif i[2] < 1
if a.hp <= (a.mhp * (1 - i[2])).to_i or a.mp <= (a.mmp * (1 - i[2])).to_i
a.hp += (a.mhp * i[2]).to_i if i[1] == 'HP'
a.mp += (a.mmp * i[2]).to_i if i[1] == 'MP'
if i[1] == 'Both'
a.hp += (a.mhp * i[2]).to_i
a.mp += (a.mmp * i[2]).to_i
end
# remove the item from the inventory
$game_party.lose_item($data_items[i[0]], 1)
end
# else, if the item restores a constant
elsif i[2] > 1
if a.hp <= a.mhp - i[2] or a.mp <= a.mmp - i[2]
a.hp += i[2] if i[1] == 'HP'
a.mp += i[2] if i[1] == 'MP'
if i[1] == 'Both'
a.hp += i[2]
a.mp += i[2]
end
# remove the item from the inventory
$game_party.lose_item($data_items[i[0]], 1)
end
end
end
end
end
end