• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Serena, Kris, Dawn, Red - which Pokémon protagonist is your favorite? Let us know by voting in our grand final favorite protagonist poll!
  • PokéCommunity supports the Stop Killing Games movement. If you're a resident of the UK or EU, consider signing one of the petitions to stop publishers from destroying games. Click here for more information!
  • 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] Changing the frequency of battle AI switching

  • 1
    Posts
    5
    Years
    • Seen Apr 1, 2020
    So, I know very little about scripting. I've only read a very basic introduction to Ruby, and tried to study the scripts that come with essentials, so I might be way off here, but hopefully what I want to do is doable. What I'm trying to do is make it so that opposing trainers more frequently switch out their pokemon if they have a better one. This is more in line with how Pokemon is played competitively, and would, I believe, make the battles more strategic.

    My thinking was that the best way to go about doing this would be to check if the best pokemon against the player's was a different one than the active pokemon, and if so switch it out a certain percent of the time (65%).

    [PokeCommunity.com] Changing the frequency of battle AI switching
    [PokeCommunity.com] Changing the frequency of battle AI switching

    I defined a new method pbBetterPokemon which is identical to pbChooseBestNewEnemy except for what's marked with red, as I find the AI does a good job finding the best new enemy when one has fainted. I set the method to be true if best pokemon is different than active pokemon, and false if else (at least I hope that's what I've done).

    Then I added a couple of lines to pbEnemyShouldWithdrawEx? where I say that if there is a better pokemon available, and a random number generator is below 65 out of a hundred then shouldswitch=true.

    The good news is that opposing pokemon do switch out about 65% of the time. The bad news is that they don't switch to the best available pokemon, and if they do they will swap that one out as well even though no other pokemon are better. So what am I doing wrong here? Any help would be highly appreciated :)
     
    Last edited:
    At the very least, you mean if pbBetterPokemon==true && pbAIRandom(100)<65. Using a single = is setting a variable called pbBetterPokemon to true. (Side note, you should be able to write pbBetterPokemon instead of pbBetterPokemon==true, IIRC they should mean the same thing).
     
    Back
    Top