• 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] Storing opposing trainer's pkmn?

  • 132
    Posts
    9
    Years
    Checking for the trainer's own pokémon can be done in-event easily. But for an opposing trainer I've had no luck storing his pokémon as a variable. I familiarized myself with PokemonTrainers a bit, but storing poke as a variable seems to only return the pokémon's numerical attributes from Trainers.txt.(Speaking of, it'd be rather nice to add an attribute to Trainers.txt, like an 18th one: "game variable." That would just be more efficient.)

    And then I believe pbAddPokemon(variable) or pbAddPokemon(pbGet(variable)) will not work, right? Please, anyone. Thanks!
     
    Last edited by a moderator:
  • 129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    Not sure what you're asking for here. Lemme set a baseline:

    Opposing trainers are nothing more than the various data you define for them (including the minimum pokemon species and level) right up until the point you call pbTrainerBattle. One of the first things that method does is call pbLoadTrainer to actualize the trainer into a PokeBattle_Trainer and several PokeBattle_Pokemon. Usually, this trainer object and his pokemon are left for the garbage collector once the pbTrainerBattle method exits (after the battle is finished).

    If you want to actualize a trainer before a battle, or in a context not associated with a battle, you could very well call pbLoadTrainer yourself and keep track of the array of [trainerObject, itemList, partyArray] it returns yourself. Making that trainer into a battle, however, would require you to tweak or remake the pbTrainerBattle method to accept the info previously mentioned.

    What are you trying to do anyway, out of curiosity?
     
  • 132
    Posts
    9
    Years
    After the player starts a battle with a trainer, I want the trainer's pokémon to be immediately stored as individual variables. Because, if the player wins he's rewarded with, for example, one of the opposing pokémon (with the same level, gender, nature, moves, etc.) to take as his own.

    Do you mean I should use pbLoadTrainer(trainerid,trainername,partyid=0) instead of pbTrainerIntro in the trainer event?

    EDIT: I guess it's impossible to store multiple attributes in one variable ;_;
     
    Last edited:
  • 129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    pbTrainerIntro is entirely unrelated. That function plays the trainer's encounter music and stops all other events on the map from moving.

    So, what you can do is you can edit the pbTrainerBattle script to store off the trainer in the event of a win. Something like this:

    Code:
    # Add this somewhere
    class PokemonTemp
      attr_accessor :lastTrainerPokemon
    end
    
    # Find this code in the PTrainer_NPCTrainers script section:
    def pbTrainerBattle(trainerid,trainername,endspeech,
                        doublebattle=false,trainerparty=0,canlose=false,variable=nil)
    # [...]
      Input.update
      pbSet(variable,decision)
      $PokemonTemp.waitingTrainer=nil
      $PokemonTemp.lastTrainerPokemon=trainer[2] #Store off the trainer's array of pokemon
      return (decision==1)
    end

    And then, in your win condition block, you can use the array of pokemon stored in $PokemonTemp.lastTrainerPokemon. Something like:

    Code:
    if $PokemonTemp.lastTrainerPokemon && !pbBoxesFull?
    pbFadeOutIn(99999){
      #Open a party selection screen, with the opponent's party
      scene=PokemonScreen_Scene.new
      screen=PokemonScreen.new(scene,$PokemonTemp.lastTrainerPokemon)
      screen.pbStartScene(_INTL("Which Pokémon would you like?"),false)
      loop do
        scene.pbSetHelpText(_INTL("Which Pokémon would you like?"))
        chosen=screen.pbChoosePokemon
        if chosen>=0
          pokemon=$PokemonTemp.lastTrainerPokemon[chosen]
          if scene.pbDisplayConfirm(_INTL("Take {0}?", pokemon.name))
            # Add the foreign pokemon
            $Trainer.seen[pokemon.species]=true #Add to Pokedex
            $Trainer.owned[pokemon.species]=true
            pbStorePokemon(pokemon) #stores pokemon in party or boxes, if there's room
            break;
          end
        else
          #The player cancelled the selection
          break if scene.pbDisplayConfirm(_INTL("Decide against taking a Pokémon?"))
        end
      end
      $PokemonTemp.lastTrainerPokemon=nil #clear out the stored party
      screen.pbEndScene
    }
    else
      #Either the player can't store any more pokemon, or the last opponent's party wasn't stored off properly.
      Kernel.pbMessage(_INTL("Can't select a Pokémon!"))
    end

    Note: I haven't tested any of the above code. Most of it was copy-pasted from existing functions.
     
  • 132
    Posts
    9
    Years
    Oh wow, thanks. I hate to ask more questions but I do think I'm missing something here.
    Code:
    # Find this code in the PTrainer_NPCTrainers script section:
    def pbTrainerBattle(trainerid,trainername,endspeech,
                        doublebattle=false,trainerparty=0,canlose=false,variable=nil)
    # [...]
      Input.update
      pbSet(variable,decision)
      $PokemonTemp.waitingTrainer=nil
      $PokemonTemp.lastTrainerPokemon=trainer[2] #Store off the trainer's array of pokemon
      return (decision==1)
    end
    So I'm meant to add variable=nil. Does that mean I'd have to add a number there in the trainer event? Like ..."Endspeech.",false,0,false,39? And, would that match the number 2 from the aforementioned $PokemonTemp.lastTrainerPokemon=trainer[2]?

    And then, in your win condition block, you can use the array of pokemon stored in $PokemonTemp.lastTrainerPokemon.

    I can't seem to find this "win condition block" in the script section PokemonTrainers (I have an outdated essentials so my script section names might be different). Instead I put the script in PokeBattle_Battle after the player wins, but each time it returns "Can't select a Pokémon."
    Should that script be in the same script section as the previous one? Thanks again.
     
  • 129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    By "win condition block" I meant in your event, there's a condition command which has pbTrainerBattle as the script condition. The block in which you also set self switch "A" to on is where I was thinking. It would probably be better, actually, if you make a function in a new script section, put that code in there, and call the function from the event.

    What version of Essentials are you using? The variable=nil thing is part of the code in 16.1/2 already... The only thing I meant for you to add is the lastTrainerPokemon line...
     
  • 132
    Posts
    9
    Years
    Weird. I added the second script in PokemonTrainers after the (decision==1), and that seemed to work in conjunction with the same script in PokeBattle_Battle for some reason. ?? It pretty much works the way it is but I might as well make a new function for tidiness's sake.

    I have the Essentials from two years ago lol. But wouldn't updating it write over my custom scripts?
     
  • 129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    Yes, doing a blind copy-paste of the script file will overwrite all of your custom scripts. In order to properly update the thing, you have to basically manually copy-paste script from one project to another. (I wonder if there's a tool out there that can merge the files properly... I wonder how hard it would be to create one...?) I still have to update my own project from 16.1 to 16.2.

    You can certainly put the function definition anywhere (more or less), but I generally try and keep things in separate sections specifically for the whole updating thing.
     
    Back
    Top