New step (var2 bugfix) added, updated Task_UseRepel code

Scyrous 2024-06-27 21:08:17 +02:00
parent a38200afe5
commit 001ef3ffbe
1 changed files with 30 additions and 8 deletions

@ -4,8 +4,9 @@ This tutorial will ask the player, upon a Repel running out, if they want to use
## Contents ## Contents
1. [Store last used Repel](#1-store-last-used-repel) 1. [Store last used Repel](#1-store-last-used-repel)
2. [Ask the player](#2-ask-the-player) 2. [Copy VAR string](#2-copy-var-string)
3. NEW - [Cycle through remaining repels](#3-cycle-through-repels) 3. [Ask the player](#3-ask-the-player)
4. [Cycle through remaining repels](#4-cycle-through-repels)
## 1. Store last used Repel ## 1. Store last used Repel
@ -27,13 +28,13 @@ Next, we need to write to the variable when a repel is used. Edit [src/item_use.
+ VarSet(VAR_REPEL_LAST_USED, gSpecialVar_ItemId); + VarSet(VAR_REPEL_LAST_USED, gSpecialVar_ItemId);
RemoveUsedItem(); RemoveUsedItem();
if (!InBattlePyramid()) if (!InBattlePyramid())
DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, CloseItemMessage);
else else
DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage); DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage);
} }
} }
``` ```
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. 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.
In [src/item.c](../blob/master/src/item.c), we will declare and define a new function (note: declare the function in include/item.h): In [src/item.c](../blob/master/src/item.c), we will declare and define a new function (note: declare the function in include/item.h):
```c ```c
@ -45,9 +46,30 @@ void ItemId_GetHoldEffectParam_Script()
VarSet(VAR_RESULT, ItemId_GetHoldEffectParam(VarGet(VAR_0x8004))); VarSet(VAR_RESULT, ItemId_GetHoldEffectParam(VarGet(VAR_0x8004)));
} }
``` ```
## 2. Copy VAR string
There is one last issue we need to solve before adding the script. We need to create a copy of gText_PlayerUsedVar2 and remove the {PAUSE_UNTIL_PRESS} portion of the string. We can't edit it directly, since gText_PlayerUsedVar2 is used in other parts of the game. If we were to use the original gText_PlayerUsedVar2 string, the player needs to press A **twice** after using a repel to get rid of the message box, which is obviously unintended. Making a copy of the string without {PAUSE_UNTIL_PRESS} bypasses this problem.
In [src/strings.c](../blob/master/src/strings.c) and [include/strings.h](../blob/master/include/strings.h), add a new string called gText_PlayerUsedRepel.
**strings.c**
```diff
const u8 gText_TMHMContainedVar1[] = _("It contained\n{STR_VAR_1}.\pTeach {STR_VAR_1}\nto a POKéMON?");
const u8 gText_PlayerUsedVar2[] = _("{PLAYER} used the\n{STR_VAR_2}.{PAUSE_UNTIL_PRESS}");
+const u8 gText_PlayerUsedRepel[] = _("{PLAYER} used the\n{STR_VAR_2}.");
const u8 gText_RepelEffectsLingered[] = _("But the effects of a REPEL\nlingered from earlier.{PAUSE_UNTIL_PRESS}");
```
**strings.h**
```diff
extern const u8 gText_TMHMContainedVar1[];
extern const u8 gText_PlayerUsedVar2[];
+extern const u8 gText_PlayerUsedRepel[];
extern const u8 gText_RepelEffectsLingered[];
```
Next, we will modify the script to ask the player if they want to use another repel. Next, we will modify the script to ask the player if they want to use another repel.
## 2. Ask the player ## 3. Ask the player
Now, we have everything we need. Edit [data/scripts/repel.inc](../blob/master/data/scripts/repel.inc): Now, we have everything we need. Edit [data/scripts/repel.inc](../blob/master/data/scripts/repel.inc):
```diff ```diff
EventScript_RepelWoreOff:: EventScript_RepelWoreOff::
@ -64,7 +86,7 @@ Now, we have everything we need. Edit [data/scripts/repel.inc](../blob/master/da
+ bufferitemname 1, VAR_REPEL_LAST_USED + bufferitemname 1, VAR_REPEL_LAST_USED
+ removeitem VAR_REPEL_LAST_USED, 1 + removeitem VAR_REPEL_LAST_USED, 1
+ playse SE_REPEL + playse SE_REPEL
+ msgbox gText_PlayerUsedVar2, MSGBOX_SIGN + msgbox gText_PlayerUsedRepel, MSGBOX_SIGN
+ goto EventScript_RepelWoreOff_End + goto EventScript_RepelWoreOff_End
+EventScript_RepelWoreOff_ChooseNo: +EventScript_RepelWoreOff_ChooseNo:
+ closemessage + closemessage
@ -91,7 +113,7 @@ And that's it!
Alternatively, check out DizzyEgg's [repel](https://github.com/DizzyEggg/pokeemerald/tree/repel) branch for a version which uses a multichoice box instead. Alternatively, check out DizzyEgg's [repel](https://github.com/DizzyEggg/pokeemerald/tree/repel) branch for a version which uses a multichoice box instead.
## 3. Cycle Through Repels ## 4. Cycle Through Repels
If you've still got repels in your bag the player will likely want to use those up as well. This is a modification of above to allow for that! First, we add an additional function. This can be placed right below Task_UseRepel in [src/item_use.c](../blob/master/src/item_use.c). And don't forget to declare the function up at the top!! If you've still got repels in your bag the player will likely want to use those up as well. This is a modification of above to allow for that! First, we add an additional function. This can be placed right below Task_UseRepel in [src/item_use.c](../blob/master/src/item_use.c). And don't forget to declare the function up at the top!!
@ -153,7 +175,7 @@ Sweet! Now, throw in a `callnative` in the assembly script and we're there. Over
bufferitemname 1, VAR_REPEL_LAST_USED bufferitemname 1, VAR_REPEL_LAST_USED
removeitem VAR_REPEL_LAST_USED, 1 removeitem VAR_REPEL_LAST_USED, 1
playse SE_REPEL playse SE_REPEL
msgbox gText_PlayerUsedVar2, MSGBOX_SIGN msgbox gText_PlayerUsedRepel, MSGBOX_SIGN
goto EventScript_RepelWoreOff_End goto EventScript_RepelWoreOff_End
... ...
``` ```