Heal HP based on spent MP

Hello!


I was wondering if someone could help me with a state I'm trying to create. Essentially, I'm trying to create a state that heals the user's HP depending on how much MP they use. I'm open to adding scripts if they are needed.


Yanfly did create a video on this kind of state, although it's for MV opposed to VxAce. Here's the video, in case it helps better explain what I'm after:


https://www.youtube.com/watch?v=bPHtuUElRhA


Thank you!  🙂
It can be done without a script, but it would require you to be very carefull with your skills, and it has one limitation:


Basically you can check in the damage formula if the skill user has a state applied, and if yes heal the user by a fixed amount before applying whatever other effect there is.


Main problem: the damage formula is only executed if the skill hits, you would loose the generation if the skill misses or is evaded.


And of course you need to know how much each specific skill costs, but unless you're using other scripts that would always be the number you set in the skill itself - easy to see when writing the skill damage formula
Edit: Oh man I should really look for which engine first. Sorry!
Thanks for the suggestions thus far! I'll certainly keep the damage formula solution in mind, although it would be nice to tie the effect to the state itself if at all possible simply due to having a somewhat rediculous smount of skills already made.


I did do some more research, and it seems that my best bet would be by using Yanfly's Lunatic States script. He has some examples in the two lunatic state packs, which I'm guessing could be made into what I'm looking for with a bit of tweaking. By chance could someone with a bit of scripting know-how take a look into this for me?
I needed a little practice. Try this:

Spoiler
#==============================================================================
#
# ▼ Yanfly Engine Ace - Lunatic States Package - Reverence Effect
#
# -- Requires: YEA - Lunatic States v1.00+
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-LSP-Reverence"] = true

#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# Install this script under YEA - Lunatic States. Then, proceed to use the
# proper effects notetags to apply the proper LSP Reverence item desired.
# Look within the script for more instructions on how to use each effect.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
# This script requires YEA - Lunatic States v1.00+ to work. It must be placed
# under YEA - Lunatic States v1.00+ in the script listing.
#
#==============================================================================

if $imported["YEA-LunaticStates"]
class Game_BattlerBase

#--------------------------------------------------------------------------
# ● Lunatic States Package Effects - Reverence
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#--------------------------------------------------------------------------
alias :lunatic_state_extension_reverence :lunatic_state_extension
def lunatic_state_extension(effect, state, user, state_origin, log_window)
case effect.upcase
#----------------------------------------------------------------------
# Reverence
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Affected is healed by the current skill's MP cost.
#
# Recommended notetag:
# <while effect: reverence x%>
#
#----------------------------------------------------------------------
when /REVERENCE[ ](\d+)([%%])/i
action = user.current_action.item
return unless action.is_a?(RPG::Skill)

value = (action.mp_cost * ($1.to_i / 100.0)).round.to_i
if $imported["YEA-BattleEngine"] && value > 0
Sound.play_recovery
text = sprintf(YEA::BATTLE:😛OPUP_SETTINGS[:hp_heal], value.group)
user.create_popup(text, "HP_HEAL")
end

user.hp = [user.hp + value, 0].max

#----------------------------------------------------------------------
# Stop editting past this point.
#----------------------------------------------------------------------
else
so = state_origin
lw = log_window
lunatic_state_extension_reverence(effect, state, user, so, lw)
end
end

end # Game_BattlerBase
end # $imported["YEA-LunaticStates"]

#==============================================================================
#
# ▼ End of File
#
#==============================================================================



Just add: <while effect: reverence 100%> to the note section of the state in question.
A set percentage of a skill's MP cost (if it has one) will be converted into HP restoration.
I needed a little practice. Try this:

Spoiler
#==============================================================================
#
# ▼ Yanfly Engine Ace - Lunatic States Package - Reverence Effect
#
# -- Requires: YEA - Lunatic States v1.00+
#
#==============================================================================

$imported = {} if $imported.nil?
$imported["YEA-LSP-Reverence"] = true

#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# Install this script under YEA - Lunatic States. Then, proceed to use the
# proper effects notetags to apply the proper LSP Reverence item desired.
# Look within the script for more instructions on how to use each effect.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
# This script requires YEA - Lunatic States v1.00+ to work. It must be placed
# under YEA - Lunatic States v1.00+ in the script listing.
#
#==============================================================================

if $imported["YEA-LunaticStates"]
class Game_BattlerBase

#--------------------------------------------------------------------------
# ● Lunatic States Package Effects - Reverence
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#--------------------------------------------------------------------------
alias :lunatic_state_extension_reverence :lunatic_state_extension
def lunatic_state_extension(effect, state, user, state_origin, log_window)
case effect.upcase
#----------------------------------------------------------------------
# Reverence
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Affected is healed by the current skill's MP cost.
#
# Recommended notetag:
# <while effect: reverence x%>
#
#----------------------------------------------------------------------
when /REVERENCE[ ](\d+)([%%])/i
action = user.current_action.item
return unless action.is_a?(RPG::Skill)

value = (action.mp_cost * ($1.to_i / 100.0)).round.to_i
if $imported["YEA-BattleEngine"] && value > 0
Sound.play_recovery
text = sprintf(YEA::BATTLE:😛OPUP_SETTINGS[:hp_heal], value.group)
user.create_popup(text, "HP_HEAL")
end

user.hp = [user.hp + value, 0].max

#----------------------------------------------------------------------
# Stop editting past this point.
#----------------------------------------------------------------------
else
so = state_origin
lw = log_window
lunatic_state_extension_reverence(effect, state, user, so, lw)
end
end

end # Game_BattlerBase
end # $imported["YEA-LunaticStates"]

#==============================================================================
#
# ▼ End of File
#
#==============================================================================



Just add: <while effect: reverence 100%> to the note section of the state in question.
A set percentage of a skill's MP cost (if it has one) will be converted into HP restoration.

Thanks a bunch, it works perfectly! 😀

Original thread: https://forums.rpgmakerweb.com/threads/heal-hp-based-on-spent-mp.73173/