NOTE: So far, this has worked great in testing. But let me know if anything weird happens.

PREFACE:
========
So you know how the newer games have a handy script code you can use to check whether or not a Pokémon in your party knows a particular skill? Well, Gen II doesn't have one of those, and that makes it really annoying to try and add new things like Dive or Secret Power or whatever else you want to do. So in this tutorial, I will show you how to modify one of the unused "special" commands and turn it into a very useful "Check Attack" command.

WHAT THIS DOES
==============
This script works by calling an existing ASM routine that was originally called by things like "using surf" and the like, except instead of checking for hardcoded values it will let you choose which skill to check for in the script, and it will return a value of "true" or "false" the same as other normal commands, making it very easy to use in a script.

APPLYING THE CODE
================
We will start by repointing the old unused special (it just said "Now on Debug") to some blank space, so that we can insert our new script. You need to place this hack in Bank 3, since that is where the exising scripts were (and there is plenty of room for this small routine there, so it shouldn't be a problem). Anyway, the pointer we are looking for is found at xC383 in Pokémon Gold. It is a normal 3-byte pointer, so it can technically point to any bank. In this example, I will be repointing it to xFD12. So we will type 03 12 7D over the old pointer and save it.

Now we will go to xFD12 and enter the new routine. So you will type:

Code:

FA 73 D1 57 CD 87 47 38 06 3E 01 EA 73 D1 C9 3E 00 EA 73 D1 C9

and hit save.

That is the already compiled version, to make it quicker to put in. For those interested, the actual ASM instructions are:

Code:

ld a,(d173) // Gets the value of the skill from the VAR
ld d,a // The original routine needs the skill in register D, so we put it there
call 4787 // Calls the existing "Does a Pokemon have this skill?" routine
JR C, $06 // If the Pokémon does not have the skill, the C flag is set, so jump ahead to that case
ld a,01 // Load A with $01, the value for "true"
ld (d173),a // Put this value back in the VAR so we can check it with the "if" commands like normal
ret // Return to the script, because we are done
ld a,00 // If the Pokémon didn't have the skill, we jump here to load A with "false"
ld (d173),a // Write A to the VAR so we can check it in the script
ret // Return to the script, because we are done

I'm sure someone will find a neater way of setting that value as true or false, but that works and is simple.

USING THIS IN A SCRIPT
===================

To use the new check code in a script, all you have to do is this:

Code:

loadvar 0x?? ' Skill number to check for
special 0x6E

And it's that simple! Now sure, since the basic routine to check for a move was technically already in the rom, you could have just written a separate ASM routine that loaded the skill you wanted to check for into register D, called the checking routine, and then have it set whatever you want before returning to the script, and call that routine with the script code for calling an ASM routine. But if you plan on having several different places that check for the Pokémon having different moves, you end up wasting a lot of space having all of those virtually identical move checking routines. So IMO this is a much nicer solution (besides, it isn't like that old Special we replaced was doing any good anyway, so why not make it useful?).

APPLICATION EXAMPLE
=================
Here is an example of how to use these new commands in an actual script.

That is a quick script I used to test this code out. It checks whether or not the player has a Pokémon in the party that knows TACKLE, and Bill will say something different accordingly.

In case anyone wants to use this, but doesn't feel confident adding an ASM routine for some reason, I've attached an IPS patch that will apply this hack to the offsets I used in the example. So if you apply this when starting a new hack, you should be fine. If you are applying it to an existing hack, make sure that the area at xFD12 is free space (00s).

Let me know if anyone has any problems with this or if someone probably named Miksy91 has any suggestions on how to improve the routine.

And it seems that Miksy91 has come up with an "optimized" version of the ASM routine in question.

Code:

ld hl, d173 // Load HL with the address of the VAR
ld a, (hl) // Load A with the VAR
ld d,a // Put A into D so the old routine can use it
push hl // Push HL so we can get the address of the VAR back later
call 4787 // Call the checking routine
pop hl // Get the address of the VAR back
ld a, 01 // Load A with "true"
jr nc, 01 // If the Pokemon had the move, skip ahead
dec a // Decrease A (making it 00 or "false") if they didn't have the move
ld (hl), a // Put True or False back into the VAR
ret // Return

You can use that version if you like, it takes slightly fewer bytes than the one I made, but it is not a radical difference and the end result is the same. So that is purely up to you.

And like Mateo pointed out here, my version is no way better than what he had come up with. The only things it does "better" are reserving the address d173 in hl and avoiding copy pasting, but it's not like they would matter at all in a code this small.

(So like... the only reason I even wrote that was because of Mateo showing me this (expecting to me to check it out), so I did )