• 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.

Randomly chosen trainer teams?

32
Posts
9
Years
    • Seen Mar 23, 2024
    So I've been thinking about ways to make my game more challenging, and one method I thought about was making it so that trainers used different Pokemon each time.

    For instance, we are battling a trainer with 6 Pokemon. (Let's make it a rematch against the Water gym). Let's say this gym leader has 10 Pokemon to choose from, including their lead and their ace. Here is an example of what you could be up against.
    272.png
    423.png
    350.png
    593-f.png
    581.png
    689.png
    130.png
    131.png

    Lead:
    186.png

    Ace:
    171.png


    So this trainer will always start with Politoed, and will always use Lanturn. The rest of the team are randomly picked; one battle, you may be facing Gastrodon, Lapras, Ludicolo and Gyarados; the next battle may put you against a different team, and so on.

    Rather than having to define 62 trainers just for this battle (yes, there are 62 possible combinations {D:}), does anyone know a script I can use to help me with this? Thanks :)
     
    824
    Posts
    8
    Years
  • Step 1.) Download this script, which allows you to write code for custom trainers.

    Step 2.) Add this code to the custom trainers script:
    Code:
    # lead and ace are the species of the trainer's lead and ace Pokemon, respectively
    # possibilities is an array with all the possible choices.  Defaults to empty
    # number is the total number of Pokemon on the team.  Defaults to six.
    # - this value does include the lead and the ace, so add 2.
    # - the code has error handlers that prevent the creation of teams larger than six, or of teams larger than the array above will allow.
    # name is the trainer's name.  Defaults to Bobby
    # class is the type of trainer they are (Ace Trainer, Gym Leader, etc.).  Defaults to Youngster.
    
    # This version of the code is for making the Pokemon have "default" moves.
    # Easier to use, but less precise
    def defaultRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",class=PBTrainers::YOUNGSTER)
      # Allow for multiple types of inputting species types
      # numbers, strings of the Pokemon's name, or the internal name
      if lead.is_a?(String) || lead.is_a?(Symbol)
        lead=getConst(PBSpecies,lead)
      end
      if ace.is_a?(String) || ace.is_a?(Symbol)
        lead=getConst(PBSpecies,ace)
      end
      for i in 0...possibilities.length
        if possibilities[i].is_a?(String) || possibilities[i].is_a?(Symbol)
          possibilities[i]=getConst(PBSpecies,possibilities[i])
        end
      end
      # Allow for multiple methods of inputting trainer type names
      if class.is_a?(String) || class.is_a?(Symbol)
        class=getConst(PBTrainers,class)
      end
      # create the "lead" pokemon
      poke1=createPokemon(lead,64) # change the 64 to be the level you want the Pokemon to be
      team=[poke1]
      # create the "grunt" pokemon
      grunts=[possibilities.length,number-2,4].min
      if grunts>0
        for i in 0...grunts
          # choosing a random Pokemon from the list of possibilities
          poke=rand(possibilities.length)
          poke2=createPokemon(possibilities[poke],64) # again, change 64 to the proper level
          team.push(poke2)
          # removing the chosen Pokemon from the list of possibilities so it doesn't get picked again.
          possibilities[poke]=nil
          possibilities.compact!
        end
      end
      # create the "ace" pokemon
      poke3=createPokemon(ace,64) # change the 64 to be the level you want the Pokemon to be
      team.push(poke3)
      # create the trainer
      return createTrainer(class,name,team)
    end
    
    # this version of the code allows you to define Pokemon complete with moves, specific abilities, etc.
    # more custom and precise, but requires more initialization
    def definedRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",class=PBTrainers::YOUNGSTER)
      # Allow for multiple methods of inputting trainer type names
      if class.is_a?(String) || class.is_a?(Symbol)
        class=getConst(PBTrainers,class)
      end
      # add the lead
      team=[lead]
      # add the grunts
      grunts=[possibilities.length,number-2,4].min
      if grunts>0
        for i in 0...grunts
          # choosing a random Pokemon from the list of possibilities
          poke=rand(possibilities.length)
          team.push(possibilities[poke])
          # removing the chosen Pokemon from the list of possibilities so it doesn't get picked again.
          possibilities[poke]=nil
          possibilities.compact!
        end
      end
      # add the ace
      team.push(ace)
      # create the trainer
      return createTrainer(class,name,team)
    end

    I use a similar method to make the rival in my game. Certain decisions you make in the game's story - obviously which starter you pick, but also other things such as what you evolve your Eevee into, or which fossil you revive first - affect the rival's team. Your 62 combinations has nothing on my 2,200+ combinations.
     
    32
    Posts
    9
    Years
    • Seen Mar 23, 2024
    Step 1.) Download this script, which allows you to write code for custom trainers.

    Step 2.) Add this code to the custom trainers script:
    Code:
    # lead and ace are the species of the trainer's lead and ace Pokemon, respectively
    # possibilities is an array with all the possible choices.  Defaults to empty
    # number is the total number of Pokemon on the team.  Defaults to six.
    # - this value does include the lead and the ace, so add 2.
    # - the code has error handlers that prevent the creation of teams larger than six, or of teams larger than the array above will allow.
    # name is the trainer's name.  Defaults to Bobby
    # class is the type of trainer they are (Ace Trainer, Gym Leader, etc.).  Defaults to Youngster.
    
    # This version of the code is for making the Pokemon have "default" moves.
    # Easier to use, but less precise
    def defaultRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",class=PBTrainers::YOUNGSTER)
      # Allow for multiple types of inputting species types
      # numbers, strings of the Pokemon's name, or the internal name
      if lead.is_a?(String) || lead.is_a?(Symbol)
        lead=getConst(PBSpecies,lead)
      end
      if ace.is_a?(String) || ace.is_a?(Symbol)
        lead=getConst(PBSpecies,ace)
      end
      for i in 0...possibilities.length
        if possibilities[i].is_a?(String) || possibilities[i].is_a?(Symbol)
          possibilities[i]=getConst(PBSpecies,possibilities[i])
        end
      end
      # Allow for multiple methods of inputting trainer type names
      if class.is_a?(String) || class.is_a?(Symbol)
        class=getConst(PBTrainers,class)
      end
      # create the "lead" pokemon
      poke1=createPokemon(lead,64) # change the 64 to be the level you want the Pokemon to be
      team=[poke1]
      # create the "grunt" pokemon
      grunts=[possibilities.length,number-2,4].min
      if grunts>0
        for i in 0...grunts
          # choosing a random Pokemon from the list of possibilities
          poke=rand(possibilities.length)
          poke2=createPokemon(possibilities[poke],64) # again, change 64 to the proper level
          team.push(poke2)
          # removing the chosen Pokemon from the list of possibilities so it doesn't get picked again.
          possibilities[poke]=nil
          possibilities.compact!
        end
      end
      # create the "ace" pokemon
      poke3=createPokemon(ace,64) # change the 64 to be the level you want the Pokemon to be
      team.push(poke3)
      # create the trainer
      return createTrainer(class,name,team)
    end
    
    # this version of the code allows you to define Pokemon complete with moves, specific abilities, etc.
    # more custom and precise, but requires more initialization
    def definedRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",class=PBTrainers::YOUNGSTER)
      # Allow for multiple methods of inputting trainer type names
      if class.is_a?(String) || class.is_a?(Symbol)
        class=getConst(PBTrainers,class)
      end
      # add the lead
      team=[lead]
      # add the grunts
      grunts=[possibilities.length,number-2,4].min
      if grunts>0
        for i in 0...grunts
          # choosing a random Pokemon from the list of possibilities
          poke=rand(possibilities.length)
          team.push(possibilities[poke])
          # removing the chosen Pokemon from the list of possibilities so it doesn't get picked again.
          possibilities[poke]=nil
          possibilities.compact!
        end
      end
      # add the ace
      team.push(ace)
      # create the trainer
      return createTrainer(class,name,team)
    end

    I use a similar method to make the rival in my game. Certain decisions you make in the game's story - obviously which starter you pick, but also other things such as what you evolve your Eevee into, or which fossil you revive first - affect the rival's team. Your 62 combinations has nothing on my 2,200+ combinations.

    Cheers dude :)

    I don't have a lot of experience with code tbh, could you give me an example of how I could implement this as I'm not sure how (Feel free to use the example in my original post!)
    It would be preferable if the example utilised the code that allows custom movesets.
    Thanks in advance
     
    Last edited:
    824
    Posts
    8
    Years
  • The script I had you download shows you how to use this in an event. However, instead of the second bit of scripting (the one that starts with p0 = createPokemon("KLANG",38)), make a script that looks like this:

    Code:
    trainer = defaultRandomTeam(
    [COLOR="Red"]"POLITOED"[/COLOR],[COLOR="DarkOrange"]"LANTURN"[/COLOR],[COLOR="SeaGreen"][[/COLOR][COLOR="Lime"]"LUDICOLO",
    "MILOTIC","GASTRODON","JELLICENT",
    "SWANNA","BARBARACLE","GYARADOS",
    "LAPRAS"[/COLOR][COLOR="seagreen"]][/COLOR],[COLOR="Blue"]6[/COLOR],[COLOR="Purple"]"Bob"[/COLOR],[COLOR="Magenta"]"GYMLEADER"[/COLOR])
    result = customTrainerBattle(trainer)
    pbSet(1,result==BR_WIN ? 0 : 1)


    You have:
    their lead and ace
    their other options (Don't forget the brackets)
    the total number of Pokemon on their team
    their name and trainer type
     
    32
    Posts
    9
    Years
    • Seen Mar 23, 2024
    So how would I go about giving the Pokemon custom moves, items and abilities? And just out of curiosity is this code compatible with any custom EV scripts? Sorry if I'm asking too much.

    EDIT: On another note, the script you gave me doesn't seem to be working. I added the custom trainers script to my game, then I added your bit on to the end like you said, now it's crashing the game, telling me I'm getting syntax errors. Is there something else I should have done?
     
    Last edited:
    824
    Posts
    8
    Years
  • It would be preferable if the example utilised the code that allows custom movesets.
    Thanks in advance

    Of course you say this as I'm typing an example of the simpler version.

    Okay, well then.

    Step 1.) Create a new script section directly below the one where you added the Custom Trainer script. Add this to it:
    Code:
    def waterLeaderRematch
    [COLOR="Red"]  lead=createPokemon(:POLITOED,64)
      lead.setAbility(2) # give Hidden Ability (Water Absorb)[/COLOR]
    [COLOR="Orange"]  ace=createPokemon(:LANTURN,64)
      ace.item=getConst(PBItems,:ASSAULTVEST) # give it the item Assault Vest[/COLOR]
    [COLOR="Lime"]  grunt1=createPokemon(:LUDICOLO,64)
      grunt1.makeMale # make it male
      grunt1.name="Miror B" # nickname it Miror B
      grunt2=createPokemon(:GASTRODON,64)
      grunt2.form=0 # give it the first form, for East Sea
      grunt3=createPokemon(:MILOTIC,64)
      grunt3.makeFemale # make it female
      grunt3.makeShiny # make it shiny
      grunt4=createPokemon(:JELLICENT,64)
      # Note that in Essentials, the stats go in this order:
      # HP, Attack, Defense, Speed, SpAtk, SpDef
      # Most Pokemon things list Speed at the end, so don't make the mistake of directly copying
      grunt4=ev=[248,0,216,44,0,0] # set the EVs
      grunt5=createPokemon(:SWANNA,64)
      grunt5.iv=[31,31,31,31,30,30] # give it Hidden Power Ground
      grunt5.pbLearnMove(:HIDDENPOWER) # teach it Hidden Power
      grunt6=createPokemon(:BARBARACLE,64)
      grunt6.setNature(:ADAMANT)  # give it an Adamant nature
      grunt7=createPokemon(:GYARADOS,64)
      # Allow the Gyarados to Mega Evolve
      grunt7.item=getConst(PBItems,:GYARADOSITE) if hasConst?(PBItems,:GYARADOSITE)
      grunt8=createPokemon(:LAPRAS,64)[/COLOR]
    [COLOR="SeaGreen"]  grunts=[[COLOR="Lime"]grunt1,grunt2,grunt3,grunt4,grunt5,grunt6,grunt7,grunt8[/COLOR]][/COLOR]
      return definedRandomTeam([COLOR="Red"]lead[/COLOR],[COLOR="Orange"]ace[/COLOR],[COLOR="SeaGreen"]grunts[/COLOR],[COLOR="Blue"]6[/COLOR],[COLOR="Purple"]"Bob"[/COLOR],[COLOR="Magenta"]:GYMLEADER[/COLOR])
    end
    Note that you need to write a function like this for any trainer that you want to use custom movesets in a randomly-generated battle.

    Note also that I tried to give examples of anything that could be useful. Ability changes, form changes, gender changes, EVs and IVs, learning a move, nicknames, Mega Evolution, other items, etc.

    Step 2.) In the event, follow the instructions in the script I linked. Instead of the second script section (the one that starts with p0 = createPokemon("KLANG",38)), make a script that looks like this:
    Code:
    result = customTrainerBattle(waterLeaderRematch)
    pbSet(1,result==BR_WIN ? 0 : 1)
     
    824
    Posts
    8
    Years
  • EDIT: On another note, the script you gave me doesn't seem to be working. I added the custom trainers script to my game, then I added your bit on to the end like you said, now it's crashing the game, telling me I'm getting syntax errors. Is there something else I should have done?

    can you be specific here on what the syntax errors are? Screenshot, possibly?
     
    32
    Posts
    9
    Years
    • Seen Mar 23, 2024
    can you be specific here on what the syntax errors are? Screenshot, possibly?

    The error is apparently at the very first line of code from the added part, which is this line:
    def defaultRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",class=PBTrainers::YOUNGSTER)
     
    32
    Posts
    9
    Years
    • Seen Mar 23, 2024
    When I start up the game, it just says:
    "Script 'customtrainers' line 216: SyntaxError occured"
     
    30
    Posts
    10
    Years
    • Seen Apr 9, 2023
    I don't suppose there was any update on this or end to this conversation that took place here, was there?
    I liked the idea laid out in this thread, but have the same syntax error as the OP and can't seem to figure out whats wrong with the syntax of that line.

    edit - Forget it, I figured it out. Seems like it was some error with the word "class." I'm a novice with all this, but I just changed it to "trainerid" like the original script linked to here used. Just look for all the subsequent times its labeled "class" and change it. It should be easy, because the text is blue, for some reason. Why is that? I imagine if I knew, I would have understood the error immediately, haha.

    Anyway, after that it works well. Only problem is the level. Its defining the level in the global scripts, so I'd need to find a way to change that on a trainer to trainer basis otherwise it seems pretty restricted.
     
    Last edited:
    13
    Posts
    8
    Years
    • Seen Mar 22, 2024
    At this point it doesn't really matter to Op, but for everyone who wants to implement this script there you go.
    Spoiler:
     
    1
    Posts
    2
    Years
    • Seen Jun 19, 2022
    Exception: NameError
    Message: Section185:266:in `definedRandomTeam'undefined local variable or method `possibilities' for #<Interpreter:0xc80dcf8>

    ***Full script:

    result = customTrainerBattle(waterLeaderRematch)
    pbSet(1,result==BR_WIN ? 0 : 1)
    Interpreter:243:in `pbExecuteScript'
    waterLeaderRematch:25:in `waterLeaderRematch'
    (eval): 1:in `pbExecuteScript'
    Interpreter:1606:in `eval'
    Interpreter:243:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:103:in `updateold'
    Scene_Map:101:in `loop'
    Scene_Map:114:in `updateold'
    Time:155:in `update'


    Help
     
    Back
    Top