Absorb Skill

So I did see a post on this but I'm mainly confused on what to do with the formula I saw...
Code:
x=a.mhp - a.hp; if b.hp <= x ;x=b.hp-1;end;a.hp+=x;x
I'm trying to just have a variance of 100 or the standard attack damage, but I'm new to formulas so I don't quite understand how it all works. I do know that a.mhp is the person using said skill's Max HP and b.hp is basically the Target's HP. The rest I don't understand so if I could have a little help with this, it would be appreciated!

(I should probably mention also that my goal here is to have the user steal an ally's HP, this would be handy for Bossfights like a Giant Slime fight where the Giant Slime can absorb it's allies HP to recover itself)
there is alot u can do with formulas alone.
https://www.rpgmakercentral.com/topic/36290-damage-formulas-101-mv-edition/
x=a.mhp - a.hp; - This sets a variable "x" to the amount of HP that the user is missing (which is a's Max HP minus a's Current HP)
if b.hp <= x ;x=b.hp-1;end; - This If - (do something) - End branch checks if the target's HP is less than "x" (the amount of HP that would be stolen), and if so, sets x to one less than the target's HP; this is done so that this move will not kill an ally
a.hp+=x; - The user gains "x" HP
x - The last value to be returned by the formula is the amount of damage (or healing) it will do before adjustments like Variance and Element Rates. Here, it's being set to x (the value calculated earlier)

Therefore, you'd want to use this damage formula on a Single Ally-targeted skill, and hopefully you have some way to prevent the user from targeting themselves. Make sure you have 0 variance and no element on the skill, if you don't want any allies to be KO'ed by it. In theory, you could also make this an All Allies skill, since the effect when used on the user himself should be nil.

However, you could probably make this easier by simply using an "HP Drain" skill on an ally, and using a simple formula - or by working some magic with Yanfly's Skill Core.
NVMD. delete this post
x=a.mhp - a.hp; - This sets a variable "x" to the amount of HP that the user is missing (which is a's Max HP minus a's Current HP)
if b.hp <= x ;x=b.hp-1;end; - This If - (do something) - End branch checks if the target's HP is less than "x" (the amount of HP that would be stolen), and if so, sets x to one less than the target's HP; this is done so that this move will not kill an ally
a.hp+=x; - The user gains "x" HP
x - The last value to be returned by the formula is the amount of damage (or healing) it will do before adjustments like Variance and Element Rates. Here, it's being set to x (the value calculated earlier)

Therefore, you'd want to use this damage formula on a Single Ally-targeted skill, and hopefully you have some way to prevent the user from targeting themselves. Make sure you have 0 variance and no element on the skill, if you don't want any allies to be KO'ed by it. In theory, you could also make this an All Allies skill, since the effect when used on the user himself should be nil.

However, you could probably make this easier by simply using an "HP Drain" skill on an ally, and using a simple formula - or by working some magic with Yanfly's Skill Core.
The explanation helps a lot but im still getting 0s with Drain, is there a example I can see that would use a default attack? Still trying to wrap my head around it but I am getting what stuff does.
Where did you get that formula from? It's not Javascript syntax so it probably wasn't meant for MV. Using as-is will cause a syntax error, and when there's a syntax error in the damage formula it will default to zero instead.

I'm not sure if damage formula errors are logged to the console (press F8 or F12 during playtest), but it would be smart if they were logged.

Try this version, which is written with Javascript syntax.
Code:
var x = a.mhp - a.hp; if (b.hp <= x) {x = b.hp-1;} a.hp += x; x
Where did you get that formula from? It's not Javascript syntax so it probably wasn't meant for MV. Using as-is will cause a syntax error, and when there's a syntax error in the damage formula it will default to zero instead.

I'm not sure if damage formula errors are logged to the console (press F8 or F12 during playtest), but it would be smart if they were logged.

Try this version, which is written with Javascript syntax.
Code:
var x = a.mhp - a.hp; if (b.hp <= x) {x = b.hp-1;} a.hp += x; x
Thank you! I was wondering why it wasn't working, it seemed fine the way it looked but glad you caught the mistake! Many Thanks!
Great catch, @Aloe Guvner!

Yeah, the syntax was correct Ruby syntax but you were using it in JavaScript-powered RPG Maker MV, which is why it was erroring out and returning 0.
Makes sense, I haven't worked with Ruby or the earlier versions of RPG Maker but makes sense it was probably from a thread about VX or VXAce.
So I did see a post on this but I'm mainly confused on what to do with the formula I saw...
Code:
x=a.mhp - a.hp; if b.hp <= x ;x=b.hp-1;end;a.hp+=x;x
I'm trying to just have a variance of 100 or the standard attack damage, but I'm new to formulas so I don't quite understand how it all works. I do know that a.mhp is the person using said skill's Max HP and b.hp is basically the Target's HP. The rest I don't understand so if I could have a little help with this, it would be appreciated!

(I should probably mention also that my goal here is to have the user steal an ally's HP, this would be handy for Bossfights like a Giant Slime fight where the Giant Slime can absorb it's allies HP to recover itself)

I wonder which Absorb & Osmose equations would be best.
Necro-post notice: @Abashi76

Original thread: https://forums.rpgmakerweb.com/threads/absorb-skill.113438/