A skill that heals on kill?

Essentially: let's say there's an enemy with 4000 HP. You use this skill on it and it does 2000 damage on the dot. You use it again, and it does 2000 damage again, this time killing the foe and healing 2000 of your own HP in the process. (possibly less if the foe didn't actually HAVE 2000 HP, but I'm not picky.)


Is this possible? And if so, how?
IF your skill is the ONLY thing that deals damage (they don't have poison or some other state that causes slip damage that could kill them after you've inflicted damage) AND your skill has a set amount of damage (no variance, no adjustment for element rates, etc) then you could do this in the damage formula:

Code:
a.hp += (b.hp <= 2000 ? b.hp : 0); 2000

That is saying increase the user's hp by the target's hp if the target has 2000 or less hp.  Regardless, do 2000 damage to the target.
Hmm... is that really the only way to do it in the base engine? Can damage formulae call on variables and such? Is it not possible to perhaps store the foe's current HP in a variable, do the damage calculations, check the foe's current HP, and if it's zero, heal the user's HP by that variable? Certainly complex, but if it's possible I'd like to run with it.


Failing that, do you suppose I might be more successful over in Plugin Support? I'll move this topic over there if necessary.
Have you tried what I gave you?  It does exactly what you requested.  You do not need a plugin, and you do not need a variable.  Both of those alternatives are more complicated, and not necessary.  


Please try my suggestion and then come back and ask for further help if that doesn't work (explaining why it doesn't work).
you could set a common event that:


-gets the character attack damage


-evaluates it against the target's HP


-then applies that value to target's HP, and if greater than target's HP, -value to character's HP.


you will need to get the attacking value first, to then evaluate it.


getting that value is your corner stone.


EDIT: just checked.


yes... you can do it.


check in common events, change variable, game data, actor's ATK.


get the ATK value, get the enemy's DEF and HP, evaluate, and set character's HP to HP + variable.


don't "heal" the actor, but set HP to value, with value being the result of the damage calculation, plus the actor's HP stored in another variable.
I think I took a wrong turn somewhere with your suggestion.


My step process was:


-get five variables: Oscar's Attack (this skill is unique to one character only anyway, so it works out), Oscar's level (it's used in the damage calculations), the Defense of Oscar's target, and the HP of Oscar's target (twice; one gets affected later down the road while one stays untouched. My intention was to use it for the healing aspect)


-multiply each of the three important variables to match up with the damage formula for the attack itself (a.atk * 6 + a.level * 10 - b.def * 2). Self-explanatory. (worth noting, I turned damage variance down to 0% for this attack to line things up right)


-make a new variable for Oscar's Damage. It's set to his adjusted Attack, plus his adjusted Level, minus his target's adjusted Defense.


-take the HP of Oscar's target and subtract it by Oscar's Damage. If the result is less than or equal to 0, change Oscar's HP by the second Oscar's Target's HP variable.


The obvious go-to issue would be that I don't know how to actually single out Oscar's target (as you can see, I'm defaulting to Target #1), but even if I go after Target #1, nothing happens. Oscar's not actually being healed. I threw in a text box to see if maybe the common event itself wasn't running, but it is. So it's either the targeting issue, the HP tally, or both. (it could possibly be the damage calculations happening before the common event here, but I'm using Yanfly's action sequence packs with the common event listed first, before the action effect. Unless that really makes no difference anyway, I don't think it could be that.)


How does it look on your end? Could you screenshot what it looks like? Maybe I just need to see it in action.

troubleshoot.png
I think the problem is that you're getting *Target 1* and not *Oscar's actual target*


you should get *"Battler Oscar"'s actual target*


you should pick up "Enemy number X" where X is defined by "The Battle Scene's active battler's last target" (the battle scene's active battler being Oscar, and his last target being a number from 1 to the size of the enemy party)


in Ace, it should be 

Code:
BattleManager.actor.last_target_index

but I don't remember the syntax for javascript.


shouldn't be hard to translate tho.


anyways, whatever the function, the result should be:


-get Oscar.


-get Oscar's parameters.


-get Oscar's target.


-get Oscar's target's index number.


-from Scene, get Enemy Number "Oscar's target's index number"


-from Actor "Enemy Number Oscar's target's index number", get parameters.


and, that, I'm not sure you can pull off with just plain variables.
just do this on your damage formula


x = your_damage_formula; a.hp += (b.hp <= x ? b.hp : 0); x

//or you might need to do

var x = your_damage_formula; a.hp += (b.hp <= x ? b.hp : 0); x






Take note though that this is based on just the damage formula of your skill, if your target has damage resistances set to it, this method doesn't put that into consideration

Original thread: https://forums.rpgmakerweb.com/threads/a-skill-that-heals-on-kill.73278/