mirror of https://github.com/pret/pokeemerald.git
Added repel cycle-through!
parent
7acd1079ed
commit
296a0436ad
|
@ -5,6 +5,7 @@ This tutorial will ask the player, upon a Repel running out, if they want to use
|
|||
## Contents
|
||||
1. [Store last used Repel](#1-store-last-used-repel)
|
||||
2. [Ask the player](#2-ask-the-player)
|
||||
3. NEW - [Cycle through remaining repels](#3-cycle-through-repels)
|
||||
|
||||
## 1. Store last used Repel
|
||||
|
||||
|
@ -89,3 +90,72 @@ And that's it!
|
|||
![](https://i.imgur.com/t0OKP9X.png)
|
||||
|
||||
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
|
||||
|
||||
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!!
|
||||
|
||||
```diff
|
||||
static void Task_UseRepel(u8);
|
||||
+void Cycle_Through_Repels(void);
|
||||
static void Task_CloseCantUseKeyItemMessage(u8);
|
||||
```
|
||||
This is a great time to point out how the function has `static` omitted.
|
||||
|
||||
From my understanding, `static` makes the function local to a file and therefore unable to be called from outside. Because we're going to use `callnative` again over in the assembly side of things, we want to declare it just like we did `ItemId_GetHoldEffectParam_Script`. (Btw, feel free to move this over to [src/item.c](../blob/master/src/item.c) with `ItemId_GetHoldEffectParam_Script` if you like the consistency, but just make sure to declare it in that `.h` file as well.)
|
||||
|
||||
Now, onto the function!
|
||||
```diff
|
||||
static void Task_UseRepel(u8 taskId)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
+ void Cycle_Through_Repels(void)
|
||||
+ {//Once the last repel of the chosen type has been depleted, find the next lowest repel class
|
||||
+ //and start using it! (Set it as VAR_REPEL_LAST_USED)
|
||||
+
|
||||
+ u16 RepelCycle[] = {ITEM_REPEL, ITEM_SUPER_REPEL, ITEM_MAX_REPEL};
|
||||
+ u8 i = 0;
|
||||
+
|
||||
+ while (gSpecialVar_Result == FALSE){
|
||||
+ gSpecialVar_Result = CheckBagHasItem(RepelCycle[i],1);
|
||||
+ if (gSpecialVar_Result == TRUE)
|
||||
+ VarSet(VAR_REPEL_LAST_USED, RepelCycle[i]);
|
||||
+ i++;
|
||||
+ if (i > 2)
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ return;
|
||||
+ }
|
||||
```
|
||||
Since we walked through it above, let's do the same here. Remember, this function occurs after all previous repels of a type were depleted (remember `compare VAR_RESULT, FALSE`?), so now we need to find if there are any others and store them in `VAR_REPEL_LAST_USED` to update the script.
|
||||
|
||||
First we make an array with all the repel item IDs and declare an increment variable `i`. Next, we loop through the repels one by one and check if they exist in the bag - note that since `ITEM_REPEL` is listed first (in the 0th array index), it will look for this first in the loop. If none are found (`VAR_RESULT` still shows as `FALSE`) it'll look for super repels, then finally max repels. In this way all the smaller items are used first and the player's bag can clear them out. Finally, if no other repels are found, we want to stop the loop at `i > 2` and `return` to the script empty-handed, which is better than spiralling away to infinity in misery.
|
||||
|
||||
NOTE: If you want to just grab the smallest repel type after the first one gets depleted (rather than waiting for all repels of its kind to run out), just change the `while` to a `For (i = 0, i = 3, i++)` loop and get rid of the `if (i > 2)` stopper.
|
||||
|
||||
Sweet! Now, throw in a `callnative` in the assembly script and we're there. Over in [data/scripts/repel.inc](../blob/master/data/scripts/repel.inc):
|
||||
```diff
|
||||
EventScript_RepelWoreOff::
|
||||
lockall
|
||||
checkitem VAR_REPEL_LAST_USED, 1
|
||||
+ callnative Quick_Repel_Cycle
|
||||
compare VAR_RESULT, FALSE
|
||||
goto_if_eq EventScript_RepelWoreOff_NoMoreRepels
|
||||
msgbox Text_RepelWoreOff_UseAnother, MSGBOX_YESNO
|
||||
compare VAR_RESULT, 0
|
||||
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_REPEL
|
||||
msgbox gText_PlayerUsedVar2, MSGBOX_SIGN
|
||||
goto EventScript_RepelWoreOff_End
|
||||
...
|
||||
```
|
||||
|
||||
Happy hunting!
|
Loading…
Reference in New Issue