Make attacks have chance of targeting wrong enemy

As it says in title. Not just basic attacks, though, but all forms of damage. For example, let's say a 25% chance of each basic attack and skill to target an enemy other than the one the player selected.

I have looked through several targeting as well as passive skills scripts, and the closest I've come was with this state self-inflicted by a passive skill: 

KiTLS8h.png


but that state takes player input completely out of the equation, it just randomly targets enemies with basic attacks. It's like having the player on auto battle, which, I imagine, would be quite boring for the person sitting behind the screen.

I can't do it through skill scopes, either, because I would like it to be sort of like a state-inflicted thing, but based on chance, and that 'state' lasts through the entire battle. A script is probably necessary for this kind of effect.

Thank you in advance.
It may be a lot of work depending on the number of skills/attacks but you could do this using common events and a branching outcome based on a random variable. More or less anyway.
I don't think this is possible with eventing as the battle flow controls let me target a specific enemy (or set something as random). Either way, I'd be forcing the player to use a specific skill, and there's no way to detect if the player is using a certain skill.

troop conditions:

nn2bCMl.png


(below) there is no way to give a player a choice of skills to use.

F95cnt7.png
Hello.

Try this:

EDIT:

Code:
#------------------------------------------------------------------------------# Use <wrong_target: x%> in skills and items notebox# Example: <wrong_target: 50%>#--# Use <disable_wrong_target> to disable this feature# for a particular skill or item#--# Use <wrongt_chance: +x%> or -x% in equipments and states notebox# to increase or decrease the chance of targeting a wrong enemy#==============================================================================module Lecode_TargetWrongEn    Default_Chance = 25  For_Actors_Only = true  endclass Game_Action    alias lecode_twe_make_targets make_targets  def make_targets    return lecode_twe_make_targets if [email protected]? && Lecode_TargetWrongEn::For_Actors_Only    unless item.nil?      return make_target_wrong_enemy if rand(100) < chance_wrong_target    end    return lecode_twe_make_targets  end    def chance_wrong_target    return -1 if item.wrong_target_disabled?    val = item.chance_wrong_target    @subject.equips.each { |e| val += e.chance_wrong_target unless e.nil? } if @subject.actor?    @subject.states.each { |s| val += s.chance_wrong_target unless s.nil? }    return [val,0].max  end    def make_target_wrong_enemy    if item.for_dead_friend?      [friends_unit.random_dead_target]    elsif item.for_friend?      [friends_unit.random_target]    else      [opponents_unit.random_target]    end  end  endclass RPG::UsableItem    def wrong_target_disabled?    self.note =~/<disable_wrong_target>/i  end    def chance_wrong_target    self.note =~ /<wrong_target:[ ]?(.+)%>/i ? $1.to_i.abs :  Lecode_TargetWrongEn::Default_Chance  end  endclass RPG::State    def chance_wrong_target    self.note =~ /<wrongt_chance:[ ]?(.+)%>/i ? $1.to_i :  0  end  endclass RPG::EquipItem    def chance_wrong_target    self.note =~ /<wrongt_chance:[ ]?(.+)%>/i ? $1.to_i :  0  end  end
Thank you very much, Lecode! It works perfectly, and you wrote it so quickly xD makes scripting look easy, haha...

meanwhile I only have a meager understanding of Ruby and must rely on other's help... I've got a lot to learn

I'll credit you as your username, then. Thanks again~

Original thread: https://forums.rpgmakerweb.com/threads/make-attacks-have-chance-of-targeting-wrong-enemy.43573/