• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] How do I check the amount of damage a pokemon of mine has dealt? How do I also check the amount of damage per physical attack and special attack? How

107
Posts
3
Years
    • Seen Apr 27, 2023
    How do I check the amount of damage a pokemon of mine has dealt?
    How do I also check the amount of damage per physical attack and special attack?
    How do I count the number of times a Pokémon X has fainted a Pokémon?
    How are the methods for this kind of thing done?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    How do I check the amount of damage a pokemon of mine has dealt?
    How do I also check the amount of damage per physical attack and special attack?
    How do I count the number of times a Pokémon X has fainted a Pokémon?
    How are the methods for this kind of thing done?

    You mean, the damage done in a whole game?
    It doesn't exist. You have to code it yourself.

    It should be easy though. From the top of my head:
    1. Add attributes to the class PokeBattle_Pokemon (the Pokémons as they are in your team) to store the total damage / number of times the Pokémon has killed another one.
    2. Find the function that actually deals the damage to a given Pokémon (should be in the class PokeBattler_Battler). Add lines of code to update the abovementioned attributes to the PokeBattle_Pokemon associated with the PokeBattle_Battler.
     
    Last edited:
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    You mean, the damage done in a whole game?
    It doesn't exist. You have to code it yourself.

    It should be easy though. From the top of my head:
    1. Add attributes to the class PokeBattle_Pokemon (the Pokémons as they are in your team) to store the total damage / number of times the Pokémon has killed another one.
    2. Find the function that actually deals the damage to a given Pokémon (should be in the class PokeBattler_Battler). Add lines of code to update the abovementioned attributes to the PokeBattle_Pokemon associated with the PokeBattle_Battler.
    [Essentials v18.1]
    In: PokeBattle_Pokemon I added a:
    attr_accessor :damage
    what worked, I can already set this in a Pokémon.

    Also in this class I put a method:
    I don't know what the effect is, I just copied the script pattern (I'm newbie).
    def damage
    return @damage || 0
    end

    in the PokeBattle_Move:

    def pbInflictHPDamage(target)
    if target.damageState.substitute
    target.effects[PBEffects::Substitute] -= target.damageState.hpLost
    else
    target.hp -= target.damageState.hpLost
    $Trainer.party[0].damage += +(target.damageState.hpLost)
    end
    end

    Once this is done, all damage done by my Pokémon is added to it in general.

    Once this is done, all damage done by my Pokémon is added to it in general.
    However, as it is a function where it loses HP, even the negative effect made by another Pokémon will count towards the first one on the team.

    I tried in def pbCalcDamage, but there it adds up to a value even higher than the enemy's HP, so I assumed that calculating through HP would be ideal.

    How do I calculate the damage done by my Pokémon, without another Pokémon passing in another turn and dealing damage?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    [Essentials v18.1]
    In: PokeBattle_Pokemon I added a:
    Code:
      attr_accessor :damage

    what worked, I can already set this in a Pokémon.

    I would recommend you call this "totalDamageTaken" or something more explicit like that. Because you also want to store "totalDamageDone":

    Code:
      attr_accessor :totalDamageTaken
      attr_accessor :totalDamageDone

    Also in this class I put a method:
    I don't know what the effect is, I just copied the script pattern (I'm newbie).

    Code:
     def damage
    return @damage || 0
    end

    This allows you to get the value of the attribute "damage", or, if "damage" is uninitialised, returns 0.
    So actually, I would recommend you don't do that. You're lucky it doesn't cause problems in the function!

    What I would recommend is to initialize totalDamageTaken in the function that initializes the Pokémon. Paste this somewhere:

    Code:
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
      end

    in the PokeBattle_Move:

    Code:
     def pbInflictHPDamage(target)
    if target.damageState.substitute
    target.effects[PBEffects::Substitute] -= target.damageState.hpLost
    else
    target.hp -= target.damageState.hpLost
    $Trainer.party[0].damage += +(target.damageState.hpLost)
    end
    end

    Once this is done, all damage done by my Pokémon is added to it in general.

    Once this is done, all damage done by my Pokémon is added to it in general.
    However, as it is a function where it loses HP, even the negative effect made by another Pokémon will count towards the first one on the team.

    I tried in def pbCalcDamage, but there it adds up to a value even higher than the enemy's HP, so I assumed that calculating through HP would be ideal.

    So the problem is that you specifically target the first Pokémon:
    Code:
    $Trainer.party[0].damage += +(target.damageState.hpLost)
    Here, "party[0]" means that you want the first Pokémon of your party (index 0 is the first index in programming) to store the damage taken.
    Actually, you need to refer to the Pokémon corresponding to the battler. The solution would be to replace this line with this:
    Code:
    target.pokemon.totalDamageTaken += target.damageState.hpLost

    Don't do that though. (Read till the end)

    How do I calculate the damage done by my Pokémon, without another Pokémon passing in another turn and dealing damage?

    So actually you want to store both the damage taken and the damage done. You cannot do both in the function above. So I suggest you delete your edits, and you do both edits in the same place, just in case you need to debug / edit this code afterwards.

    Go to:
    Code:
      def pbProcessMoveHit(move,user,targets,hitNum,skipAccuracyCheck)
    and find the lines:
    Code:
        # Deal the damage (to all allies first simultaneously, then all foes
        # simultaneously)
        if move.pbDamagingMove?
          # This just changes the HP amounts and does nothing else
          targets.each do |b|
            next if b.damageState.unaffected
            move.pbInflictHPDamage(b)
          end
          # Animate the hit flashing and HP bar changes
          move.pbAnimateHitAndHPLost(user,targets)
        end
    Below this line:
    Code:
            move.pbInflictHPDamage(b)
    add this:
    Code:
            b.pokemon.totalDamageTaken += target.damageState.hpLost
            user.pokemon.totalDamageDone += target.damageState.hpLost
    Here, "user" refers to the user of the move that dealt damage. So here you store both the damage dealt and taken.
     
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    I would recommend you call this "totalDamageTaken" or something more explicit like that. Because you also want to store "totalDamageDone":

    Code:
      attr_accessor :totalDamageTaken
      attr_accessor :totalDamageDone



    This allows you to get the value of the attribute "damage", or, if "damage" is uninitialised, returns 0.
    So actually, I would recommend you don't do that. You're lucky it doesn't cause problems in the function!

    What I would recommend is to initialize totalDamageTaken in the function that initializes the Pokémon. Paste this somewhere:

    Code:
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
      end



    So the problem is that you specifically target the first Pokémon:
    Code:
    $Trainer.party[0].damage += +(target.damageState.hpLost)
    Here, "party[0]" means that you want the first Pokémon of your party (index 0 is the first index in programming) to store the damage taken.
    Actually, you need to refer to the Pokémon corresponding to the battler. The solution would be to replace this line with this:
    Code:
    target.pokemon.totalDamageTaken += target.damageState.hpLost

    Don't do that though. (Read till the end)



    So actually you want to store both the damage taken and the damage done. You cannot do both in the function above. So I suggest you delete your edits, and you do both edits in the same place, just in case you need to debug / edit this code afterwards.

    Go to:
    Code:
      def pbProcessMoveHit(move,user,targets,hitNum,skipAccuracyCheck)
    and find the lines:
    Code:
        # Deal the damage (to all allies first simultaneously, then all foes
        # simultaneously)
        if move.pbDamagingMove?
          # This just changes the HP amounts and does nothing else
          targets.each do |b|
            next if b.damageState.unaffected
            move.pbInflictHPDamage(b)
          end
          # Animate the hit flashing and HP bar changes
          move.pbAnimateHitAndHPLost(user,targets)
        end
    Below this line:
    Code:
            move.pbInflictHPDamage(b)
    add this:
    Code:
            b.pokemon.totalDamageTaken += target.damageState.hpLost
            user.pokemon.totalDamageDone += target.damageState.hpLost
    Here, "user" refers to the user of the move that dealt damage. So here you store both the damage dealt and taken.

    Perfect, I learned a lot from these few explanations!
    Perfect, I learned a lot from these few explanations!

    With that, I went to realize another attribute, I called it:
    attr_accessor :totalPhysicalDamage
    attr_accessor :totalSpecialDamage

    and also defined them in initialize!
    below:
    user.pokemon.totalDamageDone += target.damageState.hpLost
    I placed:

    user.pokemon.totalPhysicalDamage && move.physicalMove? += target.damageState.hpLost

    But there was a syntax error in
    move.physicalMove?
    Looking at the codes was the way I found to define, would you know what's wrong?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    I placed:

    Code:
     user.pokemon.totalPhysicalDamage && move.physicalMove? += target.damageState.hpLost

    But there was a syntax error in
    move.physicalMove?
    Looking at the codes was the way I found to define, would you know what's wrong?

    The idea is: add the damage, IF the move is physical. In Ruby, it's written like this:

    Code:
     user.pokemon.totalPhysicalDamage += target.damageState.hpLost if move.physicalMove?
    Same for special damage.

    PS: To post code on PokéCommunity, use [CODE_] [/CODE_] instead of [QUOTE_] [/QUOTE_] (remove the "_").
     
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    The idea is: add the damage, IF the move is physical. In Ruby, it's written like this:

    Code:
     user.pokemon.totalPhysicalDamage += target.damageState.hpLost if move.physicalMove?
    Same for special damage.

    PS: To post code on PokéCommunity, use [CODE_] [/CODE_] instead of [QUOTE_] [/QUOTE_] (remove the "_").

    Thanks for the tip! Look, I went to test the script and got the following error on the line:
    Code:
    b.pokemon.totalDamageTaken += target.damageState.hpLost
    user.pokemon.totalDamageDone += target.damageState.hpLost
    Where the target has not been defined.
    I assumed target would be b, so I did:
    Code:
    user.pokemon.totalDamageDone += b.damageState.hpLost
    and it worked perfectly!

    Now I would like to count the knockouts caused by my Pokémon! For this I have already created the new attribute called:
    knockouts
    I immediately thought of the faint command
    Code:
    def pbFaint(showMessage=true)
    However, I realized that it is valid for both the user and the enemy Pokémon.
    How do I recognize that the fainted is the enemy and add to the new Pokémon attribute?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Thanks for the tip! Look, I went to test the script and got the following error on the line:
    Code:
    b.pokemon.totalDamageTaken += target.damageState.hpLost
    user.pokemon.totalDamageDone += target.damageState.hpLost
    Where the target has not been defined.
    I assumed target would be b, so I did:
    Code:
    user.pokemon.totalDamageDone += b.damageState.hpLost
    and it worked perfectly!
    Wonderful :)

    Now I would like to count the knockouts caused by my Pokémon! For this I have already created the new attribute called:
    knockouts
    I immediately thought of the faint command
    Code:
    def pbFaint(showMessage=true)
    However, I realized that it is valid for both the user and the enemy Pokémon.
    How do I recognize that the fainted is the enemy and add to the new Pokémon attribute?
    So, you initialize the new attribute in class PokeBattle_Pokemon, like the previous ones:

    Code:
      attr_accessor :numPokemonsPutKO

    and add some code to this: (this is an extension of the initialisation function I gave you in a previous post).

    Code:
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
        @numPokemonsPutKO = 0 
      end

    The function pbFaint() "knows" only the fainting Pokémon, and not the Pokémon that made it faint.

    My idea was to look for abilities or items that trigger when a Pokémon faints, and that has an effect on the Pokémon that killed it. For example: Moxie.
    Moxie is defined as a Battle Handler (which is a convenient way to add effects to a specific script without changing anything in the functions that control battle):
    Code:
    BattleHandlers::UserAbilityEndOfMove.add(:MOXIE,
    Battle Handlers are called in functions of the form trigger[Battle Handler Name]:
    Code:
      def self.triggerUserAbilityEndOfMove(ability,user,targets,move,battle)
    This function is called only once in the code, in the function:
    Code:
      def pbEffectsAfterMove(user,targets,move,numHits)
    As this is a big function, I suggest to make another function, for example written in the script that contains the initialize function I mentioned above.
    So, find the lines:
    Code:
        # Consume user's Gem
        if user.effects[PBEffects::GemConsumed]>0
          # NOTE: The consume animation and message for Gems are shown immediately
          #       after the move's animation, but the item is only consumed now.
          user.pbConsumeItem
        end
    and below, paste this:
    Code:
    # Register when a Pokemon faints: 
    pbRegisterFaintedPokemon(user,targets,move,@battle)
    and in the separate script, paste this:
    Code:
    class PokeBattle_Battler
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
      end 
    end

    By the way, your total code should look like this:

    Code:
    # In a separate script: 
    class PokeBattle_Pokemon
      attr_accessor :totalDamageTaken 
      attr_accessor :totalDamageDone 
      attr_accessor :numPokemonsPutKO
    
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
        @numPokemonsPutKO = 0 
      end
    end 
    
    class PokeBattle_Battler
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
      end 
    end
    + the small edits to this function:
    Code:
      def pbProcessMoveHit(move,user,targets,hitNum,skipAccuracyCheck)
    which contain only:
    Code:
        b.pokemon.totalDamageTaken += b.damageState.hpLost
        user.pokemon.totalDamageDone += b.damageState.hpLost
     
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    Wonderful :)


    So, you initialize the new attribute in class PokeBattle_Pokemon, like the previous ones:

    Code:
      attr_accessor :numPokemonsPutKO

    and add some code to this: (this is an extension of the initialisation function I gave you in a previous post).

    Code:
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
        @numPokemonsPutKO = 0 
      end

    The function pbFaint() "knows" only the fainting Pokémon, and not the Pokémon that made it faint.

    My idea was to look for abilities or items that trigger when a Pokémon faints, and that has an effect on the Pokémon that killed it. For example: Moxie.
    Moxie is defined as a Battle Handler (which is a convenient way to add effects to a specific script without changing anything in the functions that control battle):
    Code:
    BattleHandlers::UserAbilityEndOfMove.add(:MOXIE,
    Battle Handlers are called in functions of the form trigger[Battle Handler Name]:
    Code:
      def self.triggerUserAbilityEndOfMove(ability,user,targets,move,battle)
    This function is called only once in the code, in the function:
    Code:
      def pbEffectsAfterMove(user,targets,move,numHits)
    As this is a big function, I suggest to make another function, for example written in the script that contains the initialize function I mentioned above.
    So, find the lines:
    Code:
        # Consume user's Gem
        if user.effects[PBEffects::GemConsumed]>0
          # NOTE: The consume animation and message for Gems are shown immediately
          #       after the move's animation, but the item is only consumed now.
          user.pbConsumeItem
        end
    and below, paste this:
    Code:
    # Register when a Pokemon faints: 
    pbRegisterFaintedPokemon(user,targets,move,@battle)
    and in the separate script, paste this:
    Code:
    class PokeBattle_Battler
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
      end 
    end

    By the way, your total code should look like this:

    Code:
    # In a separate script: 
    class PokeBattle_Pokemon
      attr_accessor :totalDamageTaken 
      attr_accessor :totalDamageDone 
      attr_accessor :numPokemonsPutKO
    
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
        @numPokemonsPutKO = 0 
      end
    end 
    
    class PokeBattle_Battler
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
      end 
    end
    + the small edits to this function:
    Code:
      def pbProcessMoveHit(move,user,targets,hitNum,skipAccuracyCheck)
    which contain only:
    Code:
        b.pokemon.totalDamageTaken += b.damageState.hpLost
        user.pokemon.totalDamageDone += b.damageState.hpLost

    Dude, tested and approved 100%! Everything worked VERY well!
    This last knockout counter, I found an even more advanced knowledge, however, I managed to keep up!
    Thank you so much for the strength, this is already great content for a Pokemon-related achievement system.

    Now, alone I will try to check the number of times a pokémon x used such a move. I'll show you the result if it's a success or I fail.
     
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    Wonderful :)


    So, you initialize the new attribute in class PokeBattle_Pokemon, like the previous ones:

    Code:
      attr_accessor :numPokemonsPutKO

    and add some code to this: (this is an extension of the initialisation function I gave you in a previous post).

    Code:
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
        @numPokemonsPutKO = 0 
      end

    The function pbFaint() "knows" only the fainting Pokémon, and not the Pokémon that made it faint.

    My idea was to look for abilities or items that trigger when a Pokémon faints, and that has an effect on the Pokémon that killed it. For example: Moxie.
    Moxie is defined as a Battle Handler (which is a convenient way to add effects to a specific script without changing anything in the functions that control battle):
    Code:
    BattleHandlers::UserAbilityEndOfMove.add(:MOXIE,
    Battle Handlers are called in functions of the form trigger[Battle Handler Name]:
    Code:
      def self.triggerUserAbilityEndOfMove(ability,user,targets,move,battle)
    This function is called only once in the code, in the function:
    Code:
      def pbEffectsAfterMove(user,targets,move,numHits)
    As this is a big function, I suggest to make another function, for example written in the script that contains the initialize function I mentioned above.
    So, find the lines:
    Code:
        # Consume user's Gem
        if user.effects[PBEffects::GemConsumed]>0
          # NOTE: The consume animation and message for Gems are shown immediately
          #       after the move's animation, but the item is only consumed now.
          user.pbConsumeItem
        end
    and below, paste this:
    Code:
    # Register when a Pokemon faints: 
    pbRegisterFaintedPokemon(user,targets,move,@battle)
    and in the separate script, paste this:
    Code:
    class PokeBattle_Battler
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
      end 
    end

    By the way, your total code should look like this:

    Code:
    # In a separate script: 
    class PokeBattle_Pokemon
      attr_accessor :totalDamageTaken 
      attr_accessor :totalDamageDone 
      attr_accessor :numPokemonsPutKO
    
      alias __darkraimaker__init initialize
      def initialize(*args)
        __darkraimaker__init(*args)
        @totalDamageTaken = 0
        @totalDamageDone = 0
        @numPokemonsPutKO = 0 
      end
    end 
    
    class PokeBattle_Battler
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
      end 
    end
    + the small edits to this function:
    Code:
      def pbProcessMoveHit(move,user,targets,hitNum,skipAccuracyCheck)
    which contain only:
    Code:
        b.pokemon.totalDamageTaken += b.damageState.hpLost
        user.pokemon.totalDamageDone += b.damageState.hpLost

    I made a new attribute that increases as the player KOs with HKO moves.
    In Move_Effects
    Code:
    def pbHitEffectivenessMessages(user,target,numTargets=1)
    below:
    Code:
    @battle.pbDisplay(_INTL("It's a one-hit KO!"))
    added:
    Code:
    user.pokemon.numPokemonsPutHKO += 1 if !user.fainted?

    also, by default I put the new attribute numPokemonsPutHKO in
    PokeBattle_Pokemon

    But now I would like to make an attribute for NON-effective damage knockouts, as opposed to Super effective ones, but I felt difficult.
    For I did not understand a way to combine this with
    PBTypes.notVeryEffective?(target.damageState.typeMod)

    would you have any ideas?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    I made a new attribute that increases as the player KOs with HKO moves.
    In Move_Effects
    Code:
    def pbHitEffectivenessMessages(user,target,numTargets=1)
    below:
    Code:
    @battle.pbDisplay(_INTL("It's a one-hit KO!"))
    added:
    Code:
    user.pokemon.numPokemonsPutHKO += 1 if !user.fainted?

    also, by default I put the new attribute numPokemonsPutHKO in
    PokeBattle_Pokemon

    Looks good!

    But now I would like to make an attribute for NON-effective damage knockouts, as opposed to Super effective ones, but I felt difficult.
    For I did not understand a way to combine this with
    PBTypes.notVeryEffective?(target.damageState.typeMod)

    would you have any ideas?

    If you're counting knockouts, you'll likely have to edit the function I gave you in a previous post:
    Code:
      def pbRegisterFaintedPokemon(user,targets,move,battle)

    Now I believe your question is: how does the function PBTypes.notVeryEffective? work?
    Here is its code:
    Code:
      def PBTypes.notVeryEffective?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
        return attackType>PBTypeEffectiveness::INEFFECTIVE && attackType<PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
        e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
        return e>PBTypeEffectiveness::INEFFECTIVE && e<PBTypeEffectiveness::NORMAL_EFFECTIVE
      end
    The first line of the body of the function:
    Code:
        return attackType>PBTypeEffectiveness::INEFFECTIVE && attackType<PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
    means that the function PBTypes.notVeryEffective? works in two different ways:
    1. You can give only one argument, in which case it has to be an integer, and it's a type effectiveness computed somewhere else (typically in the damage calculation, whose result is stored in target.damageState.typeMod)
    2. Or you can give it one attack type and one, two or three target types, in which case it will compute the effectiveness itself.

    From what you're trying to do, you should be in the first case scenario.
    Edit thefunction pbRegisterFaintedPokemon I gave you before:
    Code:
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| 
          user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted 
          user.pokemon.numPokemonsPutKONotVeryEffective += 1 if b.damageState.fainted &&  PBTypes.notVeryEffective?(b.damageState.typeMod)
        }
      end
    (Assuming you name your variable "numPokemonsPutKONotVeryEffective")
     
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    Looks good!



    If you're counting knockouts, you'll likely have to edit the function I gave you in a previous post:
    Code:
      def pbRegisterFaintedPokemon(user,targets,move,battle)

    Now I believe your question is: how does the function PBTypes.notVeryEffective? work?
    Here is its code:
    Code:
      def PBTypes.notVeryEffective?(attackType,targetType1=nil,targetType2=nil,targetType3=nil)
        return attackType>PBTypeEffectiveness::INEFFECTIVE && attackType<PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
        e = PBTypes.getCombinedEffectiveness(attackType,targetType1,targetType2,targetType3)
        return e>PBTypeEffectiveness::INEFFECTIVE && e<PBTypeEffectiveness::NORMAL_EFFECTIVE
      end
    The first line of the body of the function:
    Code:
        return attackType>PBTypeEffectiveness::INEFFECTIVE && attackType<PBTypeEffectiveness::NORMAL_EFFECTIVE if !targetType1
    means that the function PBTypes.notVeryEffective? works in two different ways:
    1. You can give only one argument, in which case it has to be an integer, and it's a type effectiveness computed somewhere else (typically in the damage calculation, whose result is stored in target.damageState.typeMod)
    2. Or you can give it one attack type and one, two or three target types, in which case it will compute the effectiveness itself.

    From what you're trying to do, you should be in the first case scenario.
    Edit thefunction pbRegisterFaintedPokemon I gave you before:
    Code:
      def pbRegisterFaintedPokemon(user,targets,move,battle)
        targets.each { |b| 
          user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted 
          user.pokemon.numPokemonsPutKONotVeryEffective += 1 if b.damageState.fainted &&  PBTypes.notVeryEffective?(b.damageState.typeMod)
        }
      end
    (Assuming you name your variable "numPokemonsPutKONotVeryEffective")

    Everything worked great, I kept working on the system and it's a lot of fun! I have two new challenges, I would like to do a mission where the user Pokémon lands the first hit in that battle, this gives value to its speed. The second challenge was to identify knockouts of only one attack (hit kill), but made by common moves.
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Everything worked great, I kept working on the system and it's a lot of fun! I have two new challenges, I would like to do a mission where the user Pokémon lands the first hit in that battle, this gives value to its speed.

    I don't understand this part. Is it a new ability? Does the speed get a boost?

    The second challenge was to identify knockouts of only one attack (hit kill), but made by common moves.

    You'd have to edit that function:

    Code:
      def pbRegisterFaintedPokemon(user,targets,move,battle)

    This time I'll let you guess what has to go there :)
    Spoiler:
     
    107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    I don't understand this part. Is it a new ability? Does the speed get a boost?



    You'd have to edit that function:

    Code:
      def pbRegisterFaintedPokemon(user,targets,move,battle)

    This time I'll let you guess what has to go there :)
    Spoiler:

    Sorry, the translator didn't help. I want to increase an attribute every time the user Pokémon hits the first move of the battle.

    About the other I managed to identify.
    Code:
          user.pokemon.numPokemonsPutKOHitkill += 1 if b.damageState.fainted && (b.totalhp == b.damageState.hpLost)

    It worked, because it will only add the value, if the lost hp is equal to the total hp of the Pokémon, this is possible because the HP LOST resets every turn!
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Sorry, the translator didn't help. I want to increase an attribute every time the user Pokémon hits the first move of the battle.

    I think you should try to edit the function:
    Code:
      def pbUseMove(choice,specialUsage=false)
    Again, don't directly edit it, copy paste this instead in the script where you put the rest of my code:
    Code:
    class PokeBattle_Battler
      alias __darkraimaker__pbUseMove pbUseMove
      def pbUseMove(choice,specialUsage=false)
        # Put your code here 
        __darkraimaker__pbUseMove(choice, specialUsage)
      end 
    end
    Now, the question is: what do you put here?
    So you can access the number of turns in battle with the attribute:
    Code:
    @battle.turnCount
    And you can see the last move used this turn in the attribute:
    Code:
    @battle.lastMoveUsed # Default value is -1, or the ID of the move used last turn.
    So my guess is, in pbUseMove, add a code like this:
    Code:
    if @battle.turnCount == 1 && @battle.lastMoveUsed == -1
    # Then add +1 to the right counter.
    end

    About the other I managed to identify.
    Code:
          user.pokemon.numPokemonsPutKOHitkill += 1 if b.damageState.fainted && (b.totalhp == b.damageState.hpLost)

    It worked, because it will only add the value, if the lost hp is equal to the total hp of the Pokémon, this is possible because the HP LOST resets every turn!

    Nice :)
     
    Back
    Top