Skill that deals damage and heals user by a percentage?

I am trying to do a skill that deals damage to an enemy while healing that deals damage using both the user's Def and M.Def instead of Atk and the user by 20% of the user's HP, but the healing seems to be exactly what I had set (.2).
Can anyone help fix my formula?

Code:
100 + (a.def * 4 + a.mdef * 4 - b.def * 2); a.gainHp(0.2)
r=(your damage formula); a.gainhp(a.hp*0.2); r
That worked- thank you. Know if I could only figure how to do this for my party-wide healing version of the skill.

EDIT: Well that broke something- my skill is healing the user, but dealing 0 damage to the enemy....

EDIT 2: Fixed the problem of 0 damage- I was using a.mdef instead of a.mdf...

EDIT 3: New problem:
error.png


EDIT 4: This healing effect itself is causing the error- guess I'll have to split this into two skills with the same name...
The damage formula in your screenshot is NOT what I wrote.
There is a reason why I used the temporary variable r that way.
The damage is always the last number processed in the damage formula, no matter what.
Well, you should of said the Rs were mandatory...

EDIT 1: Nope, your formula didn't work...
error2.png


EDIT 2: I just noticed I added an extra )- my mistake.

EDIT 3: WHAT THE FLIP AM I DOING WRONG?!
error3.png
Javascript is case-sensitive. Look closely and you'll see it 🙂
Javascript is case-sensitive. Look closely and you'll see it
I don't see it...
On your first post you wrote "a.gainHp" but in your damage formula you wrote "a.gainHP"
On your first post you wrote "a.gainHp" but in your damage formula you wrote "a.gainHP"
PoF.png

I tried that and it worked... Now how would I change a.gainHp to affect the entire party?
You can iterate over $gameParty but then it would always be the heroes who get healed. The way to do it so both enemies or actors could use the skill is like this. Remove your previous gainHp of course, so the caster isn't healed twice.
Code:
a.friendsUnit().aliveMembers().forEach(friend => friend.gainHp(friend.hp * 0.2));

Spoiler: For old versions of MV
Code:
a.friendsUnit().aliveMembers().forEach(function(friend) {friend.gainHp(friend.hp * 0.2)});
@Aloe Guvner So, basically this?

Code:
r=100 + (a.def * 4 + a.mdf * 4 - b.def * 2); a.friendsUnit().aliveMembers().forEach(friend => friend.gainHp(friend.hp * 0.2)); r

EDIT: Tried this as is- got an error "Unexpected token =>"

Actually, this skill was going to be player only, so how would I use $gameParty in this case?
EDIT: Tried this as is- got an error "Unexpected token =>"

If you have an old version of MV, then use the code I put in the box titled "For old versions of MV"
@Aloe Guvner I am on 1.5.2

EDIT: The old version worked- thanks.

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-deals-damage-and-heals-user-by-a-percentage.100006/