Partner trainer

*For how to define a trainer, see Defining a trainer.*
This page describes **partner trainers**. It details both registering/deregistering a partner trainer (for battles) and making an event follow the player around.

## Setting a partner trainer up

Partner trainers are identical to any other trainer, so you should create them in exactly the same way as you would any other trainer. The only difference is in how they are used (they are an ally in battle rather than an opponent).

Partner trainers also require a back sprite, just like the player characters have back sprites. Back sprites are specific to trainer types, and are placed in the folder "Graphics/Trainers" with the name "XXX\_back.png", where "XXX" is the trainer type's ID.

Typically, partner trainers will have a trainer type unique to themselves (i.e. there are no other trainers in the game that share their trainer type). This is only a rule, though; you can have the player team up with a Bug Catcher if you want.

## Teaming up with a partner

This section explains how to make a partner trainer show up in battle alongside the player. See below for how to make them follow the player around.

Having a registered partner trainer will cause all wild battles to be double battles, and these plus any double trainer battles (either defined as a double battle or a case of two trainers spotting the player at the same time) will involve both the player and their partner against the opponent(s). 1v1 battles against a single trainer are unaffected, and the partner will not participate in those battles. In addition, the battle rule "noPartner" will ensure that a battle will not involve a partner trainer.

After every battle (even single ones which the partner didn't participate in), the player's party will be fully healed (ostensibly by the partner).

The player can only team up with (i.e. register) one partner at a time.

### Registering a partner

Partner trainers must be registered and deregistered. This is done with the following code:

```
pbRegisterPartner(:HOOPYTRAINER, "Zaphod", 0)

```

The parameters for `def pbRegisterPartner` are as follows:

1. The partner's trainer type. Note the colon at the beginning.
2. The partner's name, in quote marks.
3. Optional. A number used to distinguish between different versions of the same trainer. Default is 0.

This is the same way you define an enemy trainer when you set up a trainer battle (trainer class plus name plus optional version number).

To deregister the partner trainer, use the following line of code:

```
pbDeregisterPartner

```

As there can only be one registered partner at any one time, `def pbDeregisterPartner` doesn't have any parameters.

## Follower events

This section explains how to have the partner trainer's event follow the player as they walk around the map. More generally, it explains how to make any event follow the player - the follower mechanic is not solely for partner trainers (it just makes sense to use a dependent event for a registered partner).

While the player has any followers, the player cannot use the moves Surf, Fly, Teleport or Dig outside battle, nor use an Escape Rope. The player can talk to the follower, but the contents of that interaction must be in a Common Event rather than in a page in that dependent event. A follower will automatically stop following the player if they black out.

### Making an event a follower

When registering a partner trainer, you will typically also want to make that trainer's event a follower. To do this, use the following line of code:

```
Followers.add(@event_id, "Dave", 42)

```

The first argument is the ID number of the event from the current map that will follow the player (`@event_id` means the event that this script is used in). The second argument is a name or phrase used to identify the follower (useful when making them stop following later on). The third argument is the number of the Common Event to run when the player talks to the follower.

Common Events are listed in the Database (F9). They are similar to events, except they only have one page and limited triggers (you should use the trigger "None", which means you need to interact with it in order to talk with it).

### Controlling a follower

It is possible to use a "Set Move Route" event command to control the movement of a follower. To do so, simply call this script command before that "Set Move Route" event command:

```
follower_move_route

```

This script ensures that the next "Set Move Route" event command will apply to the follower instead of whichever event it designated. Note that this only applies to one such event command, so you will need to use this script before each "Set Move Route" event command you want to apply to the follower. This script does not need to be called immediately before the "Set Move Route" event command, though; its use will be remembered until it applies.

It is also possible to play an animation (defined in the Database) on top of the follower, such as an exclamation bubble. To do so, simply call this script command before that "Show Animation" event command:

```
follower_animation

```

This script ensures that the next "Show Animation" event command will apply to the follower instead of whichever event it designated. Note that this only applies to one such event command, so you will need to use this script before each "Show Animation" event command you want to apply to the follower. This script does not need to be called immediately before the "Show Animation" event command, though; its use will be remembered until it applies.

### Followers across multiple maps

Followers are typically only used (in the official games) in a single specific map, teaming up with the player at the start and leaving at the end. However, you may want a follower to follow the player across multiple maps.

Followers can move between connected maps just fine. You do **not** need an event representing the follower on each map that the player could visit with the follower.

Door events will need some modifications to work well with followers. Immediately after the player walks into the door and becomes transparent, the following script should be called, followed by a "Wait for Move's Completion":

```
Followers.follow_into_door

```

As the name suggests, this script makes the follower(s) pursue the player into the door and become transparent once they enter it. After this happens, the rest of the event (animating the door closing again) can happen as normal.

In addition, the second page of a door event will also need modifying. This page triggers when the player is exiting the door. At the start, when the player is made transparent, the following script should also be run:

```
Followers.hide_followers

```

Also, once the player has walked out of the door, the following script should be run:

```
Followers.put_followers_on_player

```

This will reposition the follower(s) to be in the same spot as the player, but they will remain invisible until the player starts to move.

There are examples of these modified door events in the example maps that come with Essentials. Cave entrances will also need the page 2 modifications, and there are examples of these as well.

Other map transfers will place the follower(s) in the same spot as the player on the new map, and make them invisible until the player starts to move.

### Removing a follower

To remove a follower, use this script command:

```
Followers.remove("Dave")

```

This uses the name or phrase which identifies that follower. Remember that you should both remove the event as a follower AND deregister the partner trainer at the same time.

When a follower is removed, it is immediately erased. Rather than instantly vanishing, you will likely want them to remain on the map, just not following the player. To achieve this, you will need to move the follower (while it is still a follower) to a fixed position, and at the same moment, remove the follower and set the Self Switch of an event in that position, which will look like the follower. This need not be the same event as the one that the follower was before it became a follower, but it may be.

The exact details of this are a little complex. Remember that the player could black out while they have a follower, which will automatically remove the follower, and so the event that became the follower will need resetting. There is an example of how to set this up at the top left of the Route 3 example map, complete with comments about what the events are doing and why.

## Tips

* You can use followers for things other than partner trainers. For example, a famous feature of Pokémon Yellow was that the player's Pikachu followed them around.
	+ Following Pokémon can be quite tricky to get to work properly, though.
* You could talk to a partner trainer to make them stop fighting alongside you in battles, or to make them fight alongside you again.