HP Drain - Skills

Hello,
I would like to understand how the HP drain option works in the skill section. How can I create a standard move that deals, for example, 100 damage and heals the user for half of the damage inflicted on enemies?
I've searched within the forum threads for similar topics, but I'm having trouble understanding it well.
Some have used specific formulas like: c = 10; a.gainHp(c / 4); c

¯_(ツ)_/¯
An HP Drain skill will heal the user for the total damage inflicted, by default.

If you wanted half the damage healed, you could do

JavaScript:
const damage = 100; a.gainHp(Math.ceil(damage / 2)); damage

That will define a variable called damage with a value of 100, heal the user for half the damage dealt rounded up, and use damage as the final calculated damage value.
Some have used specific formulas like: c = 10; a.gainHp(c / 4); c
in the damage formula box, the damage dealt is whatever expression is after the last semicolon if there is anything past it. all the code of the formula gets ran, but only the last bit becomes the damage calc.

Because of that, youre able to have your formula (10, but can be anything), save it into a variable (c), call the gainHp() method in order to heal the attacker based on the value of your formula-variable, and then have the last section just be the variable to make sure that thats what the damage calc uses.
Thanks to both of you, I think I understand more now.

If I may ask, is there some collection/archive of basic skills here on the forum or elsewhere? Because for my video game, I would like to be able to create fairly common skills as a start, and having a collection of them would be useful to me.
Thanks to both of you, I think I understand more now.

If I may ask, is there some collection/archive of basic skills here on the forum or elsewhere? Because for my video game, I would like to be able to create fairly common skills as a start, and having a collection of them would be useful to me.
There's a topic kicking about somewhere with a series of templated damage formulae for achieving various things.
There's a topic kicking about somewhere with a series of templated damage formulae for achieving various things.
Where I can find it?
On these forums somewhere. You have access to the same search tools I do. 😛
On these forums somewhere. You have access to the same search tools I do. 😛

I think I've found it, thank you!
I think I've found it, thank you!
not exactly - that is the tutorial but not the example collection
and there is one for each maker as different makers use different code/language

Original thread: https://forums.rpgmakerweb.com/threads/hp-drain-skills.164725/