MV Storing damage from overkill to use on another skill (Yanfly)

Hey all,

So my game features weakpoints that when destroyed give various effects. I was trying to achieve this with a state on the target that has this Buff/States code:

JavaScript:
<Custom Deselect Effect>
if (value >= target.hp) {
var overkill = value - target.hp;
$gameVariables.setValue(291, overkill);
}
</Custom Deselect Effect>

Which then gets used in another skill's damage formula via Force Skill:
(a.mhp * 0.4) + v[291]

For some reason it gives this error:
Code:
YEP_CoreEngine.js:1098 TypeError: Cannot read property 'clamp' of null
    at Game_Enemy.Game_BattlerBase.refresh (rpg_objects.js:2614)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_X_EquipRequirements.js:490)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_DamageCore.js:1210)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_BuffsStatesCore.js:1164)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_WeaponUnleash.js:505)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_AbsorptionBarrier.js:732)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_X_LimitedSkillUses.js:625)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_AutoPassiveStates.js:421)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_X_SelectionControl.js:804)
    at Game_Enemy.Game_BattlerBase.refresh (YEP_EnhancedTP.js:3427)

Is "value" not able to be used in this way? It seems like it is recognized when using it in other places from the same plugin.
Is "value" not able to be used in this way?
No - it's only in the two notetags right before and after damage.

Besides which, even if you still had value, referencing the target's hp in Deselect wouldn't be the right math since the damage has already been dealt and the hp clamped at 0.

Just stick that code in a Confirm effect.
@ATT_Turan That makes sense. But so far I can't get it to work. I started with that and tried a few things, including breaking it up:

Code:
<Custom Confirm Effect>
if (value >= target.hp) {
var vdam = value;
var overkill += vdam - target.hp;
}
</Custom Confirm Effect>
<Custom Conclude Effect>
$gameVariables.setValue(291, overkill);
</Custom Conclude Effect>

Always the same crash. I also tried this var vdam = parseFloat(value); in case it's somehow NaN? I had that issue before. But I'm not sure that command is recognized in a notetag.
Id assume you cant use += when declaring a variable. never tried it, but theres no value to add on to yet.

You cant use a variable declared in one notetag and use it in another like that. They dont persist. Why not set the gameVariable inside the confirm effect?
Your second example there couldn't work because variables you make in a notetag don't persist. So by the time you get to Conclude, there's no such thing as overkill.

Are you sure that you're killing a target with the skill that sets overkill before trying to use the one that references it?

Try changing the damage formula to:
Code:
(a.mhp * 0.4) + (v[291] ? v[291] : 0)
The new formula always seems to be adding 0 to the damage.

Are you sure that you're killing a target with the skill that sets overkill before trying to use the one that references it?

This is a good bet. The force action is happening immediately after a target is killed, so maybe RPG Maker is calculating the force action's damage early?

I guess I could try Skill Core, but that means I need to edit every damage skill in the game...

Edit: I just did this...

Code:
<Custom Confirm Effect>
$gameVariables.setValue(291, 9999);
</Custom Confirm Effect>

... and it's still adding 0 to the damage. So this must get run at the wrong time to affect the force skill.
The new formula always seems to be adding 0 to the damage.
Oh, because I'm dumb and neither you nor Robro double checked me 🤣

Confirm goes on an attacker's state. It should be React.

Code:
<Custom React Effect>
if (value >= target.hp)
    $gameVariables.setValue(291, value - target.hp);
</Custom React Effect>
Oh, because I'm dumb and neither you nor Robro double checked me 🤣
Yknow, I did notice that. but after the first reply i thought he readjusted everything to support it 😛
@Robro33 That will teach you to presume that anyone is smarter than my stupidity!
Oh, because I'm dumb and neither you nor Robro double checked me 🤣

Confirm goes on an attacker's state. It should be React.
You know, I guess I never read closely enough to realize some of those should go on the attacker and some on the defender... despite the "Quick Reference" section that's clearly in the plugin :hswt:

So the new formula works! But now I'm racking my brain trying to figure out how to get it to accumulate from multi hits (which is why I tried the +=). I'll post again if I figure something out. I know I need two game variables... but looping on each React is throwing me off.
But now I'm racking my brain trying to figure out how to get it to accumulate from multi hits...I know I need two game variables... but looping on each React is throwing me off.
You don't need two variables, nor any kind of looping. Just add the existing value of the variable into what you're setting the new value to.

Code:
<Custom React Effect>
if (value >= target.hp)
    $gameVariables.setValue(291, $gameVariables.value(291) + value - target.hp);
</Custom React Effect>

At some point, you're going to need to reset it to 0 (unless it's supposed to keep building for the entire game), but I don't know when you intend that to happen.
You don't need two variables, nor any kind of looping. Just add the existing value of the variable into what you're setting the new value to.
Dangit I've seen this kind of trick a hundred times and I didn't try it! I guess it's just... weird to change a variable with itself? One day I'll remember basic coding things, lol ;_;
At some point, you're going to need to reset it to 0 (unless it's supposed to keep building for the entire game), but I don't know when you intend that to happen.
Yeah, I shoved a "change variable 291 = 0" into an action sequence for those force action skills to perform as a finish action. Seems like an acceptable solution since I don't have that many force actions to change.

Thank for your wisdom and patience as always!

EDIT:

For posterity, the action sequence looks like this:
Code:
<setup action>
display action
</setup action>
<finish action>
change variable 291 = 0
clear battle log
</finish action>

The "setup action" part is needed to prevent the enemy from surviving on 0 hp when killed by a force action. Wacky things happen when skills are queued up too fast 🙄 The "display action" and "clear battle log" are for consistency of skill messages at the top.

ANOTHER EDIT:

Again, just for posterity, posting the final formula.

The above Custom React works perfectly if trying to push strictly overkill damage to a target. However, the odd way my game works made me realize I want to transfer over the effort put into the first target as well (since the idea is that you are hitting an enemy's weakpoint). So now the formula I have is this:

Code:
<Custom React Effect>
if (value >= target.hp && target.hp>0) {
$gameVariables.setValue(291, value - target.hp + target.mhp);
}
else if (value >= target.hp) {
    $gameVariables.setValue(291, $gameVariables.value(291) + value);
}
</Custom React Effect>

The first part grabs the health of the target and stores it first, along with however much damage the first hit did minus the remaining health. This only happens while the target is alive when the blow kills them, so it accounts for one-hit kills, multi-hit kills, and multi-turn kills.

The second part traps any subsequent hits after the target is dead and adds it to the overkill damage. Since it only gets run when the target is dead, there is no need to subtract their current hp.

Original thread: https://forums.rpgmakerweb.com/threads/storing-damage-from-overkill-to-use-on-another-skill-yanfly.172017/