MV A state that counts a kill in battle?

I need that when a character with this state kills an enemy in battle (with an attack or skill, but not with an item), 1 is added to the counter of this state.

I tried to do something, but it didn't work out.
Code:
<Custom Conclude Effect>
if (!this.isItem && target.isActor() !== user.isActor() && target.isDead()) {
target.addStateCounter(stateId, 1);
target.clampStateCounter(stateId,0,100);
}
</Custom Conclude Effect>

I use YEP plugins (BuffsStatesCore; AutoPassiveStates)
Try changing your check to
Code:
 this.isDamage() && target.hp==0 && !target.isStateRestst(1)
If its relevant that the target must be an actor and the user is not, and the state winds up on actors too then add the other checks. But checking if the target's HP hit 0 and if theyre not immune to dying generally is enough. You might have to change that from a confirm effect to a conclude as well
Code:
!target.isStateRestst(1)
I think that ought to be stateResist

However, the bigger problem with the OP's code is they're trying to add and clamp the state counter on the target, not the user. So that would increment a counter on a state that the dead person had...

That should be user.addStateCounter and user.clampStateCounter
I think that ought to be stateResist

However, the bigger problem with the OP's code is they're trying to add and clamp the state counter on the target, not the user. So that would increment a counter on a state that the dead person had...

That should be user.addStateCounter and user.clampStateCounter
Oh my God! I didn't even notice it. Thanks!
Try changing your check to
Code:
 this.isDamage() && target.hp==0 && !target.isStateRestst(1)
If its relevant that the target must be an actor and the user is not, and the state winds up on actors too then add the other checks. But checking if the target's HP hit 0 and if theyre not immune to dying generally is enough. You might have to change that from a confirm effect to a conclude as well
And thank you! Everything is working now.
The one issue I could think of would be that if you have a multi-hit attack, every subsequent hit after killing the target would probably count as a separate kill with this setup.

If that is a concern you could maybe add
this.isHit() && ...
to the condition to check if the hit went through or use
this.isStateAdded(1)
to ensure the death state was actually added through this hit.
@Another Fen I don't think that would do it. The hits are actually hits - the target is made immortal at the beginning so it can take multiple hits.

You would have to use an earlier notetag to create a switch on the target; then, the conditional for recording a kill checks for the target to be dead and that switch is false. Then it increments the kill counter, turns the switch on, and all subsequent hits will be skipped.

The isStateAdded() might do it, but that might also persist through all hits of the skill. I haven't looked at the exact timing of when addedStates gets cleared.
Not sure if still relevant, from what I remember once the target is dead it should no longer be an eligible target for the remaining hits, so those would produce "unused" results but likely still trigger the reaction effects.

The result is cleared at the beginning of the hit, so there should not be anything bleeding over from hit to hit unless I'm missing something.
Not sure if still relevant, from what I remember once the target is dead it should no longer be an eligible target for the remaining hits
But (presuming the OP is using Yanfly's Battle Engine Core), the target is not dead from the first hit. The default action sequence applies an immortal state at the beginning of every skill.

So it will have 0 HP but be alive, and both hits are actually hits (incidentally, isHit() would be a property of the action result, not the skill 😉 ).

Using isStateAdded() (which, again, is a method of the result) won't work because the enemy doesn't get the death state added and actually die until they're refreshed after the action is over.

I believe the only(? or at least simplest) route is to use a switch.

Code:
<Custom Conclude Effect>
if (target.hp<=0 && !target.justDied)
{
    target.justDied = true;
    user.addStateCounter(stateId, 1);
    user.clampStateCounter(stateId,0,100);
}
</Custom Conclude Effect>
Ah, this makes a lot more sense then.

Assuming the target cannot be revived this sounds like a good solution (otherwise you could still reset the switch in a custom initate effect maybe).

Edit: In case someone needs this, the custom initiate effect could look like this:
Code:
<Custom Initiate Effect>
if (target.hp > 0) { target.justDied = false; }
</Custom Initiate Effect>

Original thread: https://forums.rpgmakerweb.com/threads/a-state-that-counts-a-kill-in-battle.163513/