MZ Change HP of Targetted Enemy

I need a very basic script call
where I

Decrease HP/Knockout of [Variable Enemy]

So if Variable = 5
Then Enemy number 5 is going to have his HP Decreased by specific damage or knocked out
You may find these useful:

You may find these useful:

I used damage formula to put some stats into variable.
but for this part I couldn't unfortunently

I want to use a common event to reduce "last enemy target" hp
not in damage formula. Hope you can help suggest some thing
In a Script command:
JavaScript:
// Get value of variable 123
const index = $gameVariables.value(123);
// Get the enemy in the position equal to that value
const enemy = $gameTroop.members()[index];
// Do 50 damage to that enemy
enemy.gainHp(-50);
// Add state ID 1 to that enemy
enemy.addState(1);
Edit the values as appropriate for your situation~
In a Script command:
JavaScript:
// Get value of variable 123
const index = $gameVariables.value(123);
// Get the enemy in the position equal to that value
const enemy = $gameTroop.members()[index];
// Do 50 damage to that enemy
enemy.gainHp(-50);
// Add state ID 1 to that enemy
enemy.addState(1);
Edit the values as appropriate for your situation~
Thanks but for some reason This affects the first enemy index not the targetted variable
It stores the first enemy for some reasons

Original thread: https://forums.rpgmakerweb.com/threads/change-hp-of-targetted-enemy.157285/