diff --git a/data/scripts/repel.inc b/data/scripts/repel.inc index fc178603c..2c4e075f4 100644 --- a/data/scripts/repel.inc +++ b/data/scripts/repel.inc @@ -1,6 +1,38 @@ EventScript_RepelWoreOff:: + checkitem VAR_LAST_REPEL_USED, 1 + compare VAR_RESULT, TRUE + goto_if_eq EventScript_UseAnother + lock msgbox Text_RepelWoreOff, MSGBOX_SIGN + release + end + +EventScript_UseAnother: + lock + msgbox Text_UseAnother, MSGBOX_YESNO + compare VAR_RESULT, YES + goto_if_eq EventScript_UsedRepel + release + end + +EventScript_UsedRepel: + bufferitemname 0, VAR_LAST_REPEL_USED + playse SE_REPEL + lock + msgbox Text_UsedNewRepel, MSGBOX_SIGN + removeitem VAR_LAST_REPEL_USED, 1 + waitse + callnative HandleUseExpiredRepel + release end Text_RepelWoreOff: .string "REPEL's effect wore off…$" + +Text_UseAnother:: + .string "REPEL's effect wore off!\n" + .string "Use another?$" + +Text_UsedNewRepel:: + .string "{PLAYER} used the\n" + .string "{STR_VAR_1}.$" diff --git a/include/constants/vars.h b/include/constants/vars.h index 8128b6f32..aba1125c0 100644 --- a/include/constants/vars.h +++ b/include/constants/vars.h @@ -271,7 +271,7 @@ #define VAR_UNUSED_0x40FC 0x40FC // Unused Var #define VAR_UNUSED_0x40FD 0x40FD // Unused Var #define VAR_UNUSED_0x40FE 0x40FE // Unused Var -#define VAR_UNUSED_0x40FF 0x40FF // Unused Var +#define VAR_LAST_REPEL_USED 0x40FF // Unused Var #define VARS_END 0x40FF #define VARS_COUNT (VARS_END - VARS_START + 1) diff --git a/src/item.c b/src/item.c index f93e7adad..3a62d83e4 100644 --- a/src/item.c +++ b/src/item.c @@ -952,3 +952,8 @@ u8 ItemId_GetFlingPower(u16 itemId) { return gItems[SanitizeItemId(itemId)].flingPower; } + +void HandleUseExpiredRepel(void) +{ + VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(VarGet(VAR_LAST_REPEL_USED))); +} diff --git a/src/item_use.c b/src/item_use.c index 5cd162519..e5e38c871 100644 --- a/src/item_use.c +++ b/src/item_use.c @@ -871,6 +871,7 @@ static void Task_UseRepel(u8 taskId) if (!IsSEPlaying()) { VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId)); + VarSet(VAR_LAST_REPEL_USED, gSpecialVar_ItemId); RemoveUsedItem(); if (!InBattlePyramid()) DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, CloseItemMessage);