Force Set battle style or forbid item usage in battle - pret/pokecrystal GitHub Wiki

This tutorial explains how to force a battle style and forbid the use of items in battles outside of places such as the Battle Tower and link battles. This method is credited to Seasick.

Contents

  1. Force a battle style
  2. Forbid item usage
  3. Implement a new battle type in a trainer battle
  4. Optional: Fix the item prohibition text

1. Force a battle style

Edit constants/battle_constants.asm:

; battle types (wBattleType values)
	const_def
	const BATTLETYPE_NORMAL
	const BATTLETYPE_CANLOSE
	const BATTLETYPE_DEBUG
	const BATTLETYPE_TUTORIAL
	const BATTLETYPE_FISH
	const BATTLETYPE_ROAMING
	const BATTLETYPE_CONTEST
	const BATTLETYPE_SHINY
	const BATTLETYPE_TREE
	const BATTLETYPE_TRAP
	const BATTLETYPE_FORCEITEM
	const BATTLETYPE_CELEBI
	const BATTLETYPE_SUICUNE
+	const BATTLETYPE_SET

Here we are adding the BATTLETYPE_SET constant to be used in trainer scripts. In fact, we are technically not forcing a battle style. Rather than directly changing the battle style option to Set, as it's done in the Battle Tower, we are simply using a battle type to make an exception for the Pokémon switch check that takes place after defeating a Pokémon. This will be explained further below.

Edit engine/battle/core.asm:

CheckWhetherToAskSwitch:
	ld a, [wBattleHasJustStarted]
	dec a
	jp z, .return_nc
	ld a, [wPartyCount]
	dec a
	jp z, .return_nc
	ld a, [wLinkMode]
	and a
	jp nz, .return_nc
	ld a, [wOptions]
	bit BATTLE_SHIFT, a
	jr nz, .return_nc
	
+	ld a, [wBattleType]
+       cp BATTLETYPE_SET
+       jr z, .return_nc

This function checks, as its name implies, whether to ask to switch Pokémon after the player defeats a Pokémon in battle. As mentioned above, we are not checking for the actual battle style option selected by the player, but simply checking if BATTLETYPE_SET is being used for the battle in question. If it is, then the check ends and the switch question is skipped.

2. Forbid item usage

Edit constants/battle_constants.asm again:

; battle types (wBattleType values)
	const_def
	const BATTLETYPE_NORMAL
	const BATTLETYPE_CANLOSE
	const BATTLETYPE_DEBUG
	const BATTLETYPE_TUTORIAL
	const BATTLETYPE_FISH
	const BATTLETYPE_ROAMING
	const BATTLETYPE_CONTEST
	const BATTLETYPE_SHINY
	const BATTLETYPE_TREE
	const BATTLETYPE_TRAP
	const BATTLETYPE_FORCEITEM
	const BATTLETYPE_CELEBI
	const BATTLETYPE_SUICUNE
        const BATTLETYPE_SET
+	const BATTLETYPE_SETNOITEMS

Just like in step 1, we are adding a battle type, this time for both forcing Set and forbidding item usage. You may also wish to create a battle type that forbids items but does not force Set (e.g. BATTLETYPE_NOITEMS). If so, make sure to add another constant here.

Edit engine/battle/core.asm again:

CheckWhetherToAskSwitch:
	ld a, [wBattleHasJustStarted]
	dec a
	jp z, .return_nc
	ld a, [wPartyCount]
	dec a
	jp z, .return_nc
	ld a, [wLinkMode]
	and a
	jp nz, .return_nc
	ld a, [wOptions]
	bit BATTLE_SHIFT, a
	jr nz, .return_nc
	
	ld a, [wBattleType]
        cp BATTLETYPE_SET
        jr z, .return_nc
+       cp BATTLETYPE_SETNOITEMS
+       jr z, .return_nc

As we did in the second part of step 1, we're adding the check for our second new battle type, which will also be forcing the Set battle style. If you made a third constant that forbid items but didn't force Set, you wouldn't run a check for that third constant here.

Edit engine/battle/core.asm one last time:

BattleMenu_Pack:
	ld a, [wLinkMode]
	and a
	jp nz, .ItemsCantBeUsed
	
+       ld a, [wBattleType]
+       cp BATTLETYPE_SETNOITEMS
+       jp z, .ItemsCantBeUsed 

Here, we are adding a check in order to skip the Battle Pack call, which would load the pack once selected. Similar to the link battle check already in the code, this new one will check whether we are using BATTLETYPE_SETNOITEMS. If so, we jump to .ItemsCantBeUsed, which skips the pack call and loads text saying that items can't be used. If you added the third constant, you would want the same check for that battle type here as well.

3. Implement a new battle type in a trainer battle

Now that the battle types and checks have been implemented, it's time to add one to a trainer battle script. We'll use the battle with Red as an example.

Edit maps/SilverCaveRoom3.asm:

Red:
	special FadeOutMusic
	faceplayer
	opentext
	writetext RedSeenText
	waitbutton
	closetext
	winlosstext RedWinLossText, RedWinLossText
	loadtrainer RED, RED1
+       loadvar VAR_BATTLETYPE, BATTLETYPE_SET
	startbattle

Voilà! With that battle type set, the player won't be asked whether they would like to switch Pokémon after defeating one, regardless of which battle style has been selected in Options. If you would like to have both forced Set and forbidden items in the same battle, swap out BATTLETYPE_SET for BATTLETYPE_SETNOITEMS. If you added the third battle type that I mentioned (or any other), include it here in the same way.

4. Optional: Fix the item prohibition text

You may want to take this opportunity to change the text used when you are unable to use items in battle. The original text states that "Items can't be used here." While this is appropriate in the Battle Tower, it sounds odd when used in proximity of other trainers that don't force Set, since the item prohibition is not location-based in that instance.

Edit data/text/battle.asm:

	BattleText_ItemsCantBeUsedHere:
	text "Items can't be"
-	line "used here."
+       line "used right now."
	prompt