• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • 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 the AI battle itself?

  • 12
    Posts
    8
    Years
    • Seen Jan 11, 2022
    So I saw a video by a YouTuber user named pimanrules where he took every trainer in pokemon red&blue and had them fight in a round-robin tournament. I thought it was really cool and it got me thinking "I could probably create something like this in pokemon essentials but with other generations and possibly maybe all of them if I'm crazy enough". I obviously wasn't going to go as far as him and do an entire tournament but I thought I could do something basic like having random trainers chosen from trainers.txt and they would automatically fight each other. After they fought, they would queue other trainers and it would repeat. Problem is, I know nothing about pokemon essentials/coding and how I would make the AI Battle itself. I couldn't find any public scripts that support v19 either so I was left coming here for help. What would be the process to code something like this and how do I get started?
     
    So I saw a video by a YouTuber user named pimanrules where he took every trainer in pokemon red&blue and had them fight in a round-robin tournament. I thought it was really cool and it got me thinking "I could probably create something like this in pokemon essentials but with other generations and possibly maybe all of them if I'm crazy enough". I obviously wasn't going to go as far as him and do an entire tournament but I thought I could do something basic like having random trainers chosen from trainers.txt and they would automatically fight each other. After they fought, they would queue other trainers and it would repeat. Problem is, I know nothing about pokemon essentials/coding and how I would make the AI Battle itself. I couldn't find any public scripts that support v19 either so I was left coming here for help. What would be the process to code something like this and how do I get started?

    Hey, it took me time but I remembered responding to a similar question.

    In the file PokeBattle_Battle, find the function:

    Code:
      def pbOwnedByPlayer?(idxBattler)
        return false if opposes?(idxBattler)
        return pbGetOwnerIndexFromBattlerIndex(idxBattler)==0
      end

    and add the line as follows:

    Code:
      def pbOwnedByPlayer?(idxBattler)
        return false if opposes?(idxBattler)
        return false if $game_switches[XXX] # Change to whatever free switch you have.
        return pbGetOwnerIndexFromBattlerIndex(idxBattler)==0
      end

    Now, I don't know much about v19 (I use v18.1 for my own project). Maybe this edit is enough, maybe not, but at least it's something to try.

    Now, if you want to make a battle AI VS AI, you need to set the corresponding switch (the XXX in the script) to ON before the battle, and switch it OFF after the battle. As for the battle itself, you will have to check the Essentials Docs (this page in particular).
     
    Hey, it took me time but I remembered responding to a similar question.

    In the file PokeBattle_Battle, find the function:

    Code:
      def pbOwnedByPlayer?(idxBattler)
        return false if opposes?(idxBattler)
        return pbGetOwnerIndexFromBattlerIndex(idxBattler)==0
      end

    and add the line as follows:

    Code:
      def pbOwnedByPlayer?(idxBattler)
        return false if opposes?(idxBattler)
        return false if $game_switches[XXX] # Change to whatever free switch you have.
        return pbGetOwnerIndexFromBattlerIndex(idxBattler)==0
      end

    Now, I don't know much about v19 (I use v18.1 for my own project). Maybe this edit is enough, maybe not, but at least it's something to try.

    Now, if you want to make a battle AI VS AI, you need to set the corresponding switch (the XXX in the script) to ON before the battle, and switch it OFF after the battle. As for the battle itself, you will have to check the Essentials Docs (this page in particular).
    Thank you for responding too this and helping me out. I am going too test this change out when I get back home in 3 days? (on vacation right now). Can I follow up with you if it works it or not? I know some people get really upset when people respond too an inactive thread so I just wanted too make sure that's alright.
     
    Thank you for responding too this and helping me out. I am going too test this change out when I get back home in 3 days? (on vacation right now). Can I follow up with you if it works it or not? I know some people get really upset when people respond too an inactive thread so I just wanted too make sure that's alright.
    A few days, a few weeks are ok, don't worry :)
    (A few years is not ok lol)
     
    A few days, a few weeks are ok, don't worry :)
    (A few years is not ok lol)
    Im back and I tried doing it. Everything happened as normal and nothing was affected. I assume its because it isn't toggled on by default. How would I do that?
    Here is what the code looks like too:
    [PokeCommunity.com] How do I make the AI battle itself?
     
    Im back and I tried doing it. Everything happened as normal and nothing was affected. I assume its because it isn't toggled on by default. How would I do that?

    So you made the script edits. Now, you have to toggle ON the corresponding switch before the battle.
    When you make a trainer just like here:
    1. Double-click on the "Conditional Branch: pbTrainerBattle(blah blah)" (the blue part in the screenshot)
    2. Click on "Control Switches", set switch 51 to ON.
    3. The Control Switch should appear BEFORE the blue part (yes, you double-clicked on the blue part, to make the switch appear before).
    4. Then, double-click on "pbTrainerEnd", "Control Switches", and set switch 51 to OFF.
     
    So you made the script edits. Now, you have to toggle ON the corresponding switch before the battle.
    When you make a trainer just like here:
    1. Double-click on the "Conditional Branch: pbTrainerBattle(blah blah)" (the blue part in the screenshot)
    2. Click on "Control Switches", set switch 51 to ON.
    3. The Control Switch should appear BEFORE the blue part (yes, you double-clicked on the blue part, to make the switch appear before).
    4. Then, double-click on "pbTrainerEnd", "Control Switches", and set switch 51 to OFF.

    Here's the thing though. I don't want this toggled for just one trainer. I want every battle I go into to be controlled by the AI. How can I apply it globally?

    Edit:
    I was able too find a way too apply it globally. Thank you so much!
     
    Last edited:
    Here's the thing though. I don't want this toggled for just one trainer. I want every battle I go into to be controlled by the AI. How can I apply it globally?

    Edit:
    I was able too find a way too apply it globally. Thank you so much!

    What did you end up doing?
    I could have sworn I saw a plugin for this yesterday but I can't find it anywhere now so I must have misread it yesterday
     
    What did you end up doing?
    I could have sworn I saw a plugin for this yesterday but I can't find it anywhere now so I must have misread it yesterday
    There are two plugins I found for this. One for 18.1 and one for 17.1
    (broken link removed)
    (broken link removed)
    As for what I did for 19.1. I had the conditional branch set too on upon starting the game.
     
    Back
    Top