PHO - Pokémon Hackers Online
Go Back   PHO - Pokémon Hackers Online > Generation I/II Hacking > Guides & Documentation

Guides & Documentation Have a tutorial or a document to share? Post it here.

User Tag List

Reply
 
Thread Tools Display Modes
Old 14th March 2014, 09:26 PM   #1
Mateo
Johto Region Champion
AdministratorPHO VIP
 
Mateo's Avatar
 
Join Date: Jul 2013
Location: Johto
Age: 28
Posts: 813
Mateo Mateo Mateo Mateo Mateo
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.

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.

Code:
#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.
Attached Files
File Type: ips Check For Skills.ips (42 Bytes, 7 views)
__________________
mateo.





"I'm gonna, uh, demonstrate the hot moves..." - Flannery
Mateo is offline   Reply With Quote
Likes Zoe Ayamoto, Miksy91 liked this post
Sponsored Links
Old 14th March 2014, 10:07 PM   #2
Mateo
Johto Region Champion
AdministratorPHO VIP
 
Mateo's Avatar
 
Join Date: Jul 2013
Location: Johto
Age: 28
Posts: 813
Mateo Mateo Mateo Mateo Mateo
Default

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.
__________________
mateo.





"I'm gonna, uh, demonstrate the hot moves..." - Flannery
Mateo is offline   Reply With Quote
Old 14th March 2014, 10:11 PM   #3
Miksy91
Gotta fill something here.
 
Miksy91's Avatar
 
Join Date: Jul 2013
Location: Northern Europe
Age: 26
Posts: 127
Miksy91
Default

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 )
__________________
Miksy91 is offline   Reply With Quote
Likes Mateo liked this post
Old 14th March 2014, 11:46 PM   #4
Zoe Ayamoto
Only Love Me...or Die
 
Zoe Ayamoto's Avatar
 
Join Date: Nov 2013
Location: Guatemala City
Age: 22
Posts: 63
Zoe Ayamoto
Default

Wow, this very AWESOME!!!!!!

The routine is very useful, now can make a real Rock Climb instead make a item to my hack, Thanks Matt <3
__________________
Zoe Ayamoto is offline   Reply With Quote
Likes Mateo liked this post
Old 14th March 2014, 11:59 PM   #5
Mateo
Johto Region Champion
AdministratorPHO VIP
 
Mateo's Avatar
 
Join Date: Jul 2013
Location: Johto
Age: 28
Posts: 813
Mateo Mateo Mateo Mateo Mateo
Default

Quote:
Originally Posted by ~G0LD! View Post
Wow, this very AWESOME!!!!!!

The routine is very useful, now can make a real Rock Climb instead make a item to my hack, Thanks Matt <3
Glad to help out :3
__________________
mateo.





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

Tags
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 08:48 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc. User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2017 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