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.
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.
![[PokeCommunity.com] Pokémon Gold/Silver Scripting Tutorial [PokeCommunity.com] Pokémon Gold/Silver Scripting Tutorial](https://img508.imageshack.us/img508/6227/scriptm.png)
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.
![[PokeCommunity.com] Pokémon Gold/Silver Scripting Tutorial [PokeCommunity.com] Pokémon Gold/Silver Scripting Tutorial](https://img23.imageshack.us/img23/8650/73061894.png)
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.
Last edited: