Spell that heals for the TP spent

So, I wanted to make a spell that costs all your current TP to heal a target's mana by the same amount.


So, using Yanfly's Skill Core I put this in the notetag:

Code:
<Custom TP Cost>
cost = user.tp
</Custom TP Cost>

and this in the damage formula (Heal MP)

Code:
a.tp

But it doesn't work. I think this is because the cost is applied before the effect so that the spell always heals for 0.


Is there a way to make the effect apply before the cost?
I'm not really good with javascript code when it comes to Yanfly's Lunatic tags. I have to google the forums like crazy to find examples. This is just a theory:


Yanfly's Skill core also has Skill Phase notetags. I believe the <Before Eval> tag should be used to set the actor's current TP to a variable. This tag allows code to run before the cost is taken.


Then use the <Post-Damage Eval> tag to subtract the actor's current TP equal to the amount of the variable.


Lastly, you'd have to use a <Cost Display Eval> with the proper text codes to display the cost of the TP.


EDIT: If you're setting a minimum amount of TP to have when using the skill, you'll need a <Custom Requirement> tag as well. There are a lot of examples in the Help File.


EDIT #2:


This should work.


<Cost Display Eval>
var variableId = 1;
var value = a.tp;
$gameVariables.setValue(variableId, value);
</Cost Display Eval>

<Custom Cost Display>
\c[4]\v[1]\c[0] TP
</Custom Cost Display>

<Pre-Damage Eval>
a.gainTp(-v[1]);
</Pre-Damage Eval>


In the skill, make sure to set the Damage type to "MP Recover" with a damage formula of v[1] (or whatever variable you're working with). Also, have the variance set to 0%. Mp Cost, Tp cost, and TP Gain should all be set to 0 as well.


Be sure to change the text codes accordingly to match whatever you have.
Thank you!


It works 🙂

Original thread: https://forums.rpgmakerweb.com/threads/spell-that-heals-for-the-tp-spent.60960/