Script Request: Flat State Resistance Bonuses

Hi,

I would like the ability to change state resistance value for actors, classes, enemies, weapons, armor, states, etc., through flat bonuses (both increases and decreases) to the value of the resistance, not the way it's done through the default engine as percentage modifiers.

For example:  Actor A has an innate 10% resistance to poison. 

He equips an armor that gives +20% resistance to poison.

He also uses a passive skill which boosts his poison resistance by 25%.

I want him to have 55% resistance to poison in this case, so that if he was attacked by an enemy or skill that had a 70% chance of inflicting poison, it would actually only be a 15% chance that Actor A would be inflicted with poison.

I've looked high and low through Yanfly's and Hime's scripts but can't seem to find the ability to do this...any help would be so very much appreciated.  Thank you in advance.
class Game_BattlerBase def element_rate(element_id) features_with_id(FEATURE_ELEMENT_RATE, element_id).inject(1.0) {|r, ft| r += ft.value - 1 } end def state_rate(state_id) features_with_id(FEATURE_STATE_RATE, state_id).inject(1.0) {|r, ft| r += ft.value - 1 } endend I have found an old thread that supposedly does what I want, but I've tried the code and it doesn't work. 

In my test, I gave an actor 50% chance to stun on hit, and an enemy 50% state resistance to stun. 

When I tested it, the actor still stunned the enemy once in a while, so I can only assume that the resistance is still being multiplicatively calculated (yielding 25%, instead of 0%).

Any help would be much appreciated.
jonthefox, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


If you need to add more information and the last post is yours, please edit the post and add the extra info.


You can access the forum rules from a link in the lower right corner of any page.
Did you delete Wavelength's post? I got a notification that he replied, and then you replied, but I don't see his post.  
You'll need to change both how the total state resist is calculated (making it additive instead of multiplicative, like those snippets do in Game_BattlerBase), and changing the parts where it randomly picks whether or not to apply the states (in Game_Battler). That should look something like the following:

Code:
  #--------------------------------------------------------------------------  # * [Add State] Effect: Normal Attack  #--------------------------------------------------------------------------  def item_effect_add_state_attack(user, item, effect)    user.atk_states.each do |state_id|      chance = effect.value1      #chance *= state_rate(state_id)      chance *= user.atk_states_rate(state_id)      chance -= state_rate(state_id)      chance *= luk_effect_rate(user)      if rand < chance        add_state(state_id)        @result.success = true      end    end  end  #--------------------------------------------------------------------------  # * [Add State] Effect: Normal  #--------------------------------------------------------------------------  def item_effect_add_state_normal(user, item, effect)    chance = effect.value1    #chance *= state_rate(effect.data_id) if opposite?(user)    chance -= state_rate(effect.data_id) if opposite?(user)    chance *= luk_effect_rate(user)      if opposite?(user)    if rand < chance      add_state(effect.data_id)      @result.success = true    end  end
I'm still getting used to Ruby and inject is one of the things that throws me for a particular loop, so I can't tell if those snippets you posted result in state_rate giving the battler's resistance to the state or 1 - the battler's resistance. If it's the wrong one, just change the "chance -= state_rate(effect.data_id)" in the code I provided here with "chance -= (1 - state_rate(effect.data_id))". I hope that works for you!

Original thread: https://forums.rpgmakerweb.com/threads/script-request-flat-state-resistance-bonuses.36967/