The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > ROM Hacking > Tools, Tutorials & Resources
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.
New threads in this forum are to be approved by a moderator before they are displayed.


Reply
 
Thread Tools
  #1    
Old April 24th, 2011, 11:55 PM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
First of all, scripting in second generation games can be done by only hex editing bytes or using a scripting tool beside with your hex editor. I prefer doing it myself the second way. Then again, using only a tool (by this time, I believe only PKSV supports 2nd gen games) is not an option. PKSV is mostly designed for editing games of third generation and doesn't recognize several commands as working scripts in second gen games.


Pokémon G/S/C Scripting Tutorial


Let's get started but the beginning of this explanation is going to be somewhat "out of the topic" because you should understand the specifics of Map Headers before moving on to scripting. Now that Johtomap is out though, it's not 100% necessary...

Each map contains its Primary Header.
Primary Header for example defines:
1) The music played on that map
2) Tileset used
3) Where the map belongs to (for example, player's house belongs to 01 which stands for NEW BARK TOWN)
4) Type of the map (I think this determines whether you can use Dig and Fly, maybe other commands too)
5) Pointer to map's Secondary Header

Secondary Header is a structure that tells the game:
1) Border tile
2) Width & Height
3) Where the map data is located
4) Where the events are
5) Where is the map's Script Header (this is usually marked as 00 00 just before the script data that different events on that map point to)
6) Map connections


Now, as you probably know (or not), events itself have their own script pointers to their scripts. To understand the data structure of events better, read "event structure" part in Tauwasser's Scripting Compendium.

So, as you can see (by reading that part of the scripting compendium), "Trigger events", "Signposts" and "People" events have a 2-byte pointer to their script data. By calculating the pointed offset with that pointer (by understanding GB/C Pointers first), you're able to find the script.



Scripting

When you've gotten the hang of Map Headers and completely understand how GB/C Pointers work, you can move on to scripting.
Then again, if you're not there yet, study how the base structures work first.

Let's start with some basic scripts.
Most people events point to structures of this kind:

1) 51 XX YY

As you can see in the compendium, that basically makes the talked-to person turn towards HIRO (6A), load font (47), display text (4C) through a 2-byte pointer (XX YY), close text (53), load moving sprites (49) and end the script (90).

Game uses command 51 XX YY to save space as it clearly uses less space than 6A 47 4C XX YY 53 49 90.


Now, let's move on to more difficult scripts.

2) "Give item" -script

As you can see in the compendium,

1F give item code:
-------------------

Gives item (item no) amount times.
Gives feedback: 00 = bag full, 01 = OK

Structure:
[1F][item no][amount]


This time there are actually four "key commands" you're going to have to use.

[31] [Bit no (2-byte)]
[09] [2byte pointer]
[1F] [item no] [amount]
[33] [Bit no (2-byte)]

As an example, I changed the script pointer of the fat man in New Bark Town to 00 70 so that it would point to a blank space to offset 0x123000.
There, I started writing a "give item" -script.

$123000
31 43 06 09 1A 70 6A 47 4C 40 70 53 1F AD 01 33 43 06 49 90

$12301A
51 20 70

$123020
"U already got a Berry!"

$123040
"Hey, take Berry!"


Now, this calls for a brief explanation now doesn't it :D ?
"43 06" is the Flag Bit I decided to use.
Check this thread that Koolboyman has created.
You can see that bit number 4306 stands for one item ball in Violet City.
In case this man also uses flag bit 4306 so that item ball should be made un-obtainable to avoid glitches.

"AD" is the byte used for Berry which I picked up from Giegue's Master Hacking Guide.


About the script itself though, the first part of the script "31 43 06" checks if flag bit 4306 has been activated or not. This information will be sent to another part in RAM memory (00 = Flag bit not activated, 01 = Flag bit activated). So basically, the game is told to write either 00 or 01 into a place in RAM where the game checks with code 09 if the value in that offset is different from 0.

