Damage Formula Question

Ok, so I have an issue where I want my character to heal themselves by a percentage of the damage caused if the enemy is under a certain state.

Example: If the enemy is under the state Bleed [#0043], then do regular damage and heal your life by 50% of the damage caused, otherwise do regular damage.

I looked at the Damage Formula Thread, but I don't know how to put it together to get my intended outcome.

Thanks!

EDIT:

Wait, does YEP_LifeSteal do that? If it does, I don't need help then, because while playing my game, I have the notetag on one of my characters and he is set to do 10% lifesteal.

Did 1700 damage
Healed 170 HP

Is this right?


Nevermind, going back on what I was asking for since I am looking for the state causing the effects and not just the effects itself.
always do regular damage, and send the battlers to a post-damage common event.

in the common event, check for state, and THEN, do the calculations.
in order to grab the battlers in question you need to grab the scene, so:
Code:
scene = SceneManager._scene
battler = scene._subject
target = $gameTroop.members[battler._lastTargetIndex]

there is no way to calculate "heal by a percentage of the damage dealt", without first dealing the damage.
always do regular damage, and send the battlers to a post-damage common event.

in the common event, check for state, and THEN, do the calculations.
in order to grab the battlers in question you need to grab the scene, so:
Code:
scene = SceneManager._scene
battler = scene._subject
target = $gameTroop.members[battler._lastTargetIndex]

there is no way to calculate "heal by a percentage of the damage dealt", without first dealing the damage.


Probably should have revisited my old threads first but...

Take damage from skill

This seems to be what I am looking for, but the opposite.

And I only want it to heal IF the enemy is under that status effect "Bleed"
well, that's one way, but if you do that you're regenerating BEFORE applying the damage, so if there's another code dealing with any of those aspects it'll likely fail to run correctly.

the damage formula should only be used to deliver the damage (and, if you want to use it correctly 100%, only be used to deliver the attack value, not the damage dealt, and not involve the defense of the target.... the damage calculation should be handled by the battle system)

for that particular case, your code should look like this:

Code:
var dmg = (formula), regen = Math.round(dmg * percentage); if (b.isStateAffected(ID)) {a.gainHp(regen)}; dmg
well, that's one way, but if you do that you're regenerating BEFORE applying the damage, so if there's another code dealing with any of those aspects it'll likely fail to run correctly.

the damage formula should only be used to deliver the damage (and, if you want to use it correctly 100%, only be used to deliver the attack value, not the damage dealt, and not involve the defense of the target.... the damage calculation should be handled by the battle system)

for that particular case, your code should look like this:

Code:
var dmg = (formula), regen = Math.round(dmg * percentage); if (b.isStateAffected(ID)) {a.gainHp(regen)}; dmg

So something like this:
Code:
var dmg = (a.atk * 4), regen = Math.round(dmg * 0.50); if (b.isStateAffected(43)) {a.gainHp(regen)}; dmg

Whereas a.atk * 4 is the formula, 50% of the damage is converted to HP Regen if the enemy is under State 43 (Bleed)?
yes, but you have to include the target's defense in the formula.
yes, but you have to include the target's defense in the formula.

Well, my intention was to have skills take hp away. To compensate, I made attacks ignore defense. Unless, that's not how it works.
there is no *how it works* when it comes to damage formulas, which is one of the things I dislike about the whole system.
there is no *how it works* when it comes to damage formulas, which is one of the things I dislike about the whole system.

Yikes. So is ignoring defense not explicitly defined or what I did was one way to do it out of thousands of others?

Because I'm mildly confused at this point.
if you don't add in the defense *because you don't need it*, that's fine.
I mean, that with the default damage formula you always have to add in the target's defense and make each skill calculate the damage on it's own, as opposed to having the battle system do it (which should be the correct way, IMO)

Original thread: https://forums.rpgmakerweb.com/threads/damage-formula-question.110180/