Is it possible to assign an enemy's ID to a variable?

I'm new to RPG Maker MV and these forums, so sorry if I'm posting in the wrong place or doing something wrong.

I'm trying to create a Steal command for my game and the way I'm trying to make it work is:
1. Character uses the Steal skill during battle, which sets off a common event.
2. The common event takes the target enemy's ID and assigns it to a variable (for example, the default Bat enemy has the ID of 1 in the database, so the variable would be set to 1)
3. Conditional branches verify what the variable is set to and adds the specified items to the player's inventory with a chance of failure.
4. A state is added to the enemy to prevent the player from stealing from them again.

I know how to do everything except step 2, which is grabbing the target's ID and assigning it to a variable. What I'd like to know if it's possible to do that somehow, or something to a similar effect. It doesn't sound like something too crazy to I assume there's a way to do it without plugins or whatever else.

I've already done searches on Google and I don't really understand most of the posts, or the alternatives I found simply didn't work for me or were not what I'm looking for, which is why I'm making a new thread to ask for help.

Thanks in advance!
Okay, I think I have a concept. In the formula line for your Steal skill, you can probably go ahead and set a variable equal to the ID. I'm not quite sure how to structure that call, at this moment, however.
EDIT: Everything I tried returned a miss on the skill or a result of "0," so this will take greater expertise than I possess.
OK - I can't give you a solution but I can tell you the basics and where the problem lies.

When fighting, you are always fighting a troop - and the targets inside the troop are identified by troop index, a number from 1 to 8.
Because you could fight a troop with eight bats, and you would need to differ between those identical enemies, so the enemy ID cannot be used at that stage.

Inside the troop, each enemy battler has a property that stores the enemy ID for that battler.
You'll need the full script of that to access it because to my kn owledge it is not one of the values referenced through the shortcuts a or b - or at least it was that way with Ace, and the post above suggests it still is that way.

And only after you got that you can use whatever structure you thought of to handle the rest, for example loading the notetag from dataenemy or whatever.
@Andar just for reference, you could do something like
Code:
v[14]=b.enemyId(); v[22]=b.index();
But then you'd also need to include an actual damage formula/value at the end. I don't know what @pawsplay was trying, but that would work.

That being said: it's rather difficult to do this in the default engine.

I can't think of a way to do it in a common event, so you would have to either:
- put it in the damage formula (which is probably undesirable because then you're forced to make the skill do damage or hit for 0 every time you use it)

- or make your Steal skill apply a state to the target, then you have troop events that check every enemy to have that state and set the variable then remove the state. That's a lot of duplication and you'd have to duplicate it for every troop in your game.

If your breaking point is spending any money on plugins, you could do some of this with Yanfly's Skill Core, which is free. Give your skill the notetag:
Code:
<Post-Damage Eval>
$gameVariables.setValue(X, target.enemyId());
target.addState(Y);
</Post-Damage Eval>
where X and Y are the IDs of the variable and the state, no leading zeros.

But really I think you'd be way better off just using an existing Steal plugin. There are several if you Google them. Yanfly has one and there are also free alternatives.
I had just gotten as far as trying to plug enemyId into the damage formula, just to see if I could get it to cough up a number.
b.enemyId() still returns 0 for me every time, but I don't know if that is a value that JS will interpret as a number, so.
EDIT: removed distracting typo
b.enemyId(b) still returns 0 for me every time, but I don't know if that is a value that JS will interpret as a number
Why are you putting b in the parentheses?
@pawsplay the enemyId() method doesn't take any argument. It's just b.enemyId().
Code:
$gameVariables.setValue(13, b.enemyId()); console.log("Hitting enemy ID ", $gameVariables.value(13)); a.atk * 4 - b.def * 2
Screenshot 2023-07-10 123741.png

To be fair to your problems, I also got the formula erroring out to 0 when I tried to use v[13]=etc. I'm not sure why.
That was just a typo on my part. i did test it without an argument.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-assign-an-enemys-id-to-a-variable.159160/