Enemy Counter Rate

Hey all,

I've been working on a game for a bit now, and one issue I continually run into is that occasionally the enemy the party is fighting will start counter attacking every single attack for about 3 turns.  I don't know what causes this or how to stop it.  The best forum topic I could find seemed to indicate that it was a part of the script, and I even know which part of the script.  However, I'm afraid of trying to change it without getting some advice from more experienced people since I don't want to break the game either.

The forum implied that the issue was In invoke skill/item, and the counter/magic counter portions.  I would greatly appreciate the help.

#--------------------------------------------------------------------------

  # * Invoke Skill/Item

  #--------------------------------------------------------------------------

  def invoke_item(target, item)

    if rand < target.item_cnt(@subject, item)

      invoke_counter_attack(target, item)

    elsif rand < target.item_mrf(@subject, item)

      invoke_magic_reflection(target, item)

    else

      apply_item_effects(apply_substitute(target, item), item)

    end

    @subject.last_target_index = target.index

  end

  #--------------------------------------------------------------------------

  # * Apply Skill/Item Effect

  #--------------------------------------------------------------------------

  def apply_item_effects(target, item)

    target.item_apply(@subject, item)

    refresh_status

    @log_window.display_action_results(target, item)

  end

  #--------------------------------------------------------------------------

  # * Invoke Counterattack

  #--------------------------------------------------------------------------

  def invoke_counter_attack(target, item)

    @log_window.display_counter(target, item)

    attack_skill = $data_skills[target.attack_skill_id]

    @subject.item_apply(target, attack_skill)

    refresh_status

    @log_window.display_action_results(@subject, attack_skill)

  end

  #--------------------------------------------------------------------------

  # * Invoke Magic Reflection

  #--------------------------------------------------------------------------

  def invoke_magic_reflection(target, item)

    @subject.magic_reflection = true

    @log_window.display_reflection(target, item)

    apply_item_effects(@subject, item)

    @subject.magic_reflection = false

  end

Original thread: https://forums.rpgmakerweb.com/threads/enemy-counter-rate.26098/