"09: When [RAM] <> 0, go to the pointed script. Else resume interpreting after the pointer."

*In this case, RAM is different from 0 if it's 01.


Now, if flag bit 4306 is activated, the game will continue at offset $12301A (because 2byte pointer 1A 70 points to it). At offset $12301A, you can find a similar script as explained above.

Anyway, if the flag bit is not activated, the main script will go on and as you can see, the talked-to person faces HIRO, loads font, displays text at offset $123040, closes text box and gives you an item (one Berry).
After that, flag bit 4306 is activated with code 33.
In the end, moving sprites are loaded and script is ended.

Here is a video of the script and a small enhancement to it.





Here is what the script looks like in PKSV.




As you can see, this is a more user-friendly way to show it but your biggest problem with PKSV can be the fact, you don't understand what different scripting commands mean (for example jumptextfaceplayer which stands for 51). This is one reason why it's best to use a hex editor with this tool.

Besides, there are several types of scripts that you can't edit with PKSV because only part of their code is normal script data, the rest isn't (for example trainer scripts, item scripts and scripts of script header).




3) Pokemon battle event

Here is another example.
This time, I made the fat man point to another script in offset 0x123100 (by changing his script pointer to 00 71).

$123100
6A 47 4C 20 71 53 83 06 00 1E 03 07 5C 06 01 5E 5F 6D 03 49 90


$123120
"CHAAR!!!"

In this script, the talked-to person faces HIRO, displays text at offset 0x123120, closes text box, plays Charizard's cry (83 06 00), loads a shiny pokemon fight (1E 03 07), loads the pokemon data of the encountered pokemon (5C 06 01), starts battle (5E), returns to ingame engine after battle (5F), hides person (6D 03), loads moving sprites and ends the script.





This time, you're going to have to give the flag bit to the person event itself, not to the script. If there is a flag bit for a person event that is being made hidden, that event won't show anymore if the map is entered again. This is mostly used for items but in occasions like this, you're going to have to do the exact same thing. In this case, I changed the flag bit of that fat man to 1700. It doesn't make any difference which flag bit you use if some other script doesn't use the exact same flag.

__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations

Last edited by miksy91; August 6th, 2012 at 03:06 AM.
Reply With Quote
  #2    
Old April 29th, 2011, 11:51 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Somewhat disappointed to see that nobody replied - should have guessed as most people hack 3rd gen anyways.

I thought that I could nevertheless expand this tutorial by putting up new script examples and probably tell something about the script header and such.
If someone actually wants to see more, ask !
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
  #3    
Old April 29th, 2011, 01:05 PM
machomuu's Avatar
machomuu
Fueled by Pepsi
Community Supporter
 
Join Date: Apr 2008
Location: 'Murca
Gender: Male
Nature: Relaxed
Wow Milksy, I might give this a shot. I've never used PKSV, I've always been an XSE man myself, but I think I'll try it out, thanks for the excellent tutorial :D.
__________________
Reply With Quote
  #4    
Old April 29th, 2011, 01:24 PM
Chimchar 9's Avatar
Chimchar 9
inactive ~ depression :/
 
Join Date: Jan 2008
Location: England, Southampton.
Age: 20
Gender: Male
Nature: Calm
Send a message via Windows Live Messenger to Chimchar 9
Finally, there's a scripting Tutorial for G/S/C! I've been waiting for one for ages. I shall try it out soon! Thank you and please add more if you can! :D
__________________
Pokemon Green Diamond
Status: On Hold.
Reply With Quote
  #5    
Old April 29th, 2011, 01:28 PM
Jack Cayman
 
Join Date: Apr 2011
Gender: Male
I might try this when it is more known and is slightly easier to do. I usually don't use hex editors too often, but this may make it seem a little interesting.
__________________
Reply With Quote
  #6    
Old April 29th, 2011, 04:17 PM
Sawakita's Avatar
Sawakita
Not Invented Here
 
