How Do I Make Enemy Attack Anyone but Themselves?

I'm specifically talking about the Attack Anyone restriction you can apply to statuses, or the One Ally targeting on a skill. I want to make it so that an enemy under one of those can't target themselves for attack.

Like, for example there's a 1v1v1 fight between Player, Enemy A, and Enemy B. If Enemy A attacks, I want him to be able to target Player or B, but not himself.
Update
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Not Attack Self on Confusion ║  Version: 1.00     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║                                     ╠════════════════════╣
# ║ Remove subject from list of targets ║    05 Jan 2024     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: nil                                            ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Will remove subject from list of potential targets       ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║   Add note tag to state <not_attack_self>                ║
# ║   Subject will not attack self when inflicted with state ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 05 Jan 2024 - Script finished                     ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Free for all uses in RPG Maker except nudity             ║
# ╚══════════════════════════════════════════════════════════╝

class RPG::State < RPG::BaseItem

  attr_accessor :not_attack_self
 
  def not_attack_self
    init_not_attack_self if @not_attack_self.nil?
    return @not_attack_self
  end
 
  def init_not_attack_self
    @not_attack_self = @note =~ /<not_attack_self>/i ? true : false
  end
 
end

class Game_Action

  def confusion_target
    case subject.confusion_level
    when 1
      opponents_unit.random_target
    when 2
      if rand(2) == 0
        opponents_unit.random_target
      else
        if friends_unit.alive_members.size == 1 && (subject.states.any? { |st| st.not_attack_self })
          opponents_unit.random_target
        else
          sbj = friends_unit.random_target
          while sbj == subject && (subject.states.any? { |st| st.not_attack_self })
            sbj = friends_unit.random_target
          end
          return sbj
        end
      end
    else
      if friends_unit.alive_members.size == 1 && (subject.states.any? { |st| st.not_attack_self })
        opponents_unit.random_target
      else
        sbj = friends_unit.random_target
        while sbj == subject && (subject.states.any? { |st| st.not_attack_self })
          sbj = friends_unit.random_target
        end
        return sbj
      end
    end
  end
end
Script works. Thanks. Feel free to close the thread.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-enemy-attack-anyone-but-themselves.164467/