You are not logged in.
NOTE: So far, this has worked great in testing. But let me know if anything weird happens.
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:
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:
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:
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?).
Here is an example of how to use these new commands in an actual script.
#org 0x15CBEE '----------------------------------- faceplayer loadfont loadvar 0x21 special 0x6E if true 0x4C29 ' 0x15CC29 2writetext 0x4C7E ' 0x15CC7E closetext loadmovesprites end #org 0x15CC29 '----------------------------------- 2writetext 0x4E49 ' 0x15CE49 closetext loadmovesprites end #org 0x15CC7E = BILL: You do not\nhave TACKLE.\e #org 0x15CE49 = BILL: TACKLE ME!\e
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.
DOWNLOAD IPS PATCH:
Check them out on Github
Hey I am confused with the place to put the codes, do you mean the old pointer is located at 0x018383 and we have to place the routine in 0x01BD12? btw the patch file seems to be outdated.
Today I won't steal Pokemon
No, why would it be at those offsets? I didn't mention those anywhere lol.
The pointer is at offset xC383.
You will change the 3 bytes found there to 03 12 7D.
You will type the new routine at xFD12.
EDIT: Also, thanks, I'll fix the download link when I get the chance.
Last edited by Mateo (2015-02-21 16:15:08)
Check them out on Github