check which enemy has state?

Basically I just need to know the script for looping through every enemy until I find the one with the state and then return its id. I know I've seen this done before but I can NOT remember how.

**EDIT** Actually, if anyone knows how to store the id of a skill's target that'd work just as well. I thought it would be something simple like $game_variables[x] = b? (I've also seen b.id) but neither seem to work? if that's correct though let me know.
To get the first enemy with that state, use:
Ruby:
enemy = $game_troop.members.find {|m| m.state?(STATE_ID)}

Alternatively, for every enemy with that state, use:
Ruby:
$game_troop.members.select {|m| m.state?(STATE_ID)}.each do |enemy|
    # do stuff here
end

Untested but it should work.

You should just be able to store the enemy using $game_variables[x] = b in the damage formula. How are you using it after it's stored?
To get the first enemy with that state, use:
Ruby:
enemy = $game_troop.members.find {|m| m.state?(STATE_ID)}

Alternatively, for every enemy with that state, use:
Ruby:
$game_troop.members.select {|m| m.state?(STATE_ID)}.each do |enemy|
    # do stuff here
end

Untested but it should work.

You should just be able to store the enemy using $game_variables[x] = b in the damage formula. How are you using it after it's stored?

Oh shoot I forgot I to check on this, sorry for the late response lol. Come to find out I was doing something else wrong on my event that SEEMED like it wasn't taking the id, but it was.

"$game_variables[x] = b" worked just fine.

But thank you very much for this! I'm still trying to learn and this is very helpful!

Original thread: https://forums.rpgmakerweb.com/threads/check-which-enemy-has-state.127917/