diff options
author | ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> | 2020-06-20 22:04:33 -0500 |
---|---|---|
committer | ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> | 2020-06-20 22:04:33 -0500 |
commit | a4b9c8e1c1a2706beb1cf4b25e92779d3e181456 (patch) | |
tree | b8d9aca9503c15b2c50f527107ccdac56904f7b6 | |
parent | 0d69a18a9a5d48230a780da047d50a30107ef221 (diff) |
made this tutorial good
-rw-r--r-- | Prompt-for-reusing-Repels.md | 163 |
1 files changed, 67 insertions, 96 deletions
diff --git a/Prompt-for-reusing-Repels.md b/Prompt-for-reusing-Repels.md index 7ca8ea1..b0fc73e 100644 --- a/Prompt-for-reusing-Repels.md +++ b/Prompt-for-reusing-Repels.md @@ -1,118 +1,89 @@ -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. +Credit to ExpoSeed for this feature. -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 +This tutorial will ask the player, upon a Repel running out, if they want to use another repel, and use the repel if they say yes. ## 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. +1. [Store last used Repel](#1-store-last-used-repel) +2. [Ask the player](#2-ask-the-player) + +## 1. Store last used Repel + +The tricky part of implementing this is that the game does not actually store which repel is used. It only changes `VAR_REPEL_STEP_COUNT`. In order to remedy this, we must store the repel used. -Edit [src/script_menu.c](../blob/master/src/script_menu.c) +We can use any of the unused vars to do this. This tutorial will use `VAR_UNUSED_0x404E`. Edit [src/include/constants/vars.h](../blob/master/include/constants/vars.h): ```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; +-#define VAR_UNUSED_0x404E 0x404E // Unused Var ++#define VAR_REPEL_LAST_USED 0x404E +``` - for (i = 0; i < count; i++) +Next, we need to write to the variable when a repel is used. Edit [src/item_use.c](../blob/master/src/item_use.c): +```diff + static void Task_UseRepel(u8 taskId) + { + if (!IsSEPlaying()) { - width = display_text_and_get_width(actions[i].text, width); + VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId)); ++ VarSet(VAR_REPEL_LAST_USED, gSpecialVar_ItemId); + RemoveUsedItem(); + if (!InBattlePyramid()) + DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + else + DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage); } - 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; +There is one last issue. We also need a value to write to `VAR_REPEL_STEP_COUNT`. From a script, we cannot get this from the item ID alone. While we could use another unused variable, there is a way to avoid having to do this. `callnative` in scripts lets you call any function from a script. So, we can define a new function and use it with `callnative`. `callnative` is not the only way to use C code in scripts. You can also define specials and save some (but not much space), but it is largely unneeded. - 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) +In [src/item.c](../blob/master/src/item.c), we will declare and define a new function: +```c +void ItemId_GetHoldEffectParam_Script(); +``` +```c +void ItemId_GetHoldEffectParam_Script() { - gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id; - VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004)); + VarSet(VAR_RESULT, ItemId_GetHoldEffectParam(VarGet(VAR_0x8004))); } ``` -## 2. Modify Repel script -Replace the contents of [data/scripts/repel.inc](../blob/master/data/scripts/repel.inc): -```c -EventScript_RepelWoreOff:: @ 82A4B2A +Next, we will modify the script to ask the player if they want to use another repel. + +## 2. Ask the player +Now, we have everything we need. Edit [data/scripts/repel.inc](../blob/master/data/scripts/repel.inc): +```diff + EventScript_RepelWoreOff:: @ 82A4B2A ++ checkitem VAR_REPEL_LAST_USED, 1 ++ compare VAR_RESULT, FALSE ++ goto_if_eq EventScript_RepelWoreOff_NoMoreRepels ++ msgbox Text_RepelWoreOff_UseAnother, MSGBOX_YESNO ++ compare VAR_RESULT, 0 ++ goto_if_eq goto_if_eq EventScript_RepelWoreOff_ChooseNo ++ copyvar VAR_0x8004, VAR_REPEL_LAST_USED ++ callnative ItemId_GetHoldEffectParam_Script ++ copyvar VAR_REPEL_STEP_COUNT, VAR_RESULT ++ bufferitemname 1, VAR_REPEL_LAST_USED ++ removeitem VAR_REPEL_LAST_USED, 1 ++ playse SE_TU_SAA ++ msgbox gText_PlayerUsedVar2, MSGBOX_SIGN ++ goto EventScript_RepelWoreOff_End ++EventScript_RepelWoreOff_ChooseNo: ++ closemessage ++ goto EventScript_RepelWoreOff_End ++EventScript_RepelWoreOff_NoMoreRepels: 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: ++EventScript_RepelWoreOff_End: end -Text_RepelWoreOff: @ 82A4B33 + Text_RepelWoreOff: @ 82A4B33 .string "REPEL's effect wore off…$" -Text_RepelAskAnother: - .string "Would you like to use another one?$" + ++Text_RepelWoreOff_UseAnother: ++ .string "REPEL's effect wore off…\n" ++ .string "Use another?$" ``` +Let's walk through this script. First, we check whether the player has another of the same repel in their bag. If they don't, we jump to the end. But if they do, we ask the player if they want to use another. If they say "No", then we close the message box and end the script. If they say "Yes", then we set the step count variable appropriately, deduct a repel from the bag, play the appropriate sound effect, and show a message saying the player used a repel. And that's it! - - -
\ No newline at end of file + + + +Alternatively, check out DizzyEgg's [repel](https://github.com/DizzyEggg/pokeemerald/tree/repel) branch for a version which uses a multichoice box instead.
\ No newline at end of file |