State disappear after three attacks

I made a shield skill that adds the state "shield" to the user. I want to made this state disappear not after 3 turns, but after 3 suffred attacks. How can I do that?
I found this script

But it does not stop damage, so I made this add-on
*Updated
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Shield State Count Hit fix   ║  Version: 1.01     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:  Patch                    ║   Date Created     ║
# ║      Allow hit to not do damage     ╠════════════════════╣
# ║      when successful.               ║    05 Jan 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: TroyZ - States Hit Count Removal               ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║ Original script allowed a state to be removed when hit,  ║
# ║ but if the state is a shield to block all damage         ║
# ║ then the player still took damage, this fixes it.        ║
# ║                                                          ║
# ║ Add Shield States below:                                 ║
# ║ Each state number added will protect from type damage    ║
# ║ Can be a single number [28], or multiple [4, 18, 28]     ║
# ║                                                          ║
# ║ Each one has it's specific hit type                      ║
# ║ Shield_State = Physical hit type                         ║
# ║ Mind_Shield = Magical hit type                           ║
# ║ Certain_Shield = Certain hit type                        ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 05 Jan 2021 - Initial publish                     ║
# ║ 1.01 - 05 Jan 2021 - Seperated damage to hit type        ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Follow the Original Authors terms                        ║
# ╚══════════════════════════════════════════════════════════╝
module R2_State_Shield_Remove_On_Hit
  Shield_State = [28, 1]
  Mind_Shield = [13, 29]
  Certain_Shield = [2, 30]
end

class Game_Battler < Game_BattlerBase
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    R2_State_Shield_Remove_On_Hit::Shield_State.each { |st|
      if item.physical? && @states.include?(st)
        value = 0
      end
    }
    R2_State_Shield_Remove_On_Hit::Certain_Shield.each { |st|
      if item.certain? && @states.include?(st)
        value = 0
      end
    }
    R2_State_Shield_Remove_On_Hit::Mind_Shield.each { |st|
      if item.magical? && @states.include?(st)
        value = 0
      end
    }
    @result.make_damage(value.to_i, item)
  end
end
I found this script

But it does not stop damage, so I made this add-on
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Shield State Count Hit fix   ║  Version: 1.00     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:  Patch                    ║   Date Created     ║
# ║      Allow hit to not do damage     ╠════════════════════╣
# ║      when successful.               ║    03 Jan 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: TroyZ - States Hit Count Removal               ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║ Original script allowed a state to be removed when hit,  ║
# ║ but if the state is a shield to block all damage         ║
# ║ then the player still took damage, this fixes it.        ║
# ║                                                          ║
# ║ Add Shield States below:                                 ║
# ║ Each state number added will protect from any damage     ║
# ║ Can be a single number [28], or multiple [4, 18, 28]     ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 05 Jan 2021 - Initial publish                     ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Follow the Original Authors terms                        ║
# ╚══════════════════════════════════════════════════════════╝
module R2_State_Shield_Remove_On_Hit
  Shield_State = [28, 1]
end

class Game_Battler < Game_BattlerBase
  alias r2_on_damage_state_remove_count on_damage
  def on_damage(value)
    R2_State_Shield_Remove_On_Hit::Shield_State.each { |st|
      if @states.include?(st)
        @result.hp_damage = 0
        @result.mp_damage = 0
        value = 0
      end }
    r2_on_damage_state_remove_count(value)
  end
end


Ok, I have one issue and one question.
- I think I didn't understand how to use the script.
My state has the effect to put physical damage to 0%, disappear at battle end, and I added in the notes:
<remove by hit: 3>
<remove by hit chance: 100>.
What do I have to put for the numbers of turns?

- I forgot to tell you I have to types of shield skill, one for physical attacks and one for special ones. So I mean the physical shield should be able to count only the attack with "physical" element. It's more complicated than I thought.
What do I have to put for the numbers of turns?
remove by hit is how many times the shield will survive a hit.
so if the enemy doesn't hit you it doesn't count, but if he does then the shield state goes down 1. when it reaches 0 the state is removed.
If you want it to last a specific number of turns then you set the turns in the state

Having different types of shield will require more work to adjust the results.
I'll try
@Ina00 Post updated above
I found this script

