Weakness Stun

Hi there, I've been wanting to make hitting a weakness create the benefit. Like Persona 3 and 4, where hitting a weakness gives you another turn except I want to make the result of hitting a weakness a chance of stunning rather than an extra turn. I do have an Ace version of this and I'm hoping if anyone would be willing to convert it into an MV plugin. The code itself is short and I'd gladly appreciate a port~

Spoiler
((EDIT : I just saw you wanted the effect to be a CHANCE to stun upon hitting a weakness.  You can do this by changing the self.add_state(33) line to the following:


if rand(100) < 40 (or whatever percentage you want instead of 40)


self.add_state(33)


end
Code:
class Game_Battler < Game_BattlerBase  #--------------------------------------------------------------------------  # * Get Element Modifier for Skill/Item  #--------------------------------------------------------------------------  def item_element_rate(user, item)    if item.damage.element_id < 0      the_rate = (user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements))    else      the_rate = (element_rate(item.damage.element_id))    end    if the_rate > 1.0      self.add_state(33)    end    return the_rate  end end
Did you make that edit? seems a bit strange.


Anyways what does it mean for someone to be weak against something?
I just copied the code from the Ace topic. Came out weird I guess. And by weakness I mean if you use an attack that an enemy is weak against. For example you use Fire on Slime, Slime is weak to Fire therefore is afflicted with a state upon taking damage.
By default, when working with element rates, 100% means no change.


Anything higher than 100% means they take more damage.


Anything less than 100% means they take less damage.


Would this be the basis for weakness/strength? If the selected element rate is greater than 100%?


var TH_GameAction_calcElementRate = Game_Action.prototype.calcElementRate;
Game_Action.prototype.calcElementRate = function(target) {
var rate = TH_GameAction_calcElementRate.call(this, target);
if (rate > 1) {
target.addState( 30 )
}
return rate;
};


This is what the snippet you've provided is basically doing.
Would this be the basis for weakness/strength? If the selected element rate is greater than 100%?



No I didn't make the edit (I don't know why the code formatted itself that way...), but yes this would be the basis for weakness/ strength.
No I didn't make the edit (I don't know why the code formatted itself that way...), but yes this would be the basis for weakness/ strength.

The snippet I provided might do the trick.
Awesome, it does the job perfectly!~ Though how would I add a percentage chance like 35% for example? I'm using Stun as the state to inflict and I don't want to have to enemies in an infinite stun lock.
@Chaos AvianYou can add a condition to it.


Of course, this applies to everything that involves elemental calculations.

Code:
var TH_GameAction_calcElementRate = Game_Action.prototype.calcElementRate;
Game_Action.prototype.calcElementRate = function(target) {
    var rate = TH_GameAction_calcElementRate.call(this, target);
    if (rate > 1) {
       // random number between 0 and 1
       if (Math.random() < 0.35) {
         target.addState( 30 )
      }
    }
    return rate;
};
@Chaos Avian This is a really cool idea how exactly do you implementthat code to a project in MV? In the database, under states?

Original thread: https://forums.rpgmakerweb.com/threads/weakness-stun.56704/