MV How can I make an enemy flee using their troop ID through a common event?

I have the troop ID stored into a variable but I can't seem to find a way to force it to leave.

A skill is used on enemy (done)-> Common event is triggered through skill (done) -> Skill grabs the enemy ID (done) -> Plays a scene with enemy (done)-> Enemy leaves (not done)
Are you sure you got the correct number?

Because enemy ID is the wrong number for fleeing.

There is enemy ID which identifies the type of enemy from the enemy database.
There is troop ID which identifies which troop of the troop database you have.
and there is enemy index, which gives the index number of the enemy in the troop array.

The last one is the only one that can make an enemy flee, because the IDs do not identify the enemy inside the troop but the base object in the database.
Are you sure you got the correct number?

Because enemy ID is the wrong number for fleeing.

There is enemy ID which identifies the type of enemy from the enemy database.
There is troop ID which identifies which troop of the troop database you have.
and there is enemy index, which gives the index number of the enemy in the troop array.

The last one is the only one that can make an enemy flee, because the IDs do not identify the enemy inside the troop but the base object in the database.
Yep I got the correct troop ID.

Is there an option using it's ID to make an enemy flee that I completely missed? I could not find an option or any related code for it.
please show us a screenshot of what exactly you are doing.

And please, use the correct names - saying you have a troop ID means you have the wrong number, because you need the index and not an ID.
please show us a screenshot of what exactly you are doing.

And please, use the correct names - saying you have a troop ID means you have the wrong number, because you need the index and not an ID.
Apologies, I appreciate the help and I will be more specific!

The skill targets an enemy and triggers a common event, I believe the enemy targeted by the skill can be referenced using 'BattleManager.actor()._lastTargetIndex', correct me if I'm wrong.

Using that, how can I make the targeted enemy disappear from the battle via common event?
BattleManager.actor() gets the actor currently receiving input. Instead, consider BattleManager._subject: the subject currently performing an action.

To make the enemy flee, here are a couple of options (untested):
  1. Directly make the enemy escape, e.g. in a Script command in a common event:
    JavaScript:
    $gameTroop.members()[BattleManager._subject._lastTargetIndex].escape();

  2. Force the enemy to use a "Flee" skill, e.g. in a Script command in a common event:
    JavaScript:
    var subject = $gameTroop.members()[BattleManager._subject._lastTargetIndex];
    subject.forceAction(123, -1);
    BattleManager.forceAction(subject);
    this.setWaitMode("action");
    Replace 123 with the ID of the "Flee" skill. This skill should have Scope: User and apply an Escape effect.
BattleManager.actor() gets the actor currently receiving input. Instead, consider BattleManager._subject: the subject currently performing an action.

To make the enemy flee, here are a couple of options (untested):
  1. Directly make the enemy escape, e.g. in a Script command in a common event:
    JavaScript:
    $gameTroop.members()[BattleManager._subject._lastTargetIndex].escape();

  2. Force the enemy to use a "Flee" skill, e.g. in a Script command in a common event:
    JavaScript:
    var subject = $gameTroop.members()[BattleManager._subject._lastTargetIndex];
    subject.forceAction(123, -1);
    BattleManager.forceAction(subject);
    this.setWaitMode("action");
    Replace 123 with the ID of the "Flee" skill. This skill should have Scope: User and apply an Escape effect.
Both work perfectly, thank you so much 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-make-an-enemy-flee-using-their-troop-id-through-a-common-event.155116/