Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Generation I Glitch Discussion

Do items have priority in Gen I? - Page 1

Do items have priority in Gen I?

Posted by: lanturnite
Date: 2018-10-27 22:40:22
My friend recently watched this video by Pikasprey about using only a Ditto to beat Pokemon R/B.

They asked me about the Blaine Super Potion glitch, which has a lot of information about it (considering how small and kinda rare it is) but they also noticed that in the video, the item goes second.

What I'm curious about, is, did items have priority in Gen I? Should Blaine's Super Potion have gone first, or was this the result of a bug?

(The link to the portion of the video I'm talking about is here.)

Re: Do items have priority in Gen I?

Posted by: Sherkel
Date: 2018-10-28 03:48:11
It's just an enemy-side thing, due to the way certain trainers are programmed to use items. This and this have your answer.

call ExecutePlayerMove
ld a, $1
callab TrainerAI

If you go first, you go before the trainer AI.

ld de, wBattleMonSpeed ; player speed value
ld hl, wEnemyMonSpeed ; enemy speed value
ld c, $2
call StringCmp ; compare speed values
jr z, .speedEqual
jr nc, .playerMovesFirst ; if player is faster
jr .enemyMovesFirst ; if enemy is faster

The order is determined the way you'd expect.

cp $40
ret nc
jp AIUseSuperPotion

This is the "Blaine Super Potion glitch": it doesn't check HP, but it goes ahead and does this anyway:

; enemy trainer heals his monster with a super potion
ld b, 50
jr AIRecoverHP

And then the main battle loop continues.

Regarding priority, it doesn't really exist as a mechanic the way it does in later games. You just have Quick Attack and Counter, whose effects are described here:
ld a, [wPlayerSelectedMove]
jr nz, .playerDidNotUseQuickAttack
ld a, [wEnemySelectedMove]
jr z, .compareSpeed  ; if both used Quick Attack
jp .playerMovesFirst ; if player used Quick Attack and enemy didn't
ld a, [wEnemySelectedMove]
jr z, .enemyMovesFirst ; if enemy used Quick Attack and player didn't
ld a, [wPlayerSelectedMove]
jr nz, .playerDidNotUseCounter
ld a, [wEnemySelectedMove]
jr z, .compareSpeed ; if both used Counter
jr .enemyMovesFirst ; if player used Counter and enemy didn't
ld a, [wEnemySelectedMove]
jr z, .playerMovesFirst ; if enemy used Counter and player didn't

Re: Do items have priority in Gen I?

Posted by: ISSOtm
Date: 2018-10-28 05:45:48
Whether an AI will use Super Potions is determined by the function TrainerAI. This function is called in the normal flow of battle, and may override the selected attack; but since the decision occurs right before the move is executed instead of before the turn priority being determined, items don't have a special priority.
This also means that special move priorities (such as Quick Attack) will have the opponent use their item second (unless the opponent also picked Quick Attack).

Calls to TrainerAI are here and here.

Somewhat what Sherkel just said.