Continue Script After Warp - Pawkkie/Team-Aquas-Asset-Repo GitHub Wiki
By Team Aqua Leader Archie.
This macro allows the script to be continued after a warp is called.
A test script is at the bottom. here
In scripting
In asm/macros/event.inc
Add this new macro:
@ Warps to a map, and plays the script passed to it
.macro warpcontinuescript map:req, X:req, Y:req, script:req, startBlack=TRUE
.byte SCR_OP_WARPCONTINUESCRIPT
.2byte \map
.2byte \X
.2byte \Y
.4byte \script
.endm
In data/script_cmd_table.inc
Add your scripting function to the respective byte.
You can replace one of these bytes: 0xc7
, 0xc8
, 0xc9
, 0xca
, 0xcb
, 0xcc
.
- script_cmd_table_entry SCR_OP_TEXTCOLOR ScrCmd_nop1, requests_effects=1 @ 0xc7
+ script_cmd_table_entry SCR_OP_WARPCONTINUESCRIPT ScrCmd_warpcontinuescript, requests_effects=1 @ 0xc7
In code
In src/scrcmd.c
Declare this at the top with the rest of the global variables.
(But feel free to declare it anywhere, before it's use)
static EWRAM_DATA const u8 *gAfterWarpScript = {0};
Add these functions.
static void FieldCallback_SetupWarpScript(void)
{
if (gAfterWarpScript == NULL)
{
gFieldCallback = NULL;
return;
}
Overworld_PlaySpecialMapMusic();
LockPlayerFieldControls();
CpuFastFill(0, gPlttBufferFaded, PLTT_SIZE);
ScriptContext_SetupScript(gAfterWarpScript);
}
bool8 ScrCmd_warpcontinuescript(struct ScriptContext *ctx)
{
u8 mapNum = ScriptReadByte(ctx);
u8 mapGroup = ScriptReadByte(ctx);
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
gAfterWarpScript = (const u8 *) ScriptReadWord(ctx);
gFieldCallback = FieldCallback_SetupWarpScript;
SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, x, y);
WarpIntoMap();
SetMainCallback2(CB2_LoadMap);
return TRUE;
}
And done! With that you can use this macro to continue your script after a warp!
Usage
This is a snippet from a ROM hack which utilizes this feature.
Be sure to change it to your needs in your script
EverGrandeCity_EventScript_WarpToChampion::
lock
faceplayer
msgbox Text_TimeToBattle, MSGBOX_DEFAULT
fadeoutbgm 0
fadescreen FADE_TO_BLACK
warpcontinuescript MAP_EVER_GRANDE_CITY_CHAMPIONS_ROOM, 6, 12, EverGrandeCity_EventScript_ContinueFromWarp
end
EverGrandeCity_EventScript_ContinueFromWarp::
fadescreen FADE_FROM_BLACK
msgbox Text_GoodLuckPlayer
release
end
Text_TimeToBattle:
.string "Come, {PLAYER}.\n"
.string "It's time!$"
Text_GoodLuckPlayer:
.string "Good luck, {PLAYER}!$"
For Expansion and/or Merrps' DNS users:
DO NOT use the fadescreenswapbuffers
, as it causes the game to freeze.