PHO - Pokémon Hackers Online
Go Back   PHO - Pokémon Hackers Online > Hacking Suite > Resources and Tutorials > Generation 1 & 2


Generation 1 & 2 RBY and GSC Resources and Tutorials. Mostly for disassembly.

User Tag List

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 14th March 2014, 09:26 PM   #1
Johto Region Champion
AdministratorPHO VIP
Luna's Avatar
Join Date: Jul 2013
Location: Johto
Age: 29
Posts: 779
Luna Luna Luna Luna Luna
Default [Gold] Adding a "Check Attack" script code

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.

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.

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.


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
loadvar 0x21
special 0x6E
if true 0x4C29 ' 0x15CC29
2writetext 0x4C7E ' 0x15CC7E

#org 0x15CC29
2writetext 0x4E49 ' 0x15CE49

#org 0x15CC7E
= BILL: You do not\nhave TACKLE.\e

#org 0x15CE49
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.
Attached Files
File Type: ips Check For Skills.ips (42 Bytes, 8 views)

"I'm gonna, uh, demonstrate the hot moves..." - Flannery
Luna is offline   Reply With Quote
Sponsored Links

adding, check attack, code, gold, script, [Tutorial]

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 02:36 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc. User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
Pokémon characters and images belong to Pokémon USA, Inc. and Nintendo.
Pokémon Hackers Online (PHO) is in no way affiliated with or endorsed by Nintendo LLC, Creatures, GAMEFREAK inc,
The Pokémon Company, Pokémon USA, Inc., The Pokémon Company International, or Wizards of the Coast.
All forum/site content (unless noted otherwise) and site designs are © 2006-2013 Pokémon Hackers Online (PHO).
Green Charizard Christos TreeckoLv100

"Black 2" by ARTPOP. Kyurem artwork by XOUS.

no new posts