• 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 make a script to use a conditional in the game that identifies that the character has knocked out 5 Geodudes for example? or captured 5 geodu

  • 232
    Posts
    7
    Years
    • Seen Jun 2, 2024
    How do I make a script to use a conditional in the game that identifies that the character has knocked out 5 Geodudes for example?
    or captured 5 geodudes, for example?
    Would anyone know how to do something that identifies this in the game?
    The closest to something like that is the Anchievments System, but it does not identify specific Pokémon ...
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen today
    How do I make a script to use a conditional in the game that identifies that the character has knocked out 5 Geodudes for example?
    or captured 5 geodudes, for example?
    Would anyone know how to do something that identifies this in the game?
    The closest to something like that is the Anchievments System, but it does not identify specific Pokémon ...

    If I were to answer specifically your question, I would suggest some code like this, to be pasted somewhere:
    Code:
    class PokeBattle_Battler
      alias __Messi_count__pbFaint pbFaint
      def pbFaint(*args)
        __Messi_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX]
        $game_variables[XXX] += 1 if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
      end 
    end
    Basically it rewrites pbFaint so that whenever you kill an opposing Geodude, it increments Game Variable XXX (where XXX needs to be replaced with a specific reserved number).

    But I suspect that, what you really want, is an achievement for killing a certain number of Geodude's.
    In the file Achievement Procs, find the function
    Code:
      def pbFaint(*args)
    and add this line at the end:
    Code:
        Achievements.incrementProgress("KILLED_GEODUDE",1) if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
    This one increments the achievement "KILLED_GEODUDE". So we need to create that achievement. Go to the file Achievement_Module, and find the definition of the list:
    @achievementList
    Go at the end of its definition:
    Code:
        "FAINTED_POKEMON"=>{
          "id"=>13,
          "name"=>"I Hope You're Not Doing a Nuzlocke",
          "description"=>"Have your Pokémon faint.",
          "goals"=>[100,250,500]
        }
      }
    There are two consecutive "}" symbols; you need to define a new achievement between them:
    Code:
        "FAINTED_POKEMON"=>{
          "id"=>13,
          "name"=>"I Hope You're Not Doing a Nuzlocke",
          "description"=>"Have your Pokémon faint.",
          "goals"=>[100,250,500]
        },
        # NEW ACHIEVEMENT (be careful to add a comma at the end of the previous line)
        "KILLED_GEODUDE"=>{
          "id"=>14,
          "name"=>"I Hate Geodude",
          "description"=>"Knock out many Geodude's.",
          "goals"=>[10, 25, 50]
        }
      }
    So now you will unlock an achiement for knocking out 10, 25 and 50 Geodudes.
     
  • 232
    Posts
    7
    Years
    • Seen Jun 2, 2024
    If I were to answer specifically your question, I would suggest some code like this, to be pasted somewhere:
    Code:
    class PokeBattle_Battler
      alias __Messi_count__pbFaint pbFaint
      def pbFaint(*args)
        __Messi_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX]
        $game_variables[XXX] += 1 if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
      end 
    end
    Basically it rewrites pbFaint so that whenever you kill an opposing Geodude, it increments Game Variable XXX (where XXX needs to be replaced with a specific reserved number).

    But I suspect that, what you really want, is an achievement for killing a certain number of Geodude's.
    In the file Achievement Procs, find the function
    Code:
      def pbFaint(*args)
    and add this line at the end:
    Code:
        Achievements.incrementProgress("KILLED_GEODUDE",1) if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
    This one increments the achievement "KILLED_GEODUDE". So we need to create that achievement. Go to the file Achievement_Module, and find the definition of the list:
    @achievementList
    Go at the end of its definition:
    Code:
        "FAINTED_POKEMON"=>{
          "id"=>13,
          "name"=>"I Hope You're Not Doing a Nuzlocke",
          "description"=>"Have your Pokémon faint.",
          "goals"=>[100,250,500]
        }
      }
    There are two consecutive "}" symbols; you need to define a new achievement between them:
    Code:
        "FAINTED_POKEMON"=>{
          "id"=>13,
          "name"=>"I Hope You're Not Doing a Nuzlocke",
          "description"=>"Have your Pokémon faint.",
          "goals"=>[100,250,500]
        },
        # NEW ACHIEVEMENT (be careful to add a comma at the end of the previous line)
        "KILLED_GEODUDE"=>{
          "id"=>14,
          "name"=>"I Hate Geodude",
          "description"=>"Knock out many Geodude's.",
          "goals"=>[10, 25, 50]
        }
      }
    So now you will unlock an achiement for knocking out 10, 25 and 50 Geodudes.

    Brother, you are a nice guy! Would you know how to define the catch for each geodude? Which line should I change for this?
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen today
    Brother, you are a nice guy! Would you know how to define the catch for each geodude? Which line should I change for this?

    I think this is where to increment the achievement (paste this somewhere):
    Code:
    module PokeBattle_BattleCommon
      alias __Messi_count__recordAndStore pbRecordAndStoreCaughtPokemon
      def pbRecordAndStoreCaughtPokemon
        # Increment achivements depending on what's been caught.
        @caughtPokemon.each do |pkmn|
          Achievements.incrementProgress("KILLED_GEODUDE",1) if pkmn.isSpecies?(:GEODUDE)
        end 
        __Messi_count__recordAndStore
      end 
    end
    The function pbRecordAndStoreCaughtPokemon updates the Pokédex and your PC when you catch a Pokémon, and this addition makes it also record your captured Pokémon. You can duplicate the code inside the function to different species.
    I haven't changed the name of the Achievement but I think you get the idea.
     
  • 232
    Posts
    7
    Years
    • Seen Jun 2, 2024
    Is the achievement system compatible with essentials v18?

    yea! read the conversation in his post. There you will see the struggle for the upgrade. But there is still a small bug regarding the opponent's achievement when using medicinal items, other than that, I didn't find any incompatibility.
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    I think this is where to increment the achievement (paste this somewhere):
    Code:
    module PokeBattle_BattleCommon
      alias __Messi_count__recordAndStore pbRecordAndStoreCaughtPokemon
      def pbRecordAndStoreCaughtPokemon
        # Increment achivements depending on what's been caught.
        @caughtPokemon.each do |pkmn|
          Achievements.incrementProgress("KILLED_GEODUDE",1) if pkmn.isSpecies?(:GEODUDE)
        end 
        __Messi_count__recordAndStore
      end 
    end
    The function pbRecordAndStoreCaughtPokemon updates the Pokédex and your PC when you catch a Pokémon, and this addition makes it also record your captured Pokémon. You can duplicate the code inside the function to different species.
    I haven't changed the name of the Achievement but I think you get the idea.

    What would be the script outside the achievement system? To identify the number of Pokémon captured? Please
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    I think this is where to increment the achievement (paste this somewhere):
    Code:
    module PokeBattle_BattleCommon
      alias __Messi_count__recordAndStore pbRecordAndStoreCaughtPokemon
      def pbRecordAndStoreCaughtPokemon
        # Increment achivements depending on what's been caught.
        @caughtPokemon.each do |pkmn|
          Achievements.incrementProgress("KILLED_GEODUDE",1) if pkmn.isSpecies?(:GEODUDE)
        end 
        __Messi_count__recordAndStore
      end 
    end
    The function pbRecordAndStoreCaughtPokemon updates the Pokédex and your PC when you catch a Pokémon, and this addition makes it also record your captured Pokémon. You can duplicate the code inside the function to different species.
    I haven't changed the name of the Achievement but I think you get the idea.

    What would be the script outside the achievement system? To identify the number of Pokémon captured? Please
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    If I were to answer specifically your question, I would suggest some code like this, to be pasted somewhere:
    Code:
    class PokeBattle_Battler
      alias __Messi_count__pbFaint pbFaint
      def pbFaint(*args)
        __Messi_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX]
        $game_variables[XXX] += 1 if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
      end 
    end
    Basically it rewrites pbFaint so that whenever you kill an opposing Geodude, it increments Game Variable XXX (where XXX needs to be replaced with a specific reserved number).

    But I suspect that, what you really want, is an achievement for killing a certain number of Geodude's.
    In the file Achievement Procs, find the function
    Code:
      def pbFaint(*args)
    and add this line at the end:
    Code:
        Achievements.incrementProgress("KILLED_GEODUDE",1) if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
    This one increments the achievement "KILLED_GEODUDE". So we need to create that achievement. Go to the file Achievement_Module, and find the definition of the list:
    @achievementList
    Go at the end of its definition:
    Code:
        "FAINTED_POKEMON"=>{
          "id"=>13,
          "name"=>"I Hope You're Not Doing a Nuzlocke",
          "description"=>"Have your Pokémon faint.",
          "goals"=>[100,250,500]
        }
      }
    There are two consecutive "}" symbols; you need to define a new achievement between them:
    Code:
        "FAINTED_POKEMON"=>{
          "id"=>13,
          "name"=>"I Hope You're Not Doing a Nuzlocke",
          "description"=>"Have your Pokémon faint.",
          "goals"=>[100,250,500]
        },
        # NEW ACHIEVEMENT (be careful to add a comma at the end of the previous line)
        "KILLED_GEODUDE"=>{
          "id"=>14,
          "name"=>"I Hate Geodude",
          "description"=>"Knock out many Geodude's.",
          "goals"=>[10, 25, 50]
        }
      }
    So now you will unlock an achiement for knocking out 10, 25 and 50 Geodudes.

    I am testing this with Elite Battle DX but this error appears to me whenever any Pokemon of mine faints ...
    ---------------------------
    Essentials
    ---------------------------
    [Pokémon Essentials version 18.1]

    [EBDX v1.0.15]

    Exception: SystemStackError

    Message: stack level too deep



    Backtrace:

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '

    PField_EncounterModifiers: 310: in `__Messi_count__pbFaint '



    This exception was logged in

    C: \ Users \ USERNAME \ Saved Games \ Essentials \ errorlog.txt.

    Press Ctrl + C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen today
    I am testing this with Elite Battle DX but this error appears to me whenever any Pokemon of mine faints ...

    Can you search for every definition of def pbFaint and post a screen of the search results? (Not the code, just the search results).
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    I think this is where to increment the achievement (paste this somewhere):
    Code:
    module PokeBattle_BattleCommon
      alias __Messi_count__recordAndStore pbRecordAndStoreCaughtPokemon
      def pbRecordAndStoreCaughtPokemon
        # Increment achivements depending on what's been caught.
        @caughtPokemon.each do |pkmn|
          Achievements.incrementProgress("KILLED_GEODUDE",1) if pkmn.isSpecies?(:GEODUDE)
        end 
        __Messi_count__recordAndStore
      end 
    end
    The function pbRecordAndStoreCaughtPokemon updates the Pokédex and your PC when you catch a Pokémon, and this addition makes it also record your captured Pokémon. You can duplicate the code inside the function to different species.
    I haven't changed the name of the Achievement but I think you get the idea.

    I found another __Messi_count, I duplicated to select another Pokémon. But I realized that this was causing the error, thanks for inducing me to answer!

    Now about the script that records the number of Pokémon captured, this I could not do without the system of achievements inserted, can you give me the strength to remove it and do it with a variable equal to this fainting counter?
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen today
    I found another __Messi_count, I duplicated to select another Pokémon. But I realized that this was causing the error, thanks for inducing me to answer!

    Now about the script that records the number of Pokémon captured, this I could not do without the system of achievements inserted, can you give me the strength to remove it and do it with a variable equal to this fainting counter?

    You can do this by adapting the code I gave ealier:
    Code:
    class PokeBattle_Battler
      alias __Messi_count__pbFaint pbFaint
      def pbFaint(*args)
        __Messi_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX]
        $game_variables[XXX] += 1 if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
      end 
    end
    Do you know ruby? How much do you want me to guide you through?
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    You can do this by adapting the code I gave ealier:
    Code:
    class PokeBattle_Battler
      alias __Messi_count__pbFaint pbFaint
      def pbFaint(*args)
        __Messi_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX]
        $game_variables[XXX] += 1 if [email protected]?(self.index) && self.isSpecies?(:GEODUDE)
      end 
    end
    Do you know ruby? How much do you want me to guide you through?

    No, I'm going to start my college this second semester of the year. I will learn programming and focus on ruby. I still don't know how to create codes.
    I can currently see a problem just by logic.
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen today
    No, I'm going to start my college this second semester of the year. I will learn programming and focus on ruby. I still don't know how to create codes.
    I can currently see a problem just by logic.
    You don't learn Ruby in college ^^

    I am still not sure of what you want. If you want a script to count whenever your Pokémon faints, something like this will do:

    Code:
    class PokeBattle_Battler
      alias __DarkraiMatter_count__pbFaint pbFaint # Rename the alias so it doesn't conflict.
      def pbFaint(*args)
        __DarkraiMatter_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX] # Here, XXX should be a reserved variable number specific to your game.
        $game_variables[XXX] += 1 if @battle.pbOwnedByPlayer?(self.index) # Here, if the Pokémon is owned by the player, we increase the related variable.
      end 
    end
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    You don't learn Ruby in college ^^

    I am still not sure of what you want. If you want a script to count whenever your Pokémon faints, something like this will do:

    Code:
    class PokeBattle_Battler
      alias __DarkraiMatter_count__pbFaint pbFaint # Rename the alias so it doesn't conflict.
      def pbFaint(*args)
        __DarkraiMatter_count__pbFaint(*args)
        $game_variables[XXX] = 0 if !$game_variables[XXX] # Here, XXX should be a reserved variable number specific to your game.
        $game_variables[XXX] += 1 if @battle.pbOwnedByPlayer?(self.index) # Here, if the Pokémon is owned by the player, we increase the related variable.
      end 
    end

    Sorry my English, this translator doesn't work very well.
    Yes, I saw that there is no ruby on the grid, I would have to study abroad, but I would know the logic of programming there.

    About the script I asked for, it is one that registers each Pokémon captured ^^
    For example:
    Register if I capture 5 geodudes,
    register if i capture 5 butterfree

    This way I will be able to do events that need catches.
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen today
    Sorry my English, this translator doesn't work very well.
    Yes, I saw that there is no ruby on the grid, I would have to study abroad, but I would know the logic of programming there.

    About the script I asked for, it is one that registers each Pokémon captured ^^
    For example:
    Register if I capture 5 geodudes,
    register if i capture 5 butterfree

    This way I will be able to do events that need catches.

    Sorry I was busy ^^
    Paste this in a new script above Main:
    Code:
    # This dictionary will store the count of Pokémons that you have caught.
    # To access the count for Kabutops for example: 
    # $CatchCount[PBSpecies::KABUTOPS]
    # If the Pokémon has a different form, then that form will have a different count.
    $CatchCount = {}
    
    alias __darkrai_matter_pbRecordAndStoreCaughtPokemon pbRecordAndStoreCaughtPokemon
    def pbRecordAndStoreCaughtPokemon
      # Adds the species to the counter.
      @caughtPokemon.each { |pkmn|
        $CatchCount[pkmn.fSpecies] = 0 if !$CatchCount[pkmn.fSpecies]
        $CatchCount[pkmn.fSpecies] += 1
      }
      # Run the normal function. 
      return __darkrai_matter_pbRecordAndStoreCaughtPokemon
    end
    Be careful though, when using this Hash $CatchCount.
    When you check the number of Pokémon caught, if you haven't caught any, you need to check if $CatchCount[PBSpecies::KABUTOPS] is not nil. If you want to access the number of captured Pokémon, you should do something like this:

    Code:
    number = $CatchCount[PBSpecies::KABUTOPS] || 0

    This way, the "number" will always be 0 if the Pokémon wasn't caught.
     
  • 107
    Posts
    3
    Years
    • Seen Apr 27, 2023
    Sorry I was busy ^^
    Paste this in a new script above Main:
    Code:
    # This dictionary will store the count of Pokémons that you have caught.
    # To access the count for Kabutops for example: 
    # $CatchCount[PBSpecies::KABUTOPS]
    # If the Pokémon has a different form, then that form will have a different count.
    $CatchCount = {}
    
    alias __darkrai_matter_pbRecordAndStoreCaughtPokemon pbRecordAndStoreCaughtPokemon
    def pbRecordAndStoreCaughtPokemon
      # Adds the species to the counter.
      @caughtPokemon.each { |pkmn|
        $CatchCount[pkmn.fSpecies] = 0 if !$CatchCount[pkmn.fSpecies]
        $CatchCount[pkmn.fSpecies] += 1
      }
      # Run the normal function. 
      return __darkrai_matter_pbRecordAndStoreCaughtPokemon
    end
    Be careful though, when using this Hash $CatchCount.
    When you check the number of Pokémon caught, if you haven't caught any, you need to check if $CatchCount[PBSpecies::KABUTOPS] is not nil. If you want to access the number of captured Pokémon, you should do something like this:

    Code:
    number = $CatchCount[PBSpecies::KABUTOPS] || 0

    This way, the "number" will always be 0 if the Pokémon wasn't caught.

    Thank you St. Cooler, it helped a lot!
     
    Back
    Top