From 564cc3e73ecd73d61ef0be4fb6b6ec185a73e73c Mon Sep 17 00:00:00 2001 From: GGbond Date: Wed, 4 Feb 2026 01:32:39 +0800 Subject: [PATCH] Fix Instruct failing improperly when the instructed move isn't in the target's moveset (#9113) --- src/battle_script_commands.c | 11 ++++++++--- test/battle/move_effect/instruct.c | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 759fcaee92..64073dbadd 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -17391,21 +17391,26 @@ void BS_TryInstruct(void) gSpecialStatuses[gBattlerTarget].instructedChosenTarget = gBattleStruct->moveTarget[gBattlerTarget] | 0x4; gCalledMove = move; u32 moveIndex; + bool32 foundMove = FALSE; for (moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++) { if (gBattleMons[gBattlerTarget].moves[moveIndex] == gCalledMove) { - gCurrMovePos = moveIndex; - moveIndex = MAX_MON_MOVES; + foundMove = TRUE; break; } } - if (moveIndex != MAX_MON_MOVES || gBattleMons[gBattlerTarget].pp[gCurrMovePos] == 0) + if (!foundMove) + { + gBattlescriptCurrInstr = cmd->failInstr; + } + else if (gBattleMons[gBattlerTarget].pp[moveIndex] == 0) { gBattlescriptCurrInstr = cmd->failInstr; } else { + gCurrMovePos = moveIndex; gBattleScripting.battler = gBattlerAttacker; // for message gEffectBattler = gBattleStruct->lastMoveTarget[gBattlerTarget]; gBattlescriptCurrInstr = cmd->nextInstr; diff --git a/test/battle/move_effect/instruct.c b/test/battle/move_effect/instruct.c index 04f5558155..2f97cda162 100644 --- a/test/battle/move_effect/instruct.c +++ b/test/battle/move_effect/instruct.c @@ -97,7 +97,7 @@ DOUBLE_BATTLE_TEST("Instruct fails if target doesn't know the last move it used" GIVEN { ASSUME(IsDanceMove(MOVE_DRAGON_DANCE)); PLAYER(SPECIES_WOBBUFFET); - PLAYER(SPECIES_ORICORIO) { Moves(MOVE_SCRATCH, MOVE_POUND, MOVE_SCRATCH, MOVE_CELEBRATE); } + PLAYER(SPECIES_ORICORIO) { Ability(ABILITY_DANCER); Moves(MOVE_SCRATCH, MOVE_POUND, MOVE_SCRATCH, MOVE_CELEBRATE); } OPPONENT(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); } WHEN { @@ -113,6 +113,27 @@ DOUBLE_BATTLE_TEST("Instruct fails if target doesn't know the last move it used" } } +DOUBLE_BATTLE_TEST("Instruct fails if the instructed move's PP is depleted") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Speed(20); Moves(MOVE_INSTRUCT, MOVE_CELEBRATE); } + PLAYER(SPECIES_WOBBUFFET) { Speed(30); MovesWithPP({MOVE_SCRATCH, 1}, {MOVE_CELEBRATE, 10}); } + OPPONENT(SPECIES_WOBBUFFET) { Speed(1); } + OPPONENT(SPECIES_WOBBUFFET) { Speed(2); } + } WHEN { + TURN { MOVE(playerRight, MOVE_SCRATCH, target: opponentLeft); } + TURN { MOVE(playerLeft, MOVE_INSTRUCT, target: playerRight); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_SCRATCH, playerRight); + NONE_OF { + ANIMATION(ANIM_TYPE_MOVE, MOVE_INSTRUCT, playerLeft); + ANIMATION(ANIM_TYPE_MOVE, MOVE_SCRATCH, playerRight); + } + } THEN { + EXPECT_EQ(playerRight->pp[0], 0); + } +} + DOUBLE_BATTLE_TEST("Instruct-called move fails if it can only be used on the first turn but consumes PP") { GIVEN {