### Compile and install libpng Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Uncompress, configure, and install the libpng library from source. ```bash tar xf libpng-1.6.37.tar.xz cd libpng-1.6.37 ./configure --prefix=/usr make check make install ``` -------------------------------- ### Example Script Using Flags Source: https://github.com/pret/pokeemerald/wiki/The-Basics-of-Scripting A complete script example demonstrating how to check, display messages, and set a system flag. ```gas Script_CheckDexFlag:: lock faceplayer goto_if_set FLAG_SYS_POKEDEX_GET, Script_DexFlagSet msgbox Text_DexFlagClear, MSGBOX_DEFAULT setflag FLAG_SYS_POKEDEX_GET release end Script_DexFlagSet:: msgbox Text_DexFlagSet, MSGBOX_DEFAULT release end Text_DexFlagClear: .string "Pokédex flag is cleared.$" Text_DexFlagSet: .string "Pokédex flag is set.$" ``` -------------------------------- ### Install agbcc (Initial build) Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Commands to clone and build agbcc for the first time. ```bash git clone https://github.com/pret/agbcc cd agbcc ./build.sh ./install.sh ../pokeemerald ``` -------------------------------- ### Install build dependencies Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Installs the essential tools and libraries required to compile the pokeemerald project. ```bash sudo apt install build-essential binutils-arm-none-eabi git libpng-dev ``` -------------------------------- ### Install agbcc (Existing build) Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Commands to install an already built agbcc into the project directory. ```bash cd agbcc ./install.sh ../pokeemerald ``` -------------------------------- ### Install Dependencies on OpenBSD Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Install required packages using pkg_add. ```bash pkg_add gmake bash arm-none-eabi-binutils clang git ``` -------------------------------- ### Usage Example for checkforspecies Source: https://github.com/pret/pokeemerald/wiki/Useful-Scripting-Specials Example script demonstrating how to use the checkforspecies macro. ```assembly Route101_EventScript_RouteSign:: checkforspecies SPECIES_TORCHIC, NO_PARTY_SCREEN, Route101_EventScript_RouteSign_HasTorchic msgbox Route101_EventScript_Text_NoTorchic, MSGBOX_DEFAULT release end Route101_EventScript_RouteSign_HasTorchic:: msgbox Route101_EventScript_Text_HasTorchic, MSGBOX_DEFAULT release end Route101_EventScript_Text_NoTorchic: .string "You don't have a TORCHIC.$" Route101_EventScript_Text_HasTorchic: .string "You have a TORCHIC!$" ``` -------------------------------- ### Install devkitPro packages Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Commands to update the package database and install the required GBA development tools. ```bash sudo pacman -Sy sudo pacman -S gba-dev ``` -------------------------------- ### Install Ubuntu WSL1 Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Executes the installation of the Ubuntu distribution with WSL1 support enabled via PowerShell. ```powershell wsl --install -d Ubuntu --enable-wsl1 ``` -------------------------------- ### Example Starter Pokémon Definitions Source: https://github.com/pret/pokeemerald/wiki/New-Birch's-Briefcase-With-Fully-Custom-Starters-by-Archie-and-Mudskip Examples of how to define starter Pokémon using the `MonChoiceData` structure. These constants can be renamed if the type trio changes, while retaining their ID values. ```C [BALL_TOP_THIRD] = {SPECIES_CHIKORITA, 5, GRASS_STARTER}, [BALL_TOP_FOURTH] = {SPECIES_TOTODILE, 5, WATER_STARTER}, [BALL_MIDDLE_THIRD] = {SPECIES_CYNDAQUIL, 5, FIRE_STARTER}, ``` -------------------------------- ### Start NixOS Development Shell Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Launch an interactive shell with the necessary build tools pre-configured. ```bash nix-shell -p pkgsCross.arm-embedded.stdenv.cc git pkg-config libpng ``` -------------------------------- ### Example Trainer Items Source: https://github.com/pret/pokeemerald/wiki/How-to-create-a-new-regular-trainer-battle This example shows how to define the items a trainer uses in battle, with a limit of four. Ensure that `ITEM_NONE` is used for any unused item slots. ```c {ITEM_HYPER_POTION, ITEM_HYPER_POTION, ITEM_NONE, ITEM_NONE} ``` -------------------------------- ### Install gdebi-core on WSL1 Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Install the 'gdebi-core' package, which is required for installing devkitPro pacman. This command is for WSL1 environments. ```bash sudo apt install gdebi-core ``` -------------------------------- ### Usage Examples for moncryscript Source: https://github.com/pret/pokeemerald/wiki/Supplementary-Scripting-Macros Demonstrates how to invoke the macro and the resulting assembly code generated. ```assembly moncryscript SPECIES_MEOWTH, Text_SomeText @ separated for clarity release end ``` ```assembly lock faceplayer waitse playmoncry SPECIES_MEOWTH, CRY_MODE_NORMAL bufferspeciesname 1, SPECIES_MEOWTH bufferstring 2, Text_SomeText msgbox Text_MonCryScript waitmoncry @ separated for clarity: below is not part of the command release end ``` -------------------------------- ### Create and Implement a Task Source: https://github.com/pret/pokeemerald/wiki/Overview∶-The-Game-Loop Example of creating a task and a callback function that performs an action based on player input. ```c // 5 is the priority, and is not important. u8 taskId = CreateTask(ButtonPressSound_Task, 5); ... void ButtonPressSound_Task(u8 taskId) { if (gMain.newKeys & A_BUTTON) { PlaySE(SE_PC_LOGIN); if (++gTasks[taskId].data[0] == 10) DestroyTask(taskId); } } ``` -------------------------------- ### Install devkitARM on macOS Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Use dkp-pacman to install the GBA development toolchain and rules. ```bash sudo dkp-pacman -Sy sudo dkp-pacman -S gba-dev sudo dkp-pacman -S devkitarm-rules ``` -------------------------------- ### CONTROLLER_INTROSLIDE Source: https://github.com/pret/pokeemerald/wiki/Battle-Controllers The battle is starting, and the background art for this battle (depicting the terrain) should slide into view. ```APIDOC ## CONTROLLER_INTROSLIDE ### Description The battle is starting, and the background art for this battle (depicting the terrain) should slide into view. ### Method Inbound ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Usage Example of getobjectfacingdirection Source: https://github.com/pret/pokeemerald/wiki/Useful-Scripting-Specials Example script demonstrating how to use the macro to check the player's direction and trigger specific messages. ```asm Route101_EventScript_RouteSign:: getobjectfacingdirection OBJ_EVENT_ID_PLAYER, VAR_TEMP_1 goto_if_eq VAR_TEMP_1, DIR_NORTH, Route101_EventScript_RouteSign_North goto_if_eq VAR_TEMP_1, DIR_SOUTH, Route101_EventScript_RouteSign_South goto_if_eq VAR_TEMP_1, DIR_WEST, Route101_EventScript_RouteSign_West goto_if_eq VAR_TEMP_1, DIR_EAST, Route101_EventScript_RouteSign_East end Route101_EventScript_RouteSign_North: msgbox Route101_Text_RouteSign_North, MSGBOX_DEFAULT release end Route101_EventScript_RouteSign_South: msgbox Route101_Text_RouteSign_South, MSGBOX_DEFAULT release end Route101_EventScript_RouteSign_West: msgbox Route101_Text_RouteSign_West, MSGBOX_DEFAULT release end Route101_EventScript_RouteSign_East: msgbox Route101_Text_RouteSign_East, MSGBOX_DEFAULT release end Route101_Text_RouteSign_North: .string "The Player is facing North!$" Route101_Text_RouteSign_South: .string "The Player is facing South!$" Route101_Text_RouteSign_West: .string "The Player is facing West!$" Route101_Text_RouteSign_East: .string "The Player is facing East!$" ``` -------------------------------- ### Usage Example for List Menu Coloring Source: https://github.com/pret/pokeemerald/wiki/List-Menu-Text-Coloring Demonstrates how to assign specific colors to list menu items during initialization. ```c for (i = 0; i < task->tNumItems; i++) { sScrollableMultichoice_ListMenuItem[i].name = sScrollingMultichoiceLists[task->tScrollMultiId].list[i].name; sScrollableMultichoice_ListMenuItem[i].id = i; sScrollableMultichoice_ListMenuItem[i].colors[0] = TEXT_COLOR_RED; // all entries will have red text } ``` -------------------------------- ### Install gba-dev on Arch Linux Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Use pacman to install the required development packages for GBA projects. ```console pacman -S gba-dev ``` -------------------------------- ### Define Starting PC Items in pokeemerald Source: https://github.com/pret/pokeemerald/wiki/Change-initial-PC-items The sNewGamePCItems array in src/player_pc.c controls the items present in the PC at the start of a new game. Ensure the array ends with { ITEM_NONE, 0 } to terminate the list. ```c static const u16 sNewGamePCItems[][2] = { { ITEM_POTION, 1 }, { ITEM_NONE, 0 } }; ``` ```c static const u16 sNewGamePCItems[][2] = { { ITEM_POTION, 5 }, { ITEM_LUCKY_EGG, 6}, { ITEM_NONE, 0 } }; ``` -------------------------------- ### Define Day and Night Start Times Source: https://github.com/pret/pokeemerald/wiki/Change-Time-Based-Evolution-Times Define these constants in `include/pokemon.h` to set the 24-hour start times for day and night. Customize these values as needed. ```c #define DAY_START 4 #define NIGHT_START 18 ``` -------------------------------- ### Example Script for Item Giving Source: https://github.com/pret/pokeemerald/wiki/Plural-Giveitem This script demonstrates the usage of the 'giveitem' command with different quantities to test the pluralization functionality. ```asm VerdanturfTown_EventScript_TownSign:: giveitem ITEM_POTION, 2 giveitem ITEM_ORAN_BERRY, 3 giveitem ITEM_POKE_BALL, 1 end ``` -------------------------------- ### Usage Examples for emote Source: https://github.com/pret/pokeemerald/wiki/Supplementary-Scripting-Macros Demonstrates various emote calls and the resulting assembly output. ```assembly emote 3 @ separated for clarity emote 1, EMOTE_HEART @ separated for clarity emote 2, EMOTE_QUESTION ``` ```assembly playse SE_PIN applymovement 3, Common_Movement_ExclamationMark waitmovement 0 applymovement 3, Common_Movement_Delay48 waitmovement 0 @ separated for clarity playse SE_PIN applymovement 1, Common_Movement_Heart waitmovement 0 applymovement 1, Common_Movement_Delay48 waitmovement 0 @ separated for clarity playse SE_PIN applymovement 2, Common_Movement_QuestionMark waitmovement 0 applymovement 2, Common_Movement_Delay48 waitmovement 0 ``` -------------------------------- ### Install createpartymon branch Source: https://github.com/pret/pokeemerald/wiki/Temporarily-Replace-Player-or-Enemy-Party-Pokemon Commands to add the remote repository and pull the createpartymon branch into your local pokeemerald project. ```bash git remote add petuh https://github.com/Petuuuhhh/pokeemerald ``` ```bash git pull petuh createpartymon ``` -------------------------------- ### Include Headers for Item Use Source: https://github.com/pret/pokeemerald/wiki/Add-Nuzlocke-Challenge Adds necessary headers for battle setup and region map functionality in item_use.c. ```C +#include "battle_setup.h" +#include "region_map.h" ``` -------------------------------- ### Install Debug System Source: https://github.com/pret/pokeemerald/wiki/Add-a-debug-menu Commands to add the remote repository, pull the debug branch, and rebuild the project with debugging enabled. ```c git remote add xaman https://github.com/TheXaman/pokeemerald/ git pull xaman tx_debug_system make clean make debugging ``` -------------------------------- ### Modify Battle Setup and Trainer Logic Source: https://github.com/pret/pokeemerald/wiki/Allow-Running-From-Trainer-Battles Updates to src/battle_setup.c to track the previous trainer and handle the run outcome flag. ```diff ------------------------------ src/battle_setup.c ------------------------------ index 03bc0a08e7..e17db26d14 100644 @@ -113,8 +113,9 @@ EWRAM_DATA static u8 *sTrainerBattleEndScript = NULL; EWRAM_DATA static u8 *sTrainerABattleScriptRetAddr = NULL; EWRAM_DATA static u8 *sTrainerBBattleScriptRetAddr = NULL; EWRAM_DATA static bool8 sShouldCheckTrainerBScript = FALSE; EWRAM_DATA static u8 sNoOfPossibleTrainerRetScripts = 0; +EWRAM_DATA static u32 sPrevTrainerSeeing = 0; // The first transition is used if the enemy pokemon are lower level than our pokemon. // Otherwise, the second transition is used. static const u8 sBattleTransitionTable_Wild[][2] = @@ -1271,9 +1272,13 @@ void SetUpTwoTrainersBattle(void) bool32 GetTrainerFlagFromScriptPointer(const u8 *data) { u32 flag = TrainerBattleLoadArg16(data + 2); - return FlagGet(TRAINER_FLAGS_START + flag); + bool8 trainerFlagValue = FlagGet(TRAINER_FLAGS_START + flag); + if (flag != sPrevTrainerSeeing && !trainerFlagValue){ + sPrevTrainerSeeing = flag; + FlagClear(FLAG_RAN_FROM_TRAINER); + } + return (trainerFlagValue || FlagGet(FLAG_RAN_FROM_TRAINER)); } // Set trainer's movement type so they stop and remain facing that direction // Note: Only for trainers who are spoken to directly @@ -1412,10 +1422,16 @@ static void CB2_EndTrainerBattle(void) { SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); if (!InBattlePyramid() && !InTrainerHillChallenge()) { - RegisterTrainerInMatchCall(); - SetBattledTrainersFlags(); + if (gBattleOutcome == B_OUTCOME_RAN){ + FlagSet(FLAG_RAN_FROM_TRAINER); + } + else + { + FlagClear(FLAG_RAN_FROM_TRAINER); + RegisterTrainerInMatchCall(); + SetBattledTrainersFlags(); + } } } } ``` -------------------------------- ### Implement warp script with flag Source: https://github.com/pret/pokeemerald/wiki/Remove-Warp-Fadescreen Example script usage showing how to set the flag before a warp command to suppress the fade. ```asm VerdanturfTown_EventScript_Camper:: lock faceplayer msgbox sText_1, MSGBOX_AUTOCLOSE fadescreen FADE_TO_BLACK setflag FLAG_REMOVE_WARP_FADE msgbox sText_2, MSGBOX_AUTOCLOSE warp MAP_RUSTBORO_CITY, 0, 0, 0 end ``` -------------------------------- ### Install devkitARM on WSL1 Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Commands to install devkitARM on WSL1 after installing 'gdebi-core'. This includes installing the devkitPro pacman package and the gba-dev package. ```bash cd /mnt/c/Users//Downloads ``` ```bash sudo gdebi devkitpro-pacman.amd64.deb ``` ```bash sudo dkp-pacman -Sy ``` ```bash sudo dkp-pacman -S gba-dev ``` -------------------------------- ### Install devkitARM on Debian/Ubuntu Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Commands to install devkitARM on Debian/Ubuntu systems. This involves installing the devkitPro pacman package and the gba-dev package. ```bash sudo gdebi devkitpro-pacman.amd64.deb ``` ```bash sudo dkp-pacman -Sy ``` ```bash sudo dkp-pacman -S gba-dev ``` -------------------------------- ### Build ROM on OpenBSD Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Navigate to the project directory and initiate the build process. ```bash cd ../pokeemerald gmake ``` -------------------------------- ### Install libpng using Homebrew on macOS Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Installs the libpng library on macOS using the Homebrew package manager. Ensure Homebrew is installed first. ```bash brew install libpng ``` -------------------------------- ### Initialize Debug Main Menu Source: https://github.com/pret/pokeemerald/wiki/Add-a-debug-menu Sets up and displays the main debug menu by creating a window, initializing a list menu, and starting a task to handle user input. ```c void Debug_ShowMainMenu(void) { struct ListMenuTemplate menuTemplate; u8 windowId; u8 menuTaskId; u8 inputTaskId; // create window HideMapNamePopUpWindow(); LoadMessageBoxAndBorderGfx(); windowId = AddWindow(&sDebugMenuWindowTemplate); DrawStdWindowFrame(windowId, FALSE); // create list menu menuTemplate = sDebugMenuListTemplate; menuTemplate.windowId = windowId; menuTaskId = ListMenuInit(&menuTemplate, 0, 0); // draw everything CopyWindowToVram(windowId, 3); // create input handler task inputTaskId = CreateTask(DebugTask_HandleMainMenuInput, 3); gTasks[inputTaskId].data[0] = menuTaskId; gTasks[inputTaskId].data[1] = windowId; } ``` -------------------------------- ### Initialize Windows Source: https://github.com/pret/pokeemerald/wiki/How-Menus-Work-‐-Part-2 Initializes a set of windows from a template list. Ensure the list is terminated with DUMMY_WIN_TEMPLATE. ```c bool16 InitWindows(const struct WindowTemplate *templates) ``` -------------------------------- ### Install Dependencies on Arch Linux Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Install required packages using pacman. ```bash pacman -S base-devel arm-none-eabi-binutils arm-none-eabi-newlib git libpng ``` -------------------------------- ### InitBgsFromTemplates Source: https://github.com/pret/pokeemerald/wiki/How-Menus-Work-‐-Part-2 Initializes background layers using a template list. ```APIDOC ## void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates) ### Description Uses a list of BgTemplate structures to set up the GBA's background layers. ### Parameters - **bgMode** (u8) - Required - The background mode (use 0 for text mode). - **templates** (const struct BgTemplate *) - Required - Pointer to the list of background templates. - **numTemplates** (u8) - Required - The number of templates in the list. ``` -------------------------------- ### Install build dependencies in msys2 Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Install the necessary toolchain packages required to compile the project. ```bash pacman -Sy msys2-keyring pacman -S make gcc zlib-devel git ``` -------------------------------- ### Navigate to base directory Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Change directory to the parent folder containing the project components. ```bash cd .. ``` -------------------------------- ### Compare ROM to Original Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Run this command to verify if your built ROM matches the original game's ROM. It will output 'OK' on success or 'FAILED' with a warning if there are differences. ```bash make compare ``` -------------------------------- ### Configure Animation Start Delay Source: https://github.com/pret/pokeemerald/wiki/How-to-add-a-new-Pokémon-species Sets the delay in frames between the Pokémon's appearance and the start of its animation. ```diff + [SPECIES_MEWTHREE - 1] = 15, ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Installs the Xcode Command Line Tools on macOS, which are necessary for development. This command should be run in the Terminal. ```bash xcode-select --install ``` -------------------------------- ### Get macOS CPU Core Count Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md On macOS, use this command to get the number of CPU cores for parallel builds, as 'nproc' is not available. ```bash sysctl -n hw.ncpu ``` -------------------------------- ### Configure Trainer Data for Mugshot Transition Source: https://github.com/pret/pokeemerald/wiki/Custom-Battle-Mugshots To enable a mugshot transition for a trainer, add the `.hasCustomTransition = TRUE` and `.transition = B_TRANSITION_MUGSHOT` fields to their data structure in `src/data/trainers.h`. ```c .hasCustomTransition = TRUE, .transition = B_TRANSITION_MUGSHOT, ``` -------------------------------- ### Install Build Dependencies (Bash) Source: https://github.com/pret/pokeemerald/blob/master/docs/legacy_WSL1_INSTALL.md Installs essential packages required for building Pokeemerald on a Debian-based Linux system like WSL1. Ensure you have internet connectivity. ```bash sudo apt install build-essential git libpng-dev gdebi-core ``` -------------------------------- ### Initialize Background Layers Source: https://github.com/pret/pokeemerald/wiki/How-Menus-Work-‐-Part-2 Configures background layers using a list of BgTemplate structures. Pass 0 for bgMode and use ARRAY_COUNT for the numTemplates argument. ```c void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates) ``` -------------------------------- ### Initialize Save Version in NewGameInitData Source: https://github.com/pret/pokeemerald/wiki/How-to-Support-Savefile-Backwards-Compatibility Update the new game initialization logic in new_game.c to set the sentinel and version. ```diff void NewGameInitData(void) { if (gSaveFileStatus == SAVE_STATUS_EMPTY || gSaveFileStatus == SAVE_STATUS_CORRUPT) RtcReset(); gDifferentSaveFile = TRUE; + gSaveBlock2Ptr->_saveSentinel = 0xFF; + gSaveBlock2Ptr->saveVersion = SAVE_VERSION; gSaveBlock2Ptr->encryptionKey = 0; ZeroPlayerPartyMons(); ZeroEnemyPartyMons(); ``` -------------------------------- ### Change Battle Message for Snow/Hail Source: https://github.com/pret/pokeemerald/wiki/Fix-Snow-Weather Modify the gWeatherStartsStringIds array in src/battle_message.c to change the string displayed when snow starts, making it display 'Started Hail' instead. ```diff const u16 gWeatherStartsStringIds[] = { [WEATHER_NONE] = STRINGID_ITISRAINING, [WEATHER_SUNNY_CLOUDS] = STRINGID_ITISRAINING, [WEATHER_SUNNY] = STRINGID_ITISRAINING, [WEATHER_RAIN] = STRINGID_ITISRAINING, - [WEATHER_SNOW] = STRINGID_ITISRAINING, + [WEATHER_SNOW] = STRINGID_STARTEDHAIL, [WEATHER_RAIN_THUNDERSTORM] = STRINGID_ITISRAINING, [WEATHER_FOG_HORIZONTAL] = STRINGID_ITISRAINING, [WEATHER_VOLCANIC_ASH] = STRINGID_ITISRAINING, [WEATHER_SANDSTORM] = STRINGID_SANDSTORMISRAGING, [WEATHER_FOG_DIAGONAL] = STRINGID_ITISRAINING, [WEATHER_UNDERWATER] = STRINGID_ITISRAINING, [WEATHER_SHADE] = STRINGID_ITISRAINING, [WEATHER_DROUGHT] = STRINGID_SUNLIGHTSTRONG, [WEATHER_SNOW] = STRINGID_STARTEDHAIL, [WEATHER_DOWNPOUR] = STRINGID_ITISRAINING, [WEATHER_UNDERWATER_BUBBLES] = STRINGID_ITISRAINING, [WEATHER_ABNORMAL] = STRINGID_ITISRAINING }; ``` -------------------------------- ### Apply Movement Commands Source: https://github.com/pret/pokeemerald/wiki/The-Basics-of-Scripting Use applymovement to initiate a path for an object and waitmovement to ensure completion before proceeding. ```gas applymovement [Local ID], [Movements Label] waitmovement [Local ID=0] ``` ```gas Script_MovementsDemonstration:: lock faceplayer msgbox Text_MovementsDemonstration, MSGBOX_DEFAULT applymovement 1, Movement_Example applymovement OBJ_EVENT_ID_PLAYER, Movement_Example waitmovement release end Text_MovementsDemonstration: .string "Hey!\n" .string "Let's walk three steps up.$" Movement_Example: walk_up walk_up walk_up step_end ``` -------------------------------- ### Include Necessary Headers Source: https://github.com/pret/pokeemerald/wiki/Trainer-Scripts Ensure `src/script.c` includes `trainer_see.h` for access to `gApproachingTrainers` and `src/trainer_see.c` includes `event_scripts.h` for related definitions. ```c #include "trainer_see.h" ``` ```c #include "event_scripts.h" ``` -------------------------------- ### Example of Shared Data Space Structure Source: https://github.com/pret/pokeemerald/wiki/Reuse-filler-save-space-for-Variables-and-Flags This is an illustrative example showing how flags and variables share the same data space in gAdditionalSaveData. It highlights potential conflicts if IDs are not managed carefully. ```c struct { u8 FLAG_FOR_SOMETHING_SUPER_SPECIAL : 1; // flag with ID 0xF000 at bit 0 of byte 0 u8 FLAG_FOR_SOMETHING_TOTALLY_BORING : 1; // flag with ID 0xF001 at bit 1 of byte 0 u8 filler; u16 VAR_FOR_SOMETHING_SUPER_SPECIAL; // var with ID 0xF001 at bytes 2 and 3 u16 VAR_FOR_SOMETHING_TOTALLY_BORING; // var with ID 0xF002 at bytes 4 and 5 }; ``` -------------------------------- ### Handle Intro Slide Animation Source: https://github.com/pret/pokeemerald/wiki/Battle-Controllers Initiates the background art slide-in animation at the start of a battle. The controller should start animations and then finish handling the command without waiting for completion. Pass the terrain ID as an argument to HandleIntroSlide. ```c HandleIntroSlide(terrainId); gIntroSlideFlags |= 1; ``` -------------------------------- ### Build pokeemerald Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Commands to enter the project directory and initiate the compilation process. ```bash cd pokeemerald make ``` -------------------------------- ### Clone and Build agbcc on OpenBSD Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Download the repository and build the agbcc compiler. ```bash git clone https://github.com/pret/pokeemerald git clone https://github.com/pret/agbcc cd agbcc && ./build.sh ./install.sh ../pokeemerald ``` -------------------------------- ### Create a simple text script Source: https://github.com/pret/pokeemerald/wiki/The-Basics-of-Scripting A basic assembly script using lock, faceplayer, and msgbox to display text to the player. ```gas Script_SimpleMsgScript:: lock faceplayer msgbox Text_SimpleMsgScript, MSGBOX_DEFAULT release end Text_SimpleMsgScript: .string "Hi!\n" .string "My name is Adam.\l" .string "What's your name?\p" .string "Nice to meet you, {PLAYER}!$" ``` -------------------------------- ### Implement Custom Trainer Battle Transition Logic Source: https://github.com/pret/pokeemerald/wiki/Custom-Battle-Mugshots In src/battle_setup.c, modify the GetTrainerBattleTransition function to check for and return the custom transition if the trainer has one set. This ensures the custom mugshot is used. ```diff if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) return B_TRANSITION_CHAMPION; + if (gTrainers[gTrainerBattleOpponent_A].hasCustomTransition) + return gTrainers[gTrainerBattleOpponent_A].transition; + if (gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_ELITE_FOUR) { ``` -------------------------------- ### Update WSL packages Source: https://github.com/pret/pokeemerald/blob/master/INSTALL.md Updates the local package index and upgrades installed packages to their latest versions. ```bash sudo apt update && sudo apt upgrade ``` -------------------------------- ### Automating VRAM Tile Allocation with Preprocessor Macros Source: https://github.com/pret/pokeemerald/wiki/How-Menus-Work-‐-Part-2 Use preprocessor definitions to calculate window tile usage and validate that the total tile count remains within the VRAM budget. ```c #define WIN_HEADER_WIDTH 26 #define WIN_HEADER_HEIGHT 2 #define WIN_OPTIONS_WIDTH 26 #define WIN_OPTIONS_HEIGHT 14 #define WIN_HEADER_TILE_IDS_USED (WIN_HEADER_WIDTH * WIN_HEADER_HEIGHT) #define WIN_OPTIONS_TILE_IDS_USED (WIN_OPTIONS_WIDTH * WIN_OPTIONS_HEIGHT) #define WIN_HEADER_BASE_BLOCK 2 #define WIN_OPTIONS_BASE_BLOCK (WIN_HEADER_BASE_BLOCK + WIN_HEADER_TILE_IDS_USED) #define END_OF_WINDOW_BLOCKS (WIN_OPTIONS_BASE_BLOCK + WIN_OPTIONS_TILE_IDS_USED) // ID of first tileset graphic after window tileset graphics #if END_OF_WINDOW_BLOCKS > 2047 #error Too many tiles used for windows; total tile count exceeds VRAM budget. #endif // divide by 64 and round up #define FIRST_SAFE_TILEMAP_BASE_INDEX (END_OF_WINDOW_BLOCKS / 64) + ((END_OF_WINDOW_BLOCKS % 64) ? 1 : 0) #if FIRST_SAFE_TILEMAP_BASE_INDEX > 31 #error Too many tiles used; the tilesets themselves may fit in VRAM but there's no safe place to put the tilemap. #endif ```