MV Confusion about Yanfly Respond Effects

Hey folks,

So, I'm quite stumped about a specific state atm. It's a bleed state that has both a duration and state counters, and what I'm trying to do atm is to make it so when the enemy with the state dies, the character that applies the state gains TP. Here's the last iteration of the notetags I've tried:
Spoiler: Code
JavaScript:
<Reapply Ignore Turns>

<Custom Regenerate Effect>
var bleed = target.getStateCounter(56);
if (bleed >= target.hp) {
$gameActors.actor(4).gainTp(Math.floor(bleed / 2));
$gameActors.actor(4).startAnimation(160);
}
target.gainHp(-bleed);
target.startAnimation(155);
</Custom Regenerate Effect>


<Custom Respond Effect>

if (target.hp <= 0) {
$gameActors.actor(4).gainTp(target.getStateCounter(56) / 2);
$gameActors.actor(4).startAnimation(160);
}
</Custom Respond Effect>




<Custom Deselect Effect>

if (target.hp <= 0) {
$gameActors.actor(4).gainTp(target.getStateCounter(56) / 2);
$gameActors.actor(4).startAnimation(160);
}
</Custom Deselect Effect>

However, neither the respond effect nor the deselect effect works when killed through an ability that deals damage the usual way. My first thought was that, because the target dies, it is no longer the target and/or the state is removed and so the respond and deselect effects do not trigger. I tested this by putting console.log(target) in both notetags and there was nothing on the console which I assume supports my theory of what's going on.

But here's where it gets confusing/interesting for me. While some of the abilities in my project deal damage through the usual way, some more complex ones deal their damage through script, using the gainHp function. And when I tested an ability that works through that function, the respond effect once again did not work. However, the deselect effect did. I tested with console.log(target) once again and the response effect wrote no target to the console when killed through gainHp function, but the deselect effect did. And this is where I'm quite confused.


As it stands, I can make the state work through the deselect effect IF the enemy is killed through the gainHp function. But I can't make it work at all if it is killed the usual way. And so, I'm here to see if anyone can elucidate me on what's going on here, and how I can actually make this work.
I've used this Plugin a lot, but I have little knowledge of the JS side of things.... BUT, I do know that the proper place for the script is in the states LEAVE or REMOVE Notetag. Respond is for something like a protect state where if the victim is attacked then the state will RESPOND to the attack. Sorry i described React not RESPOND... RESOND is after you select a target for the state.

I don't use the DESELECT note at all but I'm pretty sure its not going to work here. It's only for when you are selecting a target for the state from what I remember.
My first thought was that, because the target dies, the state is removed and so the respond and deselect effects do not trigger.
Possibly? do you happen to not be using yanfly's battle engine core? usually when you do, it adds an immortality effect to prevent targets from dying till the skill fully resolves. without it, it might be possible to get the states cleared by death before associated evals can run. id have to check it out. i dont know offhand.

And when I tested an ability that works through that function, the respond effect once again did not work. However, the deselect effect did. I tested with console.log(target) once again and the response effect wrote no target to the console when killed through gainHp function, but the deselect effect did. And this is where I'm quite confused.
deselect and respond hook into different functions. deselect runs when the action is applied while respond is ran when the action's damage is executed. its why deselect and confirm require the skill to hit the target to run - because damage isnt executed with a miss.
if the skills dont have a damage type, they shouldnt be able to trigger respond effects as they dont execute damage.

I don't use the DESELECT note at all but I'm pretty sure its not going to work here. It's only for when you are selecting a target for the state from what I remember.
deselect is an effect that runs when the battler with the state is the target of an action. its the last effect within the set to run. youre thinking of either conclude or initiate

Respond is for something like a protect state where if the victim is attacked then the state will RESPOND to the attack. Sorry i described React not RESPOND... RESOND is after you select a target for the state.
both are the result of being hit, but react happens pre damage execution while respond is post. so if you wanted to do something like reduce incoming damage by a certain amount, only one of those tags could do it.
@Robro33

I do have battle engine core, and as far as I know, it is required for the BuffStateCore to work as well. If that does add an immortality check (which makes sense) then I have no idea why I'm having this issue.

The interesting thing is, deselect only works on the ability that deals its damage through gainHp function and not the one that does it normally while respond works with neither. Which is strange to me because the ability that deals its damage normally does have a damage type and a damage formula that is bog-standard.
and as far as I know, it is required for the BuffStateCore to work as well
it can be used alone, but im not sure if many people do 🤣
its not listed as a requirement on the site and the plugin's introduction section has an instruction for placement *if* youre using the battle engine core.

The interesting thing is, deselect only works on the ability that deals its damage through gainHp function and not the one that does it normally while respond works with neither. Which is strange to me because the ability that deals its damage normally does have a damage type and a damage formula that is bog-standard.
lets start with some basic steps then. provide screenshots of your plugin manager so we can see the load order.
After testing more abilities to see what works and what doesn't, I believe I have figured out the problem. It is indeed because the target is dying before the respond effect can take place and as you said @Robro33 the battleEngine does have immortal state applied however the abilities I was testing before were using Action Sequences and apparently Action Sequences does overwrite that immortal state. When I tested the same without using Action Sequences, everything worked as intended. So I think what I need to do is manually apply immortal state inside the Action Sequence that I have and that should fix it.
I was testing before were using Action Sequences and apparently Action Sequences does overwrite that immortal state. When I tested the same without using Action Sequences, everything worked as intended. So I think what I need to do is manually apply immortal state inside the Action Sequence that I have and that should fix it.
yeah, the battle engine provides default action sequences for each skill and the action sequence plugins gives you more control over what your skills use. any sequence you set up replaces the default one, and the default <setup action> makes targets immortal. add a IMMORTAL: TARGETS TRUE in the setup action. the default finish action removes it for you
@Robro33

Thanks, do I need to worry about sequencing, like having to remove the immortal state *before* damage is applied, or does it not matter as long as the state is removed at the end step?
removing immortality before the damage would cause the same issue you had before - the target not being immortal and losing their states by dying early. so long as you dont have custom finish actions, itll removed automatically by the default finish. if you do have custom finish actions then you need to add a line to remove immortality.
@Robro33

Adding an immortality state to my action sequences did not work. I'm thinking the whole action sequences runs before the respond effect, meaning the immortal state gets applied and removed before the respond effect can trigger.
share the entire action sequence to be certain. when it comes to that set of buffs and states core notetags, those state effects play with every action effect ran.

just to be sure, youve modified the right skill and you saved your project between tests, right?
Yes, I've saved between tests. And here's one of the Action Sequences:


Spoiler: Sequence
<setup action>

clear battle log

display action

immortal: targets true

jump user: 300, 20

move user: target, front, 20

wait for movement

motion thrust: user

motion wait: user



</setup action>



<target action>

action animation: target

action effect: target

add state 56: target

eval: target.addStateCounter(56,7)

add state 58: target

wait for animation

</target action action>
theres a comma in immortal: targets, true that i must have missed (even though i copied it from a place that had it 🤣).
theres a comma in immortal: targets, true that i must have missed (even though i copied it from a place that had it 🤣).
Yep, that did the trick! Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/confusion-about-yanfly-respond-effects.180774/