Calculate Counter Chance based on attacker CNT vs target CNT?

Specifically, the section I want to change is this, line 591 to 600 in Scene_Battle:
Code:
#--------------------------------------------------------------------------
# * Invoke Skill/Item
#--------------------------------------------------------------------------
  def invoke_item(target, item)
    if rand < target.item_cnt(@subject, item) # <--- THIS LINE
      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

I want to change that "target.item_cnt" to be the target's cnt vs the atacker's cnt. (target cnt - attacker cnt.)

I'm pretty sure no rounding when the number is negative is necessary, as rand is positive, so even -100% results in no counter.

Any idea as to how I would go about doing this? How would I add the attacker's CNT into this?


If this involves an external script, it must be compatible with: Most Yanfly scripts, Fomar0153's ATB system, and Victor Core.

Not sure if this would help, but here's an example of an incompatible script of similar purpose (no battle animations play, which is vital for Galv's Timed Button Attacks): Hamedo: Improve Counter Attack
The one that needs to change is not that line, but the one in Game_Battler. This located in Game_Battler at line 458
Code:
class Game_Battler
 def item_cnt(user, item)
    return 0 unless item.physical?     
    return 0 unless opposite?(user)   
    return cnt - user.cnt # <-- changed this
  end
end
It should be compatible with most of scripts you mentioned above, unless.... when it's not
The one that needs to change is not that line, but the one in Game_Battler. This located in Game_Battler at line 458
Code:
class Game_Battler
 def item_cnt(user, item)
    return 0 unless item.physical?   
    return 0 unless opposite?(user) 
    return cnt - user.cnt # <-- changed this
  end
end
It should be compatible with most of scripts you mentioned above, unless.... when it's not
Thanks a lot! It works perfectly! 🙂

Issue has been resolved.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/calculate-counter-chance-based-on-attacker-cnt-vs-target-cnt.91479/