Apply State to User if User Kills an Enemy.

The idea is a kill skill, when the actor kills an enemy they gain a buff for a few turns.

The conditions are: User has state(x), state(x) has attack state (y), if an enemy dies with state (y) by the user with state (x) then the user gains state (z).

I'm unsure if there is a scripting method to avoid having to check for state (y) or not or if it can be achieved via Yanfly's buffs and states core through lunatic scripting methods.
state(x) has attack state (y), if an enemy dies with state (y) by the user with state (x) then the user gains state (z).
is state y a requirement, or is that just something you tried to implement it? if all you wanted to do was track if an a battler killed another battler while a state was active on the attacker and then give them a state as a reward, you do something like this

Code:
<Custom Initiate Effect>
if (this.isForOpponent() && this.isDamage() && target.hp>0)
  user._killcheck = true;
</Custom Initiate Effect>

<Custom Conclude Effect>
if (target.hp == 0 && user._killcheck) 
  user.addState(z);
delete user._killcheck;
</Custom Conclude Effect>
state(x) has attack state (y), if an enemy dies with state (y) by the user with state (x) then the user gains state (z).
Put into the notetags for state y:
Code:
<Custom Respond Effect>
if (target.hp <= 0 && user == origin)
    user.addState(z);
</Custom Respond Effect>
where z is the ID of the state, no leading zeros.

@Robro33 I'm curious what the point is of your Initiate Effect. Under what circumstance could you perform an action and the target has 0 HP except that you killed them?
I'm curious what the point is of your Initiate Effect. Under what circumstance could you perform an action and the target has 0 HP except that you killed them?
its a bit of a convention i started following in my project at some point. multihit skills and enemies that were resistant to death would trigger the effects multiple times, so i started doing that to catch it
Thank you both. I plugged in @ATT_Turan 's method, which worked but wouldn't trigger if an enemy was one-shot killed. However, @Robro33 's method seems to be working without a hitch!

Originally I worried I'd have to consider the Kill Skill state being triggered if an ally killed an enemy after the user did. But with either method, it seems that's not an issue. It seems I only need state (x) and state (z)! Much easier.
worked but wouldn't trigger if an enemy was one-shot killed.
That's weird, there's nothing in my notetag's code that would know whether the target started at full health or not. So long as the state has been applied from a previous attack, it should work fine.

Robro's code doesn't check for your state y to have been applied at all.

Perhaps that's what you're talking about - you want to account for the possibility that one attack both applies state y and kills the enemy, but you can't. Attack State effects happen at the end of the attack, and dead targets can't get states added to them.
Yes, I think that was the issue. I assumed I had to apply a state, but your methods negate it being needed at all. I assume maybe using state (y) could maybe have it's applications for poison? Perhaps that'd be it's own can of worms.
I added it to another test state as:
<Custom Action End Effect>
if (target.hp <= 0 && user == origin)
user.addState(187);
</Custom Action End Effect>

worked like a charm~
Attack State effects happen at the end of the attack, and dead targets can't get states added to them.
If you have Yanfly's State Categories plugin, you could use <Category: Bypass Death Removal> on the state, which would allow it to be applied to dead targets.
If you have Yanfly's State Categories plugin, you could use <Category: Bypass Death Removal> on the state, which would allow it to be applied to dead targets.
True enough. And apparently the action end is after all the effects but while the target hasn't been flagged as dead, yet. Which I didn't think would work, but the OP says it's good for them so yay.

Original thread: https://forums.rpgmakerweb.com/threads/apply-state-to-user-if-user-kills-an-enemy.169318/