How can I determine an actor position with a "all enemies" attack?

So, here is the thing. I managed to understand how Yanfly Lunatic State works.
What I did is an state when I get damaged, I gain 1000 HP back.
The state I create make that when I get damaged, it store the ID of my actor in a variable. (Let's say its variable 36) and then it call a common event. In that common event, it make that the actor(variable 36) gain 1000 HP.
So far it work perfect. But then there's a problem, when 2 or more actors have the same state and get damaged at the same time with an "all enemies" attack, only the last one in the line will be affected by the lunatic state.

So the idea to fix this was to make that the variable 36 was the ID of actor 1. Then variable 37 is actor 2 and so. But I'm not sure how to make this. I tried this line:

Code:
$game_variables[36 + $game_party.members[index]] = self.id

but so far is not changing not a single variable.

(I'm sorry, I'm very dumb with script calls and coding)
What does your common event look like now?
I would have it setup with the variable conditioned to be an array and add the actor id to the array when the state is applied. Then in your Common event you can do a array.size script command to do the hp add for each entry.
$game_variables[36] = []
actor gets state $game_variables[36].push($game_actors[self.id])

recover 100 hp
$game_variables[36].each do |a|
$game_actors[a].hp += 1000
end

state removed
$game_variables[36].each_with_index do |a, i|
$game_variables[36].delete_at(i) if a == self.id
end

Not sure if all that will work or where it would go.
Thanks for your reply!
I might have explained what I'm doing better.

Here's what I'm doing step by step.

First, I'm using Yanfly Lunatic State, and using an state with the shock effect.

1655155130478.png


The Shock effect I made is "NUMINOUS" which just save the ID of the actor being hit in variable 36.

1655155187283.png

The Numinous state has 2 array in it "shock effect" one is "NUMINOUS", which is the one that store the ID of the actor in the variable 36.
Then it also call for the common event 121.

1655155308237.png


For last, there's the common event, that heal 1000 HP to the actor with the ID stored in variable 36.
(And there's a condition based in another script I'm using but is not important for this).


BEFORE:
1655155387743.png

As you see, both actors with 2000 HP, when using the same state, and being hit at the same time, only the last one will be healed by the state, as the variable 36 overwrite the last one inmediately.

AFTER:
1655155478607.png


The only other possible solution I could think of, is to change the whole base script to make it check for common events in order of attacks of something like that.

(I tried what you told me but I must be dumb cuz I'm not sure how should I implement it).
In your lunatic state change it to be
# set variable to array if 0
$game_variables[36] = [] if $game_variables[36] == 0
# add actor id to array
$game_variables[36].push(self.id)

then in the common event use the code I gave
Code:
recover 100 hp
$game_variables[36].each do |a|
$game_actors[a].hp += 1000
end

I don't know what the numinous in grave is. something else you are doing?

Not sure yet where to put the code to clear the array. Perhaps after the battle.
OMG! It worked! I love you so much!

I don't know what the numinous in grave is. something else you are doing?

I'm using a card game script that change the skills in the game for cards. Numinous is a card that heal you for 1000 HP and then it check if there's more copies of Numinous in your graveyard and heal you 500 for each copy.

I think I can mix what you teached my with a script call to check this and do the effect. Any ways this helped me for several other cards that work similar. Thank you a lot!
Oh and we also need to put in the code to remove the actor when the state is removed.
Looks like Game_Battler
remove_state
so we need to do an alias of that method.
Ruby:
class Game_Battler
  alias r2_remove_numious_state_variable    remove_state
  def remove_state(state_id)
    if state_id == #whatever the state is for this
      $game_variables[36].each_with_index do |a, i|
        $game_variables[36].delete_at(i) if a == actor.id
      end
    end
    r2_remove_numious_state_variable
  end
end
not entirely sure that will work.
Oh yeah, cuz the ID of the actor is still stored in the array right? Yeah, I was testing and for some reason if I got hit again when I have the state, it heal me 1000 more (2000) I suppose it was for this reason.

I'm sorry but where should I put that code? Should I create it like a new script below lunatic state?
like a new script below lunatic state?
yes, but you should also look in your game if there are any other references to remove_state.
ctrl+shift+F
Umm... I must be doing something stupidly wrong, but I'm not sure what:

1655162975104.png

1655162994967.png
you didn't remove all the text
whatever the state is for this <- that whole line needed to be changed to the state id.
Yeah, as I suppose, I was doing something stupidly wrong hahaha. Thanks for all your help! You're awesome.
So... I went back from work and tried it with fixing my error.
It doesn't give me an error anymore, but the array still has the ID of the actors. (I checked this with a script call)

As I say I'm not a scripter, so I can't get to see the problem in your code. For most part as I understood, your script check if the state I made is removed from an actor, then delete any number in that variable(36) array that it's equal to any actor with such id. Right?
I would really need your project to test (so I don't have to recreate it)
But I assumed that the remove state method would take the actor out of the array when the state was removed.
And I didn't give you anything yet to clear the variable array when the battle is over, assuming the states are removed at the end of battle and are not persistent.

But if you have custom battle scripts or your not doing a standard battle, then things could be a little different.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-determine-an-actor-position-with-a-all-enemies-attack.148490/