Take damage from skill

Hello, I was wondering if there was a formula I could input to make my character take a percentage of the damage dealt to the enemy.

Example:

Let's say the skill Take Down does 300 damage. I would like for 10% of that damage (30 damage) to be delt back to the user.

NOTE: The percentage is what I am after (10% specifically), not the static damage (300/30 damage).

Thank you!
Try something like this~
Code:
var dmg = a.atk * 4 - b.def * 2, ouch = Math.round(dmg * 0.1); a.gainHp(-ouch); dmg
Full explanation:
  • Calculate skill damage and store in a temporary variable named dmg;
  • Calculate self damage (0.1 = 10% of dmg value, rounded to nearest integer) and store in temporary ouch var;
  • Apply self damage to skill user (i.e. "gain negative ouch HP");
  • Return dmg as formula result. 😤
(These "temporary" variables are deleted once the formula has been evaluated.)
Try something like this~
Code:
var dmg = a.atk * 4 - b.def * 2, ouch = Math.round(dmg * 0.1); a.gainHp(-ouch); dmg
Full explanation:
  • Calculate skill damage and store in a temporary variable named dmg;
  • Calculate self damage (0.1 = 10% of dmg value, rounded to nearest integer) and store in temporary ouch var;
  • Apply self damage to skill user (i.e. "gain negative ouch HP");
  • Return dmg as formula result. 😤
(These "temporary" variables are deleted once the formula has been evaluated.)

HILARIOUS!

Thank you for the breakdown too. That should help me with other formulas I might need.
You're welcome, happy RPG Making! 🙏

Original thread: https://forums.rpgmakerweb.com/threads/take-damage-from-skill.109901/