forked from DizzyEggg/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 3
Prompt for reusing Repels
ExpoSeed edited this page Jun 13, 2020
·
8 revisions
Credit to DizzyEgg for this feature. This feature may also be directly pulled from DizzyEgg's repel branch.
This tutorial will ask the player, upon a Repel running out, if they want to use another repel and also let the player choose which repel to use.
TODO: Add explanations for every action
The Repel menu will use the custom multichoice.
Edit src/script_menu.c
-static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress, u8 cursorPos)
+static void DrawMultichoiceMenuCustom(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count)
{
int i;
u8 windowId;
- u8 count = gMultichoiceLists[multichoiceId].count;
- const struct MenuAction *actions = gMultichoiceLists[multichoiceId].list;
int width = 0;
u8 newWidth;
for (i = 0; i < count; i++)
{
width = display_text_and_get_width(actions[i].text, width);
}
newWidth = convert_pixel_width_to_tile_width(width);
left = ScriptMenu_AdjustLeftCoordFromWidth(left, newWidth);
windowId = CreateWindowFromRect(left, top, newWidth, count * 2);
SetStandardWindowBorderStyle(windowId, 0);
PrintMenuTable(windowId, count, actions);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, count, cursorPos);
schedule_bg_copy_tilemap_to_vram(0);
InitMultichoiceCheckWrap(ignoreBPress, count, windowId, multichoiceId);
}
Add the following new code:
static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress, u8 cursorPos)
{
DrawMultichoiceMenuCustom(left, top, multichoiceId, ignoreBPress, cursorPos, gMultichoiceLists[multichoiceId].list, gMultichoiceLists[multichoiceId].count);
}
void TryDrawRepelMenu(void)
{
static const u16 repelItems[] = {ITEM_REPEL, ITEM_SUPER_REPEL, ITEM_MAX_REPEL};
struct MenuAction menuItems[4] = {NULL};
int i, count = 0;
for (i = 0; i < ARRAY_COUNT(repelItems); i++)
{
if (CheckBagHasItem(repelItems[i], 1))
{
VarSet(VAR_0x8004 + count, repelItems[i]);
menuItems[count].text = ItemId_GetName(repelItems[i]);
count++;
}
}
if (count > 1)
DrawMultichoiceMenuCustom(0, 0, 0, FALSE, 0, menuItems, count);
gSpecialVar_Result = (count > 1);
}
void HandleRepelMenuChoice(void)
{
gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id;
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004));
}
Replace the contents of data/scripts/repel.inc:
EventScript_RepelWoreOff:: @ 82A4B2A
msgbox Text_RepelWoreOff, MSGBOX_SIGN
checkitem ITEM_REPEL, 1
compare VAR_RESULT, TRUE
goto_if_eq EventScript_RepelWoreOff_AskAnother
checkitem ITEM_SUPER_REPEL, 1
compare VAR_RESULT, TRUE
goto_if_eq EventScript_RepelWoreOff_AskAnother
checkitem ITEM_MAX_REPEL, 1
compare VAR_RESULT, FALSE
goto_if_eq EventScript_RepelWoreOff_End
EventScript_RepelWoreOff_AskAnother:
msgbox Text_RepelAskAnother, MSGBOX_YESNO
closemessage
compare VAR_RESULT, 0
goto_if_eq EventScript_RepelWoreOff_End
callnative TryDrawRepelMenu
compare VAR_RESULT, FALSE
goto_if_eq EventScript_RepelWoreOff_Chose
waitstate
compare VAR_RESULT, 127
goto_if_eq EventScript_RepelWoreOff_End
EventScript_RepelWoreOff_Chose:
callnative HandleRepelMenuChoice
bufferitemname 1, VAR_0x8004
removeitem VAR_0x8004, 1
playse SE_TU_SAA
msgbox gText_PlayerUsedVar2, MSGBOX_SIGN
EventScript_RepelWoreOff_End:
end
Text_RepelWoreOff: @ 82A4B33
.string "REPEL's effect wore off…$"
Text_RepelAskAnother:
.string "Would you like to use another one?$"
And that's it!