But it does not stop damage, so I made this add-on
*Updated
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Shield State Count Hit fix   ║  Version: 1.01     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:  Patch                    ║   Date Created     ║
# ║      Allow hit to not do damage     ╠════════════════════╣
# ║      when successful.               ║    05 Jan 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: TroyZ - States Hit Count Removal               ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║ Original script allowed a state to be removed when hit,  ║
# ║ but if the state is a shield to block all damage         ║
# ║ then the player still took damage, this fixes it.        ║
# ║                                                          ║
# ║ Add Shield States below:                                 ║
# ║ Each state number added will protect from type damage    ║
# ║ Can be a single number [28], or multiple [4, 18, 28]     ║
# ║                                                          ║
# ║ Each one has it's specific hit type                      ║
# ║ Shield_State = Physical hit type                         ║
# ║ Mind_Shield = Magical hit type                           ║
# ║ Certain_Shield = Certain hit type                        ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 05 Jan 2021 - Initial publish                     ║
# ║ 1.01 - 05 Jan 2021 - Seperated damage to hit type        ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Follow the Original Authors terms                        ║
# ╚══════════════════════════════════════════════════════════╝
module R2_State_Shield_Remove_On_Hit
  Shield_State = [28, 1]
  Mind_Shield = [13, 29]
  Certain_Shield = [2, 30]
end

class Game_Battler < Game_BattlerBase
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    R2_State_Shield_Remove_On_Hit::Shield_State.each { |st|
      if item.physical? && @states.include?(st)
        value = 0
      end
    }
    R2_State_Shield_Remove_On_Hit::Certain_Shield.each { |st|
      if item.certain? && @states.include?(st)
        value = 0
      end
    }
    R2_State_Shield_Remove_On_Hit::Mind_Shield.each { |st|
      if item.magical? && @states.include?(st)
        value = 0
      end
    }
    @result.make_damage(value.to_i, item)
  end
end

First, thank you for spending your time helping me 🙂
I don't know why, but the script doesn't seem to work, the shield doesn't disappear.
How do I need to configure the state? I mean in the database, becouse it seems the game only read database infos and not the notes.
Another issue and that I have two levels of shield, so Shield I and II skills have to reduce by half the damage (I did this by element rate), and Shield III and IV have to block the attack. With this script all shield states reduce the damage to 0.
the shield doesn't disappear
Not is my tests. I'll check it out.
Shield I and II skills have to reduce by half the damage (I did this by element rate), and Shield III and IV have to block the attack.
It's always good to let people know what you want. You are just adding on more conditions every time I make a new script.

What else is there?
Not is my tests. I'll check it out.

It's always good to let people know what you want. You are just adding on more conditions every time I make a new script.

What else is there?

Yes I know, I'm so sorry. I write here everything to know.
-There are 8 shield skills in total, 4 levels for the physical shield and 4 for special ones.
- Shield skill database settings:
no restrictions, remove at battle end, remove restriction option disabled (I don't know what this one do), disappear at the end of turn (I don't know if I need to change this to end of action or nothing, can you tell me?)
- skills are:
Shield I, shield II, shield, shield IV for physical.
I and II have element rate "physical" at 50%, III and IV have element rate "physical" at 0%.

Barrier I, barrier II, barrier III and barrier IV for special.
Database settings are the same.
I and II have all of the elements at rate 50%, III and IV have all of the elements at rate 0%.


- What's the difference between, for example, shield I and shield II if they have same settings? Basically I is single target and II is to all of the actors.

I think that's all, I'm sorry again.
With these settings the sistuation is:
- The damage is always blocked, also if the shield has 50% rate and not 0%.
- The shield disappears following thw database option and not the notes.

Maybe I added wrong the scripts in materials... Do I have to split them or put them in one script one under the other?



PS: I don't post screenshots becouse I have RPG maker in Italian.
Maybe I added wrong the scripts in materials
Not exactly. I did make a small mistake. I voided the damage so when the on_damage method was called it did not process because the damage was zero.
Ruby:
        make_damage_value(user, item)
        execute_damage(user)
        on_damage(@result.hp_damage) if @result.hp_damage > 0
make_damage is where I change the value, so since hp_damage was 0 it did not call on_damage. which is where the update_states_hit_count is located.

I added the method call into my code and created the multiple state levels that you wanted.

