summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorghoulslash <41651341+ghoulslash@users.noreply.github.com>2020-07-03 12:20:40 -0600
committerghoulslash <41651341+ghoulslash@users.noreply.github.com>2020-07-03 12:20:40 -0600
commit83434352ab12814ff7ee7403af9e1cbcecaedbe1 (patch)
treeb558def07ed502538474810b80748bf16cbf84d6
parent8bb58bca4c4e58c5a9692e343814fc45136b0498 (diff)
Updated Trainer Scripts (markdown)
-rw-r--r--Trainer-Scripts.md26
1 files changed, 23 insertions, 3 deletions
diff --git a/Trainer-Scripts.md b/Trainer-Scripts.md
index 4adae6c..bc94077 100644
--- a/Trainer-Scripts.md
+++ b/Trainer-Scripts.md
@@ -2,7 +2,9 @@
Credit to ghoulslash. Pull from his [repo](https://github.com/ghoulslash/pokeemerald/tree/trainer_see_scripts) or follow the guide below.
-Default Pokemon Trainers require the first script command to be trainerbattle to function correctly. This feature allows you to run any script while including the "trainer spotting" effect (see the bottom of the page for an example)
+Default Pokemon Trainers require the first script command to be trainerbattle to function correctly. This feature allows you to run any script while including the "trainer spotting" effect. Here's an example:
+
+<a href="https://imgur.com/JJ81c6i"><img src="https://i.imgur.com/JJ81c6i.gif" title="source: imgur.com" /></a>
### Modify Trainer Sight
**1. Open [src/trainer_see.c](../blob/master/src/trainer_see.c).** Find the function `CheckForTrainersWantingBattle`. Modify it to the following:
@@ -152,12 +154,11 @@ static u8 CheckTrainer(u8 objectEventId)
}
```
-**4. Create the function `GetObjectEventTrainerSightFlagByObjectEventId`**
+**3. Create the function `GetObjectEventTrainerSightFlagByObjectEventId`**
First, open [src/event_object_movement.c](../blob/master/src/event_object_movement.c). Somewhere, add the function `GetObjectEventTrainerSightFlagByObjectEventId`:
```c
u16 GetObjectEventTrainerSightFlagByObjectEventId(u8 objEventId)
{
- // ideally, would use a the last two bytes of the object event template
return GetObjectEventTemplateByLocalIdAndMap(gObjectEvents[objEventId].localId, gObjectEvents[objEventId].mapNum, gObjectEvents[objEventId].mapGroup)->trainerType;
}
```
@@ -167,6 +168,8 @@ Next, define the new function in [include/event_object_movement.h](../blob/maste
### Define TRAINER_TYPE_RUN_SCRIPT
add `#define TRAINER_TYPE_RUN_SCRIPT 4` to [include/constants/trainer_types.h](../blob/master/include/constants/trainer_types.h)
+This is actually superfluous, but is a nice way to demonstrate that any value >= 4 will allow you to run any script.
+
### Make a new approach script
Open [data/scripts/trainer_script.inc](../blob/master/data/scripts/trainer_script.inc) and add the following to the bottom
@@ -186,6 +189,23 @@ Next, add `extern const u8 EventScript_ObjectApproachPlayer[];` somewhere to [in
### Create `LoadTrainerObjectScript`
Open [src/script.c](../blob/master/src/script.c) and add the following function:
+```c
+bool8 LoadTrainerObjectScript(void)
+{
+ sScriptContext1.scriptPtr = gApproachingTrainers[gNoOfApproachingTrainers - 1].trainerScriptPtr;
+}
```
+Also, add `#include "trainer_see.h"` to the top of the file for this function to recognize `gApproachingTrainers`
+
### How to Set Up:
+Rather than make a new object event template field, we can use the fact that `.trainerType` is conveniently 16 bits. Set up your object event the following way:
+<a href="https://imgur.com/oYsv8ZB"><img src="https://i.imgur.com/oYsv8ZB.png" title="source: imgur.com" /></a>
+
+Here's a brief run-down of the important fields:
+* `Script`: the script you want the object to run upon approaching the player.
+* `Trainer Type:` the flag that allows the script to run. This must be >3, although you wouldn't want to use a temporary flag anyway. When the flag in this field is set, the object won't approach you anymore.
+* `Sight Radius:` the same as for regular trainers
+
+**Note:** there are two bytes free at the end of ObjectEventTemplate. You could easily add the trainer script flag here (don't forget to change the porymap json, GetObjectEventTrainerSightFlagByObjectEventId, and global.fieldmap.h!), and keep the trainer type field as intended.
+