Join Date: May 2010
Gender: Male
Good tutorial Miksy! I hope this will convince more people to enjoy GSC scripting and hacking.

On a side note: I think you're allowed to post external links as long as they're relevant to the thread (this is actually the right case), as you can see in this sadly forgotten thread.
__________________



| 1st Gen Hacking: Useful Links | A good example of REAL ROM Hacking |
Reply With Quote
  #7    
Old April 29th, 2011, 11:20 PM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Thanks for all the positive comments

By request, I happened to write another example.
In it, you encounter a shiny Charizard and I might put up a video of it too.
Check the bottom of the first post to see what it could look like.
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
  #8    
Old May 8th, 2011, 02:43 AM
itari's Avatar
itari
Community Supporter
 
Join Date: Mar 2010
Location: 渦潮隠れの里
Age: 17
Gender: Female
Nature: Relaxed
This is a great tutorial! It's pretty cool that you can have any Pokemon be shiny for a battle. I thought it was special for the gyarados only.
__________________
Reply With Quote
  #9    
Old June 13th, 2011, 12:24 PM
FireSlasher's Avatar
FireSlasher
Beginner Hacker seeking help
 
Join Date: Apr 2009
Location: Massachusetts
Age: 18
Gender: Male
Nature: Lax
Send a message via Yahoo to FireSlasher Send a message via Skype™ to FireSlasher
this is slightly off AND on topic. im trying to teach myself to hex edit, and i was attempting to use goldfinger. im completely lost and curious if icould get some help from anybody familiar with goldfinger or any other program
__________________
This signature has been disabled.
100px too wide
Please review and fix the issues by reading the signature rules.

You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.

Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
Reply With Quote
  #10    
Old June 30th, 2011, 06:46 PM
TheOrangePichu's Avatar
TheOrangePichu
Currently working on new hack
 
Join Date: Jun 2011
Location: Earth
Gender: Male
Nature: Jolly
Saw your tutorial and I also saw a pretty old tutorial made by cooley. Are these two scripting procedures the same? (using the same commands) or is there something different both of you guys did?
Reply With Quote
  #11    
Old July 7th, 2011, 11:44 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Quote:
Originally Posted by TheOrangePichu View Post
Saw your tutorial and I also saw a pretty old tutorial made by cooley. Are these two scripting procedures the same? (using the same commands) or is there something different both of you guys did?
If you meant, "did you use different commands to explain it ?", then yes but both of us used Tauwasser's Scripting Compendium as base.
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
  #12    
Old July 18th, 2011, 12:23 PM
Cheesewig's Avatar
Cheesewig
Hi!
 
Join Date: Jul 2011
Gender: Male
Nature: Relaxed
Just wondering if anyone could help me make a script.

The script is like the Guide gent script.
I need the player to follow the character around the map.
Could anyone help me?
Reply With Quote
  #13    
Old August 26th, 2011, 07:02 PM
HackChu's Avatar
HackChu
I need a haircut...
Community Supporter Tier 1
 
Join Date: Jan 2007
Location: Bankrupt Amerika
Age: 21
Gender: Male
Nature: Modest
Very good thread. Thanks Milksy, this helps alot my friend.
__________________
Join us!

My 'learning how to combine battle scripts' thread:
http://www.pokecommunity.com/showthread.php?t=183001

SoulSilver FC:1162 1864 5409
Name: Ethan

Black FC: 2666 1354 4379
Name: Ashton

White 2 FC: 1120 8065 3049
Name: Nate

3DS Friend Code: 1349-4646-2412
Name: tysonrss
Reply With Quote
  #14    
Old September 3rd, 2011, 04:02 PM
hinkage's Avatar
hinkage
Go make some new disaster
Community Supporter
 
Join Date: Aug 2010
Age: 18
Hey thanks. It's not as long as some GBA ones but it was nice of you to do this. Too bad editing random Trainers requires hex editing. I REALLY loathe hex editing. It's so obsolete when writing programs, and only good for hacking >_>
__________________
(ღ˘⌣˘ღ)
Reply With Quote
  #15    
Old September 14th, 2011, 11:01 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
I'm still checking this thread every once in a while so in case you have questions about scripting, feel free to ask.
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
  #16    
Old September 30th, 2012, 07:11 PM
RPD490's Avatar
RPD490
 
Join Date: Jan 2009
Location: Blackthorn City, Johto
Gender: Male
Nature: Relaxed
Wow, I just realized how much more harder it is for me to get one script down, when I was able to do 3-4 types of scripts for FireRed. Anyway I just wanna be able to do a test script for within the Safari Zone, if you saw in the Skeetendo Forum, I posted a pic of a redesigned version of the unused Safari Zone and I wouldn't put anything special in it, just a place you can visit, as well as catch Pokemon in the back, kinda of like the National Park, only this one is in Kanto and is much smaller XD

Anyway if I wanna be able to get more event data to work within there, would I wanna repoint the Map Event Data to maybe the National Park's since the Safari Zone uses the tiles and block data from the National Park. Because really learning how to repoint data is pretty much the barrier thats in my way before I can get into scripting. XD
Reply With Quote
  #17    
Old September 30th, 2012, 08:24 PM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Quote:
Originally Posted by RPD490 View Post
Wow, I just realized how much more harder it is for me to get one script down, when I was able to do 3-4 types of scripts for FireRed. Anyway I just wanna be able to do a test script for within the Safari Zone, if you saw in the Skeetendo Forum, I posted a pic of a redesigned version of the unused Safari Zone and I wouldn't put anything special in it, just a place you can visit, as well as catch Pokemon in the back, kinda of like the National Park, only this one is in Kanto and is much smaller XD

Anyway if I wanna be able to get more event data to work within there, would I wanna repoint the Map Event Data to maybe the National Park's since the Safari Zone uses the tiles and block data from the National Park. Because really learning how to repoint data is pretty much the barrier thats in my way before I can get into scripting. XD
You could check out a pointer tutorial I've written and yes, to make Safari Zone actually like a playable map, you'll have to repoint event data to blank space (00 00 00...) and write your own events there and have their script pointers point to blank space in the same rom bank and fill the wanted scripts in there. It's not that complicated once you get used to it.
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
  #18    
Old October 1st, 2012, 05:16 PM
RPD490's Avatar
RPD490
 
Join Date: Jan 2009
Location: Blackthorn City, Johto
Gender: Male
Nature: Relaxed
Well after learning how to do all this, and thanks to Mateo's tutorial on adding events to Goldmap, I was able to repoint the event data to a free space. So now I just need to do is add scripting to the people I placed in there, as well as the signpost, and adding wild Pokemon data to the park.
Reply With Quote
  #19    
Old October 8th, 2012, 01:31 AM
jackiekis
Unhatched Egg
 
Join Date: Oct 2012
Gender: Male
Oh, please, tell me... I spent months trying to figure out how to modify the Learnset and the level at which pokémon evolve in Gold Edition. Do you use any kind of software, or you do it by code? I would be forever indebted to you if you help me
Reply With Quote
  #20    
Old October 13th, 2012, 06:44 PM
theoblivinator's Avatar
theoblivinator
1337 Poisons
 
Join Date: May 2009
Location: Iowa
Age: 23
Gender: Male
Nature: Careful
Quote:
Originally Posted by jackiekis View Post
Oh, please, tell me... I spent months trying to figure out how to modify the Learnset and the level at which pokémon evolve in Gold Edition. Do you use any kind of software, or you do it by code? I would be forever indebted to you if you help me
You can edit the evolutions and the learnsets of Pokemon using a HEX editor.

In Pokemon Gold go to offset 0x427BD. There will be a table of 251 two-byte pointers that point to the learnset and evolution data for each Pokemon, in Pokedex order. For instance the first pointer is Bulbasaur's and is B3 69 which points to offset 0x429B3.

Go to offset 0x429B3 and you will find Bulbasaur's evolution and learnset data in this format:

[Evolution Data] 00 [Attack Data] 00

Evolution Data is defined like this:

[Evolution Type] [Trigger] [What Pokemon to evolve into]

Evolution types:

0x01 = Level evolution. Your trigger will be the level you want the Pokemon to evolve at.

0x02 = Item evolution. Your trigger will be the item you need to use on the Pokemon to evolve it.

0x03 = Held item trade evolution. Your trigger will be the item your Pokemon needs to be holding while traded to evolve. If you don't need an item the value is 0xFF.

0x04 = Happiness evolution. Your trigger will be any of these values: 0x01 can evolve at any time of day, 0x02 can evolve during the morning or day, 0x03 can evolve at night.

0x05 = Stat evolution (at a certain level). Your trigger will be two bytes long, the first byte will be your level, the second byte will be any of these values: 0x01 for Attack > Defense, 0x02 for Attack < Defense, 0x3 Attack = Defense.

Attack Data is defined like this:

[Level] [Attack]

Remember all your values need to be in hexadecimal.
Reply With Quote
  #21    
Old March 10th, 2014, 05:40 AM
hakinfreak
 
Join Date: Mar 2014
Location: follow my steps
Gender: Male
Nature: Calm
<p>thanks alot for such a tutorial. Can u tell a bit about flags and how they work? </p><p>&nbsp;</p>
Reply With Quote
  #22    
Old April 10th, 2014, 02:53 AM
masterxy's Avatar
masterxy
 
Join Date: Nov 2013
Location: Austria
Gender: Male
Nature: Relaxed
Nice Tutorial
Seeing as there's no real script editor for second gen I might add that to the Tool I'm writing atm. But it will have low priority. Of course I'd need to find out what all the bytes mean first too
But indeed a nice starting point to GSC Scripting
__________________
Double Battle Team

Reply With Quote
  #23    
Old April 11th, 2014, 03:13 PM
com3tiin's Avatar
com3tiin
Soy chamber...
 
Join Date: Jan 2013
Gender: Male
PKSV works perfectly for the second generation games, only a few commands are different, but the truth is that it works 100%

Thanks to your tutorials I learned to use pKSV
Reply With Quote
  #24    
Old April 12th, 2014, 11:45 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Quote:
Originally Posted by masterxy View Post
Nice Tutorial
Seeing as there's no real script editor for second gen I might add that to the Tool I'm writing atm. But it will have low priority. Of course I'd need to find out what all the bytes mean first too
But indeed a nice starting point to GSC Scripting
We've got all the information right here
http://hax.iimarck.us/files/scriptingcodes_eng.htm

Tauwasser has explained a few codes wrong. For instance codes "0A and 0B" should be swapped in terms of what they do, but apart from those small errors, that document is brilliant.

Quote:
Originally Posted by com3tiin View Post
PKSV works perfectly for the second generation games, only a few commands are different, but the truth is that it works 100%

Thanks to your tutorials I learned to use pKSV
Well actually, pskv has a few bugs in it and some things could be implemented better in it as well. But it works well for the most stuff. Only things I can remember it "does" wrong are "fruittree" and some phone call command.

Quote:
Originally Posted by hakinfreak View Post
<p>thanks alot for such a tutorial. Can u tell a bit about flags and how they work? </p><p>&nbsp;</p>
Not sure if you're still around or not, but flags are 16-bit values that tell, which value to check from a table that starts in ram address $D7B7.

For example, flag "2A 03" represents for "0x32A"th flag which would be in address: $D7B7 + 0x32A / 0x8

*that dividing by 0x8 comes from the fact that we have to convert the bit value to hexadecimal first before we can sum that to the start of the table ($d7b7).

Once you set a bit number / flag, "1" is written to the address where the flag "points to" and when you reset a flag, "0" is written to that same address. So flags simply point to a single bit in ram.
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

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
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 10:54 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.