Hopefully this will do all you need.
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Shield State Count Hit fix   ║  Version: 1.02     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:  Patch                    ║   Date Created     ║
# ║      Allow hit to not do damage     ╠════════════════════╣
# ║      when successful.               ║    05 Jan 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: TroyZ - States Hit Count Removal               ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║ Original script allowed a state to be removed when hit,  ║
# ║ but if the state is a shield to block all damage         ║
# ║ then the player still took damage, this fixes it.        ║
# ║                                                          ║
# ║ Add Shield States below:                                 ║
# ║ Each state number added will protect from type damage    ║
# ║ Can be a single number [28], or multiple [4, 18, 28]     ║
# ║                                                          ║
# ║ Each one has it's specific hit type                      ║
# ║ Shield_State = Physical hit type                         ║
# ║ Mind_Shield = Magical hit type                           ║
# ║ Certain_Shield = Certain hit type                        ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 05 Jan 2021 - Initial publish                     ║
# ║ 1.01 - 06 Jan 2021 - Seperated damage to hit type        ║
# ║ 1.02 - 06 Jan 2021 - Created percentage damage option    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Follow the Original Authors terms                        ║
# ╚══════════════════════════════════════════════════════════╝
module R2_State_Shield_Remove_On_Hit
    # states that give 100% protection from damage
  Physical_Shield = [1, 28]
  # Physical hit type protection
  Mind_Shield = [13, 29]
  # Magic hit type protection
  Certain_Shield = [4, 30]
  # Certain hit type protection
    
    # states that give percentage protection
  Half_Physical = [2, 33]
  # Physical hit type protection
  Half_Mind = [14, 32]
  # Magic hit type protection
  Half_Certain = [5, 31]
  # Certain hit type protection
    
    # Percentage values for half states 50 = 50%
  Physical_Rate = 50
  # Physical hit type protection percentage value
  Mind_Rate = 70
  # Magic hit type protection percentage value
  Certain_Rate = 30
  # Certain hit type protection percentage value
    
end

class Game_Battler < Game_BattlerBase
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    R2_State_Shield_Remove_On_Hit::Half_Physical.each { |st|
      if item.physical? && @states.include?(st)
        value = ((value * R2_State_Shield_Remove_On_Hit::Physical_Rate) / 100).to_i
      end
    }
    R2_State_Shield_Remove_On_Hit::Half_Certain.each { |st|
      if item.certain? && @states.include?(st)
        value = ((value * R2_State_Shield_Remove_On_Hit::Certain_Rate) / 100).to_i
      end
    }
    R2_State_Shield_Remove_On_Hit::Half_Mind.each { |st|
      if item.magical? && @states.include?(st)
        value = ((value * R2_State_Shield_Remove_On_Hit::Mind_Rate) / 100).to_i
      end
    }
    R2_State_Shield_Remove_On_Hit::Physical_Shield.each { |st|
      if item.physical? && @states.include?(st)
        value = 0
        update_states_hit_count
        remove_states_by_hit_count
      end
    }
    R2_State_Shield_Remove_On_Hit::Certain_Shield.each { |st|
      if item.certain? && @states.include?(st)
        value = 0
        update_states_hit_count
        remove_states_by_hit_count
      end
    }
    R2_State_Shield_Remove_On_Hit::Mind_Shield.each { |st|
      if item.magical? && @states.include?(st)
        value = 0
        update_states_hit_count
        remove_states_by_hit_count
      end
    }
    @result.make_damage(value.to_i, item)
  end
end
Not exactly. I did make a small mistake. I voided the damage so when the on_damage method was called it did not process because the damage was zero.
Ruby:
        make_damage_value(user, item)
        execute_damage(user)
        on_damage(@result.hp_damage) if @result.hp_damage > 0
make_damage is where I change the value, so since hp_damage was 0 it did not call on_damage. which is where the update_states_hit_count is located.

I added the method call into my code and created the multiple state levels that you wanted.

