Hello,
Now, the problem is that when an enemy freezes more than one actor, only the last one affected gets the change.
This is an expected behavior related to how event calls work in battle.
When you cast a skill/item, it first applies its effects (like state addition, damage etc.) for each targets, and then, before proceeding with the next action, it checks if there are some events to call (common events and/or the troops events).
onadd: if self.is_a?(Game_Actor); $game_variables[101] = self.id;end
onadd: $game_temp.reserve_common_event(51)
By doing so, if you add the state to more than one targets, then event 51 will be called after all effects are done and V[101] will have the value of the last affected battler's id, leading to unwanted behavior.
The same goes for your onremove effects.
You might even observe that if the skill used was supposed to call another common event (say 40) and it adds a state calling common event 51, then only one of the two events will be called because the game only remembers a single common event to call.
Does anyone have advice on how to make sure the commands run for every relevant actor?
There are many ways to deal with it, I can't think of one that is truly satisfying, but here is a working solution:
Did you know that your variables could store something else than numbers? You can actually store anything, so you can also turn a variable into an array that will be updated whenever an actors get the state.
First of all, find a way to initialize your variable into an array, for instance in a setup event (called once per game), put the command:
Ruby:
$game_variables[101] = []
Put this in your notetags:
Code:
onadd: $game_variables[101].push(self.id) if self.actor
onadd: $game_temp.reserve_common_event(51)
Then, in your common event, you can do a loop on the array like this:
(note that I have not tested this code so feel free to say if something is not working)
Edit: before the end of the loop, don't forget to increase V[103] by 1 otherwise you get an infinite loop!