(Kinda works but not right) Parameter based HP/MP regen?

I was wondering if it would be possible to have a regeneration effect based on a parameter.


For example, each turn the character recovers (parameter value)/2 HP. So if they had 20 vitality (or whatever param) they would recover 10 HP.


If possible, I would like to make it work with a state, so I can use yanfly's passive states and tick based regen.
In MV, it can be easily done with a lunatic mode parameter on Yanfly's Buff and State's core. For example, here's the code I use to regenerate 2 * the caster's MAT in a state (ignore the fact the variable is called damage, I use the same code for poisons too, and didn't want to change the name of the variable):


<Custom Regenerate Effect>


var damage = origin.mat * 2.0;


// Heal the amount of HP stored in damage.


target.gainHp(damage);


// Check if the target is dead.


if (target.isDead()) {


// If the target is dead, make it collapse.


target.performCollapse();


}


</Custom Regenerate Effect>


Change the code in line 1 to regenerate whatever you wish.
In MV, it can be easily done with a lunatic mode parameter on Yanfly's Buff and State's core. For example, here's the code I use to regenerate 2 * the caster's MAT in a state (ignore the fact the variable is called damage, I use the same code for poisons too, and didn't want to change the name of the variable):


<Custom Regenerate Effect>


var damage = origin.mat * 2.0;


// Heal the amount of HP stored in damage.


target.gainHp(damage);


// Check if the target is dead.


if (target.isDead()) {


// If the target is dead, make it collapse.


target.performCollapse();


}


</Custom Regenerate Effect>


Change the code in line 1 to regenerate whatever you wish.

This works, but for some reason every turn It does like 20 regens. I am working with low parameter values, which may influence it. My characters agility is 10, and it seems to not happen as bad at higher agi for some reason. I use yanfly ctb battle system, and tick based regen. Something about tick based regen and low agi is causing the problem.
What'd you change line 1 to? It will calculate whatever you change line 1 to for your regen.


Also, keep in mind that CTB was never designed to work well for low AGI values, so you may run into a lot of trouble with that alone. The only fix is to raise your AGI values if that is causing a problem.

Original thread: https://forums.rpgmakerweb.com/threads/kinda-works-but-not-right-parameter-based-hp-mp-regen.65291/