Hopefully this will do all you need.
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Shield State Count Hit fix   ║  Version: 1.02     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:  Patch                    ║   Date Created     ║
# ║      Allow hit to not do damage     ╠════════════════════╣
# ║      when successful.               ║    05 Jan 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: TroyZ - States Hit Count Removal               ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║ Original script allowed a state to be removed when hit,  ║
# ║ but if the state is a shield to block all damage         ║
# ║ then the player still took damage, this fixes it.        ║
# ║                                                          ║
# ║ Add Shield States below:                                 ║
# ║ Each state number added will protect from type damage    ║
# ║ Can be a single number [28], or multiple [4, 18, 28]     ║
# ║                                                          ║
# ║ Each one has it's specific hit type                      ║
# ║ Shield_State = Physical hit type                         ║
# ║ Mind_Shield = Magical hit type                           ║
# ║ Certain_Shield = Certain hit type                        ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 05 Jan 2021 - Initial publish                     ║
# ║ 1.01 - 06 Jan 2021 - Seperated damage to hit type        ║
# ║ 1.02 - 06 Jan 2021 - Created percentage damage option    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Follow the Original Authors terms                        ║
# ╚══════════════════════════════════════════════════════════╝
module R2_State_Shield_Remove_On_Hit
    # states that give 100% protection from damage
  Physical_Shield = [1, 28]
  # Physical hit type protection
  Mind_Shield = [13, 29]
  # Magic hit type protection
  Certain_Shield = [4, 30]
  # Certain hit type protection
   
    # states that give percentage protection
  Half_Physical = [2, 33]
  # Physical hit type protection
  Half_Mind = [14, 32]
  # Magic hit type protection
  Half_Certain = [5, 31]
  # Certain hit type protection
   
    # Percentage values for half states 50 = 50%
  Physical_Rate = 50
  # Physical hit type protection percentage value
  Mind_Rate = 70
  # Magic hit type protection percentage value
  Certain_Rate = 30
  # Certain hit type protection percentage value
   
end

class Game_Battler < Game_BattlerBase
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    R2_State_Shield_Remove_On_Hit::Half_Physical.each { |st|
      if item.physical? && @states.include?(st)
        value = ((value * R2_State_Shield_Remove_On_Hit::Physical_Rate) / 100).to_i
      end
    }
    R2_State_Shield_Remove_On_Hit::Half_Certain.each { |st|
      if item.certain? && @states.include?(st)
        value = ((value * R2_State_Shield_Remove_On_Hit::Certain_Rate) / 100).to_i
      end
    }
    R2_State_Shield_Remove_On_Hit::Half_Mind.each { |st|
      if item.magical? && @states.include?(st)
        value = ((value * R2_State_Shield_Remove_On_Hit::Mind_Rate) / 100).to_i
      end
    }
    R2_State_Shield_Remove_On_Hit::Physical_Shield.each { |st|
      if item.physical? && @states.include?(st)
        value = 0
        update_states_hit_count
        remove_states_by_hit_count
      end
    }
    R2_State_Shield_Remove_On_Hit::Certain_Shield.each { |st|
      if item.certain? && @states.include?(st)
        value = 0
        update_states_hit_count
        remove_states_by_hit_count
      end
    }
    R2_State_Shield_Remove_On_Hit::Mind_Shield.each { |st|
      if item.magical? && @states.include?(st)
        value = 0
        update_states_hit_count
        remove_states_by_hit_count
      end
    }
    @result.make_damage(value.to_i, item)
  end
end


I tested a little and the situation is:
- The damage parcetage work perfectly. (maybe special damage have some issue, if without barrier the damage is 80-100 whit it is 15-20)
- The state follows the hit number i wrote in the note.
- The only issue is that the damege isn't differenced, a special move counts as same as a physical move, if the player suffers 5 attacks the shield disappear.
What does "certain" mean?

Don't worry, you are spending too much time for me, if don't want to fix this I don't mind 🙂
a special move
What is a special move?
1610027180233.png
What is a special move?
View attachment 174582


Ok,I've already set this right. Issues are the same I wrote before. The special damage counts the same as physical damage.
Another error appears when I load the game: "undefined method "(rectangle symbol) =" for nil:Nil class" refered to the original author's script, but I think I need to play a new game.
Issues are the same I wrote before. The special damage counts the same as physical damage
I don't think I can help you. What special damage?
I don't think I can help you. What special damage?

I think It's better to give up, I think this would be easier. Don't worry I'll keep the turn counter, It's a very small thing I don't mind to change.
I think It's better to give up
Well, it's a language barrier thing. I don't know what you're talking about.

What is Special Damage? Can you post a screen shot?

Original thread: https://forums.rpgmakerweb.com/threads/state-disappear-after-three-attacks.131846/