Skip to content

Make Sandstorm raise the Special Defense of Rock type Pokémon by 50%

Idain edited this page Apr 8, 2021 · 5 revisions

From generation 4 onwards, the Sandstorm weather raises the Special Defense of Rock-type Pokémon by 50%, so in this simple tutorial we'll implement this feature into Pokémon Crystal.

Contents

  1. Create the function SandstormSpDefBoost
  2. Call the function while getting the damage stats

1. Create the function "SandstormSpDefBoost"

In engine/battle/effect_commands.asm, create the new function:

+SandstormSpDefBoost: 
+; First, check if Sandstorm is active.
+	ld a, [wBattleWeather]
+	cp WEATHER_SANDSTORM
+	ret nz
+
+; Then, check the opponent's types.
+	ld hl, wEnemyMonType1
+	ldh a, [hBattleTurn]
+	and a
+	jr z, .ok
+	ld hl, wBattleMonType1
+.ok
+	ld a, [hli]
+	cp ROCK
+	jr z, .start_boost
+	ld a, [hl]
+	cp ROCK
+	ret nz
+
+.start_boost
+	ld h, b
+	ld l, c
+	srl b
+	rr c
+	add hl, bc
+	ld b, h
+	ld c, l
+	ret

The 1st thing you might've noticed is that we're using the opponent's types instead of the user's to perform the boost. This is because we're gonna make the check while getting the damage stats, i.e. when the user is attacking the opponent.

2. Call the function while getting the damage stats

In the same file, call the newly created function in both PlayerAttackDamage and EnemyAttackDamage:

PlayerAttackDamage:
	...
.special
	ld hl, wEnemyMonSpclDef
	ld a, [hli]
	ld b, a
	ld c, [hl]

+	call SandstormSpDefBoost
	...
EnemyAttackDamage:
	...
.special
	ld hl, wBattleMonSpclDef
	ld a, [hli]
	ld b, a
	ld c, [hl]

+	call SandstormSpDefBoost
	...

And that's it! Now the game will try to perform the boost while getting the Sp. Def of the opponent by first checking the weather and then the opponent's types. If the check is successful, it'll get the 50% boost from the Sandstorm.

Clone this wiki locally