Action Sequence on defeating an enemy

Here's what I want to pull of:

When a specific enemy is beaten a premade action sequence will play. I would like to create it using Yanflys Action Sequence Packs and it should involve the party member who dealt the finishing blow. This last part is where I am stuck.

My first thought was forcing the enemy to use a skill when its HP reach Zero via Battle Event and Force Action Command, but how do I make it target the one who killed it?

I feel like it would be better to link this to the party members action somehow, but I have no idea how I could do that.

I am using most of Yanflys Battle related Plugins as well as Irinas Action Sequence Impact.

Other thoughts I had involved playing around with counter skills or follow up skills, but I wasn't able to come up with something yet ...

Any ideas?
You need to be storing the value of the last actor to attack so you can grab that value when the enemy dies. The engine may well store that information itself somewhere, but I'm not sure where. So, off the top of my head, the easiest way to collect the index ID of the most recent actor to attack would be using Yanfly Buffs and States Core and Auto Passive States to put a passive state on all your actors. In that state, place the following timing effect Note Tag:

Code:
<Custom Action Start>
  $gameVariables.setValue(x, target.index());
</Custom Action Start>

Replace "x" with the variable number you want to store the index ID of the last actor to take an action. This will basically put a passive state on all the actors, and at the start of each of the actor's actions, it will store the index ID of that actor.

Then, on the Troop Event page that activates when the particular enemy hits 0 hp... first of all, you may have to use "Change Enemy State" to remove the "Dead" state and use "Enemy Recover" to restore at least 1 HP. (Not sure if this is necessary; it may do the "forced action" even if it's dead, but this step makes sure it's still "alive," just in case it doesn't process forced actions in the "dead" state.)

Then, on the same Troop Event page, use the following script call to the Force Action command, using the stored id of the last actor:

JavaScript:
var targetIndex = $gameVariables.value(x);
$gameTroop.members()[y].forceAction(z, targetIndex);
BattleManager.forceAction($gameTroop.members()[y]);

Where "x" is the Variable Number you used to store the last actor's index in the state's timing effect;
"y" is the index of the enemy that needs to use the forced action;
and "z" is the skill Id number of the skill the enemy is being forced to use.

Finally, if the enemy is supposed to die afterward, finish the Troop Event page by reducing the enemy's HP back to 0, which should automatically re-inflict the "dead" state. (If not, manually re-add the "dead" state, too.)

I haven't tested this, but I think it should work...

ETA: Sorry, I speed-read and missed this part:

I feel like it would be better to link this to the party members action somehow, but I have no idea how I could do that.

To have the Forced Action be performed BY the actor who killed the enemy instead of ON the actor BY the enemy, it's basically the same thing, you would just change the Forced Action script call in the Troop Event page to something like this:

JavaScript:
var index = $gameVariables.value(x);
$gameParty.members()[index].forceAction(z, -2);
BattleManager.forceAction($gameParty.members()[index]);

This will have the actor do the forced action on the enemy.
Worked perfectly! Thank you! Even simple script calls are still like magic to me and I can't do much more than copy & paste

I ended up using the second option, but it doesn't really matter who's the user and who's the target in the end, since both are controllable in the action sequence and it's just about the visuals in my case.

Also, just if someone else wants to try this: I had to change the State Notetag to:
<Custom Action Start Effect>

Again, thank you so much for the detailed description : )

Original thread: https://forums.rpgmakerweb.com/threads/action-sequence-on-defeating-an-enemy.134776/