Script that returns the Id of the actor that is being targeted by an enemy

Is there a script that returns the Id the actor that is being targeted (will be attacked) by an enemy?
I have the following action sequence for an enemy skill, but it is not working :

if BattleManager._action._targetIndex == 0
motion sleep: target
end
Is there a script that returns the Id the actor that is being targeted (will be attacked) by an enemy?
I have the following action sequence for an enemy skill, but it is not working :

if BattleManager._action._targetIndex == 0
motion sleep: target
end
if targets[0].isActor() && targets[0]._actorId == 2
//code
end
if targets[0].isActor() && targets[0]._actorId == 2
//code
end
It works, Thank you!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/script-that-returns-the-id-of-the-actor-that-is-being-targeted-by-an-enemy.104509/