[Tutorial]Intro to Scripting In Hex

View previous topic View next topic Go down

[Tutorial]Intro to Scripting In Hex

Post by Mateo on Mon Jul 01, 2013 2:27 am

Okay, this is a basic introductory tutorial to script hacking/creating in Pokémon Gold/Silver. It makes heavy reference to Tauwasser's Scripting compendium, posted in another topic on here.

Here's how to get started:

1. Go to the event data, and find blank space in the same bank
2. Enter your new script in the blank space
3. Go back to the event's data and change the pointer there to point to the start of your new script instead of the old one. (where the pointer is in their data is explained in the compendium, near the bottom)

In addition to the pointer pointing to the start of the script, you will have to use pointers at various other times in your script if they are necessary. These are all documented in the compendium as to which codes require a pointer and what exactly that pointer points to.

For example, if you want to show text, you would load the font (47) then call the text (4C, followed by a 2 byte pointer to the text (in the same bank), Then go on with the rest of your script. It seemed complicated at first for me too. Lord knows it took me a while to get it down, and I still haven't experimented with all the script codes yet. When I first made the Museum cost money to enter I had the bytes for the money all turned around  Razz So it's always a learning process, but you will get it with practice. Rome wasn't built in a day, and neither will your Rom hack.

When I personally was learning to script, what I did was I would go to a person's script pointer, and write down the codes in notepad (one code per line) then go in a write next to them what they did. I would just go a handful at the time until I reached the end of the script. It's a little time consuming, but most scripts are short so it doesn't usually take very long. What I would end up with would look like this:


Or occasionally something a little longer

09-If "ON"
XX-Pointer ' "Sup dawg I got amber oh snap!"
9D-Give Item
82-Old Amber
01-Give 1

' If "ON"

XX-Pointer ' "Sup Dawg I like amber"

As you will see, that one is longer, but not completely ridiculous. It is also made of 2 scripts, one which runs if a flag is on, the other runs before it is on. For example, this is a script from SaR. As you will see from the joking shorthand of the text I used when writing this down, he runs one script the first time you talk to him (Giving you the Old Amber) and the other, shorter script (identical to the first one I showed) after you have already been given the Old Amber.

Basically, you can get by with simple scripts to start off with, but there are a few simple things you can remember:

If you load the font (47), you have to reload the sprites (49) before you end the event or make a person move

If you want an event to do something different at different times, you must use a flag (called BitNo.s in the compendium, these are identical to "switches" in RPGMaker vocabulary)

All scripts and text must be in the same bank, unless you use a special code to load from another bank.

If you want to show a Pokémon picture (55), you have to do a screen refresh (48) beforehand (Don't ask me why, I just found this out the hard way)

All scripts will pretty much end with Return Code 2 (90). ' Scripts in the script header will use the other return code. This is just that some things have to be set differently for map loading to continue. Usually it will use a simple priority jump 0x8C to a regular script (ending in 0x90) and after it returns will use a 0x8F. (addition from Tauwasser)

After using an 08 or 09 command for a conditional branch (for example if you chose "yes" go to one script, else run another) then pointer follows the 08 or 09 command and the "Else" code follows immediately after with no need for another pointer.
' Apparently some Nintendo made scripts will follow a conditional branch like this with a x03 followed by a two byte pointer to the next byte, which is the start of the Else script. This is almost never necessary and can be greatly simplified by doing what I said.

I've referenced BitNo.s a few times in here. I do not have a list of what all of them do by default, so I unfortunately cannot tell you "these are free to use for whatever you like". However, I can tell you what I did. Using the partial list in the compendium to know which ones are reset on map changes and whatnot, I just started from scratch with the list in SaR, making a list as I go. This way you don't run into conflicts, and you will probably find this way to be the most economical if you are doing a good overhaul/a lot of scripting anyway. If you find a script that you don't need to redo, but it has a BitNo, it takes all of 5 seconds to replace it with a new one on your list or simply document which one it uses. ' according to Tauwasser, you may still run into conflicts this way, as some things such as Pokerus and items in the room and such will reference BitNos. and can cause problems, so just be careful. If you do experience a conflict, it is still easy to use a new non-conflicting BitNo.

Just remember:
-Don't get discouraged if it seems complicated at first. You will get the hang of it over time.
-Start simple and work your way up to longer, more complicated scripts
-If it doesn't work, read the descriptions and try to see why it doesn't and see what will make it work.
-Don't hesitate to ask questions, but always try it for yourself first. Figuring something out on your own always feels better than having it handed to you.
-Don't forget, you can always look at a Nintendo-made script that does something similar to what you are doing (or even just part of what you are doing) if you get stuck. ' This is how I figured out about having to do the screen refresh before showing a Pokémon picture. Drove me nuts!


Also, here is an example script for a standing Pokemon, such as Mewtwo.

00-Part of cry code
XXXX-Pointer (2-byte) to text for Pokemon
XX-TYpe(See list)
5F-ReloadMap/Return to PC is lost
XX-PersonEvent (Goldmap person number + 1, or Johtomap person number + 2)

If I'm not badly mistaken that should work for a generic standing pokemon like the birds. You will need to give the person event ta BitFlag so it will stay hidden. This tutorial script is not for ones like Ho-oh that need and item, those would be a little different. Here is the list of types of fights:

* 09 for "A wild PKMNNAME appears."; Withdraw possible
* 08 for "PKMNNAME falls from tree."
* 07 for a shiny PKMN
* 06 for win without actual fight
* 05 for fight with possible withdraw
* 04 for "The caught PKMNNAME attacks." (Rod)
* 03 for fight with DUDE’s back pic
* 02 for fight with HIRO’s back pic
* 01 for fight with possible withdraw
* 00 for fight with possible withdraw

Information taken from the compendium's examples and from memory of how I've done it in the past.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

My Hacks:

Skeetendo Thread

Skeetendo Thread - Celadon Mansion Thread - PC Thread


Posts : 89
Join date : 2013-02-07
Age : 28
Location : Celadon City, Kanto

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum