Subject Actor and Subject Enemy Problem

Is there a way to change the subject as not the actor? This is because I want to create an auto cast skill whenever the turn ends. Somehow, when I use the troops, the damage is still given to me, instead to the enemy. Here's my code:

Code:
class Scene_Battle < Scene_Base  alias milena_cast_skill_turn_end turn_end  def turn_end    milena_cast_skill_turn_end     $game_troop.members.each do |player|      milena_cast_skill(player)    end  end     def milena_cast_skill(battler)    last_subject = @subject    @subject = battler    action = Game_Action.new(battler)    action.set_skill(8)    battler.actions.unshift(action)    use_item    battler.actions.shift    @subject = last_subject  end  end
What scope have you selected for skill 8?
The subject indicates the user of an action, so if you are using the default database entries I'd expect each enemy to firebreath the party.

If you are using the standard battle system you may have to pause the battle process while the actions are performed.
I have not selected a scope. I just set it to force activate. I am using the default battle system for this because I want it to be working with everything. What I have a problem is if I use:

def turn_end milena_cast_skill_turn_end $game_party.members.each do |player| milena_cast_skill(player) end end This works perfectly, it damages me. But if I use troops, the skill works but I was the one being damaged, not the enemy.
Mmm, did you test it using "Battle Test" and didn't save your project after modifying the script?

The targeting works fine when I test it (except that the game crashes if I choose a new action before the enemies are done with their actions).
I'll try to see what is wrong and let you know about its progress.

Original thread: https://forums.rpgmakerweb.com/threads/subject-actor-and-subject-enemy-problem.37768/