-
Notifications
You must be signed in to change notification settings - Fork 93
Adding a Forfeit Option in the duels
Hello! In this tutorial we are going to Add a Forfeit option in the duels!
First we will add a new text, please check the "Add new text" tutorial.
+ ForfeitText:
+ text "Do you Want to Forfeit the Duel?"
+ line " No Yes"
+ done
This will be our way of ensuring that the player really wants to forfeit the duel or not.
Now we are going to add this code in Effect Functions, please check the "Choices Within Attacks" tutorial.
+PlayerForfeitEffect:
+ bank1call DrawDuelMainScene ; draws a screen for the player to select from
+ ldtx hl, ForfeitText ; loads the text we made in step 1
+ call TwoItemHorizontalMenu ; defines that this text contains 2 menu items (no/yes)
+ ldh a, [hKeysHeld] ; loads the player's input
+ and B_BUTTON
+ jp nz, PlayerYesNoEffect ; this forces the player to select either "Yes" or "No", can't exit
+ ldh a, [hCurMenuItem] ; stores the result in a
+ ldh [hTemp_ffa0], a ; loads what the player selected into hTemp_ffa0
+ ret
What this would do is ask the Player using the text we added, depending on the response (Yes or no), x or y will happen which we would define in the next step.
Now we will add the actual effect. Go to the file in src/engine/duel/core.asm and in line 328 we would add this:
bit START_F, a
jp nz, DuelMenuShortcut_OpponentActivePokemon
+ bit SELECT_F, a
+ jp nz, HandleBetweenTurnKnockOuts.set_player_forfeit
.b_not_held
ldh a, [hKeysPressed]
and START
Now if we read a little of the current function we will see that it would jump to another one depending on which combination of buttons are pressed, in this case it is HOLD_B+SELECT, which would jump directly to our own custom code right after line 7320, under .set_duel_finished:
.asm_6ec4
ld e, a
ld d, $00
ld hl, .Data_6ed2
add hl, de
ld a, [hl]
.set_duel_finished
ld [wDuelFinished], a
scf
jr .asm_6eb2
+.set_player_forfeit
+ farcall PlayerForfeitEffect
+ ldh a, [hTemp_ffa0]
+ or a
+ jp z, DuelMainInterface
+ ld a, TURN_PLAYER_LOST
+ ld [wDuelFinished], a
+ scf
+ jr .asm_6eb2
So, This will be activated the moment the player holds down the B-button and presses Select in the main battle menu and will ask if they want forfeit the duel. If the player chooses No, the menu will return to normal; if they choose Yes, the duel will end with the other player winning.