MV Stacking Lifesteal with Yanfly?

I'm looking for help on how to make a state that utilizes counters for each hit on a target, then uses those to stack up lifesteal, up to a limit of 20, worth 5% each. I think this would be easier if I knew how to (call?) lifesteal like other values but right now I have this complicated mixture that doesn't work from other skills I wrote and found.


TLDR; Hit enemy, get 5% lifesteal per hit, not steal 5% life per hit, but actually increase the rate of lifestealing.

I'm not sure if user.LifeStealRate works at all.
I thought it'd start sort of like this (this clearly doesn't work but the idea is there) :

Code:
<Custom Confirm Effect>
// Check if the damage dealt deals physical HP damage.
if (value > 0 && this.isHpEffect()) {
  user._stackinglife = user._stackinglife || 0;
  // Get the current number of stacks. Min 0, Max 20.
  var stacks = user._stackinglife.clamp(0, 20);
  // Increase stack count.
  stacks += 1;
  // Set stack count min to 0, max to 20.
  stacks = stacks.clamp(0, 20);
  user.setStateCounter(stateId, 'x' + stacks);
  user._stackinglife = stacks;
var bonus = (stacks * 0.05)
dmg = Math.ceil(value * bonus);
user.gainHp(dmg);
user.startDamagePopup();
user.clearResult();
}
</Custom Confirm Effect>


<Custom Remove Effect>
// Reset the stack count.
user._stackinglife = 0;
</Custom Remove Effect>
theres a missing ; when you create the bonus variable.

when i was writing life stealing skills, i found that the life steal plugin didnt work on my project and decided to use other methods for lifestealing, like using the damage formula tag to give the user the amount of healing according to the damage. its a good thing to note that the damage made may be more than the target have of hp left, meaning a target with 1 hp would receive 20 damage and the life stolen would be more than the amount deserved.

i would recommend you trying build this effect based on the damage formula notetag instead of a state. i found that way more simpler.

EDIT:
heres the code from the life stealing skill i made then:

Code:
<Damage Formula>
   //made some calculations using other plugins, element rates and variables:
   var sml = a.skillMasteryLevel(20);
   var dR = ((a.elementRate(15) - 1) * 10);
   var dLVL = $gameVariables.value(43);
   var dALT = $gameVariables.value(44);
 
   //defined what the damage would be to the target:
   var NVALue = sml + dALT + dLVL + dR;
 
   //if target was near death and damage would be greater, id give the exact value so the target would die:
   value = Math.min(NVALue, target.hp);
 
   //and the skill user would receive what life left the target had before the damage:
   a.gainHp(Math.floor(value));
 
</Damage Formula>
theres a missing ; when you create the bonus variable.

when i was writing life stealing skills, i found that the life steal plugin didnt work on my project and decided to use other methods for lifestealing, like using the damage formula tag to give the user the amount of healing according to the damage. its a good thing to note that the damage made may be more than the target have of hp left, meaning a target with 1 hp would receive 20 damage and the life stolen would be more than the amount deserved.

i would recommend you trying build this effect based on the damage formula notetag instead of a state. i found that way more simpler.

EDIT:
heres the code from the life stealing skill i made then:

Code:
<Damage Formula>
   //made some calculations using other plugins, element rates and variables:
   var sml = a.skillMasteryLevel(20);
   var dR = ((a.elementRate(15) - 1) * 10);
   var dLVL = $gameVariables.value(43);
   var dALT = $gameVariables.value(44);

   //defined what the damage would be to the target:
   var NVALue = sml + dALT + dLVL + dR;

   //if target was near death and damage would be greater, id give the exact value so the target would die:
   value = Math.min(NVALue, target.hp);

   //and the skill user would receive what life left the target had before the damage:
   a.gainHp(Math.floor(value));

</Damage Formula>
I love how clean the code is written for this, but I believe we're talking about different types of lifesteal. In a lot of modern games, lifesteal is just a heal based on a percentage of the damage dealt, rather than actually stealing the hp of an enemy. It's a means of self sustain whilst still doing damage. The only problem with the damage formula is that I am not sure how to utilize stacks, increasing the rate of lifesteal % per successful hit of the ability.
create a state for the life thief that when applied, will check if a counter exists or create one:

user._stealStack = user.stealStack || 0;

//dont forget to add the state to the attacker on the beginning of the damage forumla:
a.addState(Y); //replace Y with the state id.

//when calculating the damage of the skill, check if the counter exists as above and then use it on the calculation:
//like, maybe:
value = X * user._stealStack; //do your magic here.
//and add a counter since the battler used the skill a once more:
user._stealStack++;


see if the above code on your damage formula notetag helps. reset the counters whenever the state is removed.

Original thread: https://forums.rpgmakerweb.com/threads/stacking-lifesteal-with-yanfly.132208/