1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
Credit to DizzyEgg for this feature. This feature may also be directly pulled from DizzyEgg's [repel](https://github.com/DizzyEggg/pokeemerald/tree/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.
## Contents
1. [Modify multichoice menu to work with custom options](#1-modify-multichoice-menu-to-work-with-custom-options)
2. [Modify Repel script](#2-modify-repel-script)
## 1. Modify multichoice menu to work with custom options
The Repel menu will use the custom multichoice.
Edit [src/script_menu.c](../blob/master/src/script_menu.c)
```diff
-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:
```c
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));
}
```
## 2. Modify Repel script
Replace the contents of [data/scripts/repel.inc](../blob/master/data/scripts/repel.inc):
```c
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!



|