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

Is it possible to have an instance in a game where the player takes control of a different character?

6
Posts
8
Years
    • Seen Sep 4, 2016
    Now this may be a bizarre question to be asking, but would it be possible for there to be an instance in a game where the player would take control of a different character, with an already set team for a boss fight or something, and then return to the player with whatever their party is? The reason I'm asking this is there's a point in a game I'm working on where the rival would take on an adversary of theirs, and instead of being a battle where the player partners up with them I'd want the player to straight up take control of them for a single battle. If it's not possible, ah well, I guess I'll settle for a partner battle.

    EDIT: If it is possible, I assume it would be possible to also make the IVs, natures, and abilities of this temporary party set in stone as well, correct?
     
    Last edited:
    129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    It is possible, but Essentials is not built for multiple protagonists, so there may be a lot of latent bugs. And it will require some amount of coding, so if that's not your thing, you should rethink the design.

    Here's some details to help: The player protagonist is an instance of PokeBattle_Trainer stored in the $Trainer global variable. (Every trainer you battle is initialized into a PokeBattle_Trainer before the battle, but the player's character is the only one that sticks around after a battle in an unmodified Essentials game.)

    The PokeBattle_Trainer class holds a trainer's party, their id, their trainer type, their badges, money, and pokedex information. It does NOT hold their bag or items. The player's bag is stored in a PokemonBag object stored in the $PokemonBag global variable. (The Pokemon and Item Storage systems are stored in separate variables still, but if the second character never has the chance to access a PC, then you won't need to worry about those.)

    So, in order to set up a new player character, you simply need to create new PokeBattle_Trainer and PokemonBag objects, stored off somewhere. You can make new pokemon with whatever moves, IVs, items, backstory, whatever that you want and slot them into the trainer object's party array. You set the trainer's name by simply assigning a string to the object's name property (DO NOT use pbTrainerName, as that has a lot of side effects).

    When you want to switch to the secondary character, assign the contents of the $Trainer and $PokemonBag variables to another variable, in some place that will be saved, like a global variable. Then assign these secondary trainer and bag objects to the $Trainer and $PokemonBag variables. From that point on, the player has switched to the other character, including name, trainer id, badges, party, etc. To switch back, it's the same swapping around variables.

    I don't want to give any concrete code until I've tried this protagonist swapping myself (because there's bound to be a few dozen bugs from latent variables). I've used spare PokeBattle_Trainer for a "living rival" system I'm playing around with for my own game, so I know the trainer stuff works.
     
    119
    Posts
    10
    Years
    • Seen Sep 1, 2023
    This is quite easily doable. I've made an entire character switching system in my game which saves positions of all characters with their own pkmn, items, storage, etc. and the player can switch between them, have them trade pkmn and items, battle, and even team up. For what you want to do you wouldn't need that entire system (besides it isn't really plug 'n play).

    If you just want to switch the player character to the other guy, and not control both characters in a double battle, add the following code above main:

    Code:
    ################################################################################
    # Script by Badhaas
    # this is a very bare bones version of my entire script which is adapted to
    # use $game_variables instead of its own class. It has a unique trainer and bag.
    #
    # How to use:
    # - Before using this script call 'cdCharacterDataSetup'!!!
    # - You can change the variable IDs used below
    # - Call 'cbNewChar(id,save,name)' to create a new character and switch to it.
    #   - id = the id in the pokemon trainers data (determines how it looks like).
    #   - save = whether to save the current character. Always do this!
    #   - name = sets the name for it, if none used the player gets to name them.
    # - Call 'cdSwitchChar(id)' to switch to another character. If the character
    #   doesn't exist a new one is created (though the name can't be set).
    #   - id = the id of the character switched to.
    # 
    # Note: the original player character is ID = 0
    
    # Change Variable ID's here:
      TRAINERDATA_VARIABLE_ID = 10  #Global variable used to store $trainer
      BAGDATA_VARIABLE_ID = 11      #Global variable used to store $bag
      CURCHAR_VARIABLE_ID = 12      #Global variable used to track current character
                                    # Note: the original player character is ID = 0
    
    # DONT EDIT BELOW THIS LINE
      
      # Initial setup
      def cdCharacterDataSetup
        $game_variables[TRAINERDATA_VARIABLE_ID] = []
        $game_variables[BAGDATA_VARIABLE_ID] = []
        $game_variables[CURCHAR_VARIABLE_ID] = 0
      end
    
      # Switch between characters
      # Note: the original player character is ID = 0
      def cdSwitchChar(id)
        cdSaveChar($game_variables[CURCHAR_VARIABLE_ID])
        # check if the new character exists
        if $game_variables[TRAINERDATA_VARIABLE_ID][id]
          cdLoadChar(id)
        else #if the character doesn't exist already
          cbNewChar(id,false)
        end
      end  #end switch char
    
      def cdSaveChar(id=$game_variables[CURCHAR_VARIABLE_ID])
        #Save bag and trainer data
        $game_variables[TRAINERDATA_VARIABLE_ID][id] = $Trainer
        $game_variables[BAGDATA_VARIABLE_ID][id] = $PokemonBag
      end
      
      def cdLoadChar(id)
        #Load bag and trainer data
        $Trainer = $game_variables[TRAINERDATA_VARIABLE_ID][id]
        $PokemonBag = $game_variables[BAGDATA_VARIABLE_ID][id]
    	
        #Set the new character ID
        $game_variables[CURCHAR_VARIABLE_ID] = id
      end
      
      # Create a new character
      def cbNewChar(id,save=true,name=nil)
        if save
          cdSaveChar($game_variables[CURCHAR_VARIABLE_ID])
        end
        
        #Create a new character
        pbChangePlayer(id)
        pbTrainerName(name)
        $Trainer.id=rand(256)
        
        #Set the new character ID
        $game_variables[CURCHAR_VARIABLE_ID] = id
      end  #end create char

    After using the above code (instructions included) you can use all the regular stuff to edit the character. Thus you can use the silent give pokemon to give them 6 pokemon and set their party this way. You can also give them items, etc. Do note a pokemon storage isn't included, thus any pokemon beyond 6 they catch goes to the original player character's storage and visiting the PC does the same.

    To add to that you could use my Event placement script if you want to still keep the other character on the map and have them switch anywhere. If it's just on fixed occasions (and thus no need for it to be this dynamic) you can just create that illusion with regular events.
     
    Last edited:

    Seth Pegasus

    Creator of Pokemon: The Conspiracy.
    83
    Posts
    11
    Years
    • Seen Aug 24, 2021
    Wow, great information here guys. This will be useful in my game as well. Thanks.
     
    Back
    Top