Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 1970-01-01 00:33:30

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 9/3,578

Intro to Scripting

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  :P 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:

6A-FacePlayer
47-LoadFont
4C-LoadText
XX-Pointer
XX-Pointer
53-CloseTextbox
49-ReloadSprites
90-End

Or occasionally something a little longer

6A-Faceplayer
31-BitTableCheck
XX-BitNo.
XX-BitNo.
09-If "ON"
XX-Pointer
XX-Pointer
47-LoadFont
4C-LoadText
XX-Pointer ' "Sup dawg I got amber oh snap!"
XX-Pointer
54-KeepTextboxOpen
9D-Give Item
82-Old Amber
01-Give 1
53-CloseTextBox
49-UnloadFont
33-BitTableSet
XX-BitNo.
XX-BitNo.
6D-HidePerson
XX-Person2
90-ReturnCode2

' If "ON"

6A-FacePlayer
47-LoadFont
4C-LoadText
XX-Pointer ' "Sup Dawg I like amber"
XX-Pointer
53-CloseTextbox
49-ReloadSprites
90-End


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!

Offline

#2 1970-01-01 00:33:30

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 18/3,578

Re: Intro to Scripting

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

83-PlayPokemonCry
XX-PokemonNumber
00-Part of cry code
47-LoadFont
4C-LoadText
XXXX-Pointer (2-byte) to text for Pokemon
53-CloseTextbox
49-UnloadFont
67-SetLastPersonTalkedTo
FF-None
1E-SetTypeOfFight
03-SetTypeOfFight
XX-TYpe(See list)
5C-LoadPokemonData
XX-Pokemon
YY-Level
5E-StartBattle
5F-ReloadMap/Return to PC is lost
6D-HidePerson
XX-PersonEvent (Goldmap person number + 1, or Johtomap person number + 2)
90-EndOfScript


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.

Last edited by Mateo (2012-10-10 23:54:28)

Offline

#3 1970-01-01 00:33:30

Miksy91
Member
Registered: 2010-10-16
Post 116/2,339

Re: Intro to Scripting

"Go to the event data, and find blank space in the same bank"

I don't get what you're trying to say here.
I thought it would have been like this;
I checked the Event Data for Azalea Town (outside map) with GoldMap and it showed that the Event Data begins at 1217e0.

Here is a picture of that part of the rom (but there is no black space anywhere)

azalea.jpg

Offline

#4 1970-01-01 00:33:30

33/703

Re: Intro to Scripting

The blank space will not be near the event data, only near the end of the same bank. In this case your best bet is 0x1225A0.

#5 1970-01-01 00:33:30

Miksy91
Member
Registered: 2010-10-16
Post 117/2,339

Re: Intro to Scripting

Thanks, that really helped.

EDIT:
So, do I have to start making the new script at 1225A0 (the other script data happens to end just at 12259f) ?

EDIT #2:
Yay  :D
I feel like I'm actually learning something, just found out that the script for Ho-Oh starts at 0x16e918.

Offline

#6 1970-01-01 00:33:30

Tauwasser
Member
Registered: 2010-10-16
Post 32/452

Re: Intro to Scripting

All scripts will pretty much end with Return Code 2 (90). Apparently there are some exceptions, I've never run into them.

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.


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 [...].

Actually, you will run into conflicts that way. IIRC, many in-built scripts use bit numbers of their own. For instance, the Pokémon Centers use one to select dialogues for PokéRUS and so on.
And the computer will check some predefined ones to check for items to put in the room. I think all of them were pretty low range, like 0x200–0x300ish.

cYa,

Tauwasser

Offline

#7 1970-01-01 00:33:30

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 271/3,578

Re: Intro to Scripting


(all of that)

Ah, thanks for explaining that better. While I haven't noticed any problems yet in SaR with where I started listing BitNos. I will keep my eyes peeled for any conflicts that may show up because of that, and will update the main post to reflect your input.

Offline

#8 1970-01-01 00:33:30

ayato
Member
Registered: 2010-10-16
Post 3/14

Re: Intro to Scripting

* 08 for "PKMNNAME falls from tree."
* 03 for fight with DUDE’s back pic
XX-BitNo.
XX-BitNo.

You can put both the Dude backpic and fell out of a tree after an event rite? and where do you find the XX? I just want to edit a script but I don't know where the mom script is at, I sort of want the character to check the phone and the PG to have a gastly photo on it, then mom comes then drags you to a cave, like going outside then going there, and soom you have another script with your first pokemon and catch it,

sorry for the thing I said it sound a little hard to understand, I can understand your intro it's really helping me  :o

Offline

#9 1970-01-01 00:33:30

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 307/3,578

Re: Intro to Scripting

nonono the type of fight is what that list is for, and is only one byte. The bitno. is 2 bytes long and is the flag set by the event.

Offline

#10 1970-01-01 00:33:30

Miksy91
Member
Registered: 2010-10-16
Post 155/2,339

Re: Intro to Scripting

I didn't understand well but you're at least trying to make a complicated script.
Learn how simple build-in scripts work first before creating something like that.

EDIT
If I have finally learned something, I'd say that's not a script; you've to do Engine Hacking to achieve what you're trying to achieve - I can't do it either and don't think many can.

Offline

#11 1970-01-01 00:33:30

ayato
Member
Registered: 2010-10-16
Post 10/14

Re: Intro to Scripting

I get it but how do you open up the one you wnat, is there a hex I have to click

Offline

#12 2010-12-24 20:11:17

EvilOttoJr
Member
Registered: 2010-12-05
Post 25/86

Re: Intro to Scripting

As to the standing Pokemon script, what is a BitFlag? What do I set XXXX to?

Offline

#13 2010-12-25 11:30:15

Miksy91
Member
Registered: 2010-10-16
Post 217/2,339

Re: Intro to Scripting

EvilOttoJr wrote:

As to the standing Pokemon script, what is a BitFlag? What do I set XXXX to?

Use a random flag (XXYY) for the event and in the end of the script of that event,
make the pokemon disappear (6DZZ) and use BitTable1 reset command (32XXYY) for the used flag.

Offline

#14 2010-12-26 20:17:54

EvilOttoJr
Member
Registered: 2010-12-05
Post 29/86

Re: Intro to Scripting

Okay, so I guess what I'm actually not understanding is, what is a flag? (in layman's terms, please :) )

Offline

#15 2010-12-26 20:36:20

Miksy91
Member
Registered: 2010-10-16
Post 220/2,339

Re: Intro to Scripting

I think I can explain "in layman's terms" (although I don't even know what that means :D) because I can't really how explain it the "way it should".

You can use flags to activate or deactivate people appearing on the map.
With BitTable1 reset command, you can deactivate the flag and with BitTable1 Set command, you can activate the flag again.
(For example in Hiro's House (Downstairs), the game is told to deactivate the flag of the mom you meet first time and activate three other moms (which you can only see one per time))

If you reseted a flag of a person, that person would still be in the map but after exiting the map and entering to it again, the person wouldn't be there. To immediately remove the person from the map after reseting the flag, make the person disappear by using command 6D [xx].

*You can also use BitTable1 commands (together with RAM Check (08 + 09)) to move on to different offsets inside a script.
For example, 31 20 20 (BitTable1 check) 08 50 60 (RAM check).

In this script, the game checks if 0x2020 is set (in BitTable1), and if it's not set, the script continues in the same bank at offset 0xY2050 (Y=Bank). If 0x2020 is set, the script continues after the 08 50 60 command.

31 command
Gives feedback after checking the bit (writes either 00 or 01 to RAM).
00 = Value 0 (OFF / Bit wasn't set), 01 = Value 1 (ON / Bit was set)

08 command
When [RAM] = 00, go to the new offset through the pointer (50 60).


*You can easily get this if you first mess around with PKSV a little bit (instead of using RAM check commands, you can just write "if true" or "if false").

This script would be:
checkbit1 0x2020
if false 0x6050

Last edited by Miksy91 (2010-12-26 20:46:22)

Offline

#16 2011-01-03 07:49:13

EvilOttoJr
Member
Registered: 2010-12-05
Post 44/86

Re: Intro to Scripting

I'm not understanding what to do to make the Pokemon permanently disappear after you fight them. It was mentioned but I'm not understanding it.

Also, I need a list of like 6 unused BitFlags. I'm using 078c-0791 but I'm not 100% sure those are clear.

Offline

#17 2011-01-03 08:57:57

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 402/3,578

Re: Intro to Scripting

To make a pokemon disappear permanently, you have it set a bit flag and hide it's event at the end of the script, and in his event data you put the flag that you set there as well. That way once you battle it, it will hide his event and then he will stay hidden because the event data tells him to be because that flag is set.

Offline

#18 2011-01-03 11:18:38

EvilOttoJr
Member
Registered: 2010-12-05
Post 46/86

Re: Intro to Scripting

So I need the BitFlag listed twice? I have it listed in the script, where else does it need to go? I'm lost...

Here's an example of the script I'm using (pretty much the same as your Pokemon script just without the text):

83-PlayPokemonCry
96-Mewtwo
00-Part of cry code
67-SetLastPersonTalkedTo
FF-None
1E-SetTypeOfFight
03-SetTypeOfFight
07-ShinyBattle
5C-LoadPokemonData
96-Mewtwo
46-Level 70
5E-StartBattle
5F-ReloadMap/Return to PC is lost
33-BitTable1Set
07 8C-The BitFlag I'm using
6D-HidePerson
02-PersonEvent (Goldmap person number + 1)
90-EndOfScript

Offline

#19 2011-01-03 17:14:54

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 403/3,578

Re: Intro to Scripting

Ok, it only goes in his script once, like you have it. The second time you do in the map editor. When you click on his person event in Megamap or Johtomap (but not Goldmap as once again it doesnt load this right) you put the flag that you set in his event data, so that the map knows to hide him if that flag is on. I've attached screenshots of both Megamap and Johtomap so you can see where I am talking about.

Megamap

Johtomap

The reason Goldmap doesnt work right with this (it will also mess up people events sometimes because of this) is because it only lets you edit 1 byte of the BitFlag, and either ignores the first one completely.

Offline

#20 2011-01-03 17:38:13

EvilOttoJr
Member
Registered: 2010-12-05
Post 47/86

Re: Intro to Scripting

Oh, okay, so THAT's what those do. I should've guessed that, but guessing while editing a rom is a bad idea in my experience.

I've got another, semi-related problem. I edited the map (made it sort-of maze-like) but now my warps don't work. All the numbers match up, so theoretically there should be no issue. I messed something up editing my map. What did I mess up and how do I fix my warps?

EDIT: My BitFlag is 07 8C. In JohtoMap, which byte goes to Index and which goes to Bit?

Last edited by EvilOttoJr (2011-01-03 17:39:59)

Offline

#21 2011-01-03 18:22:07

Tauwasser
Member
Registered: 2010-10-16
Post 65/452

Re: Intro to Scripting

EvilOttoJr wrote:

EDIT: My BitFlag is 07 8C. In JohtoMap, which byte goes to Index and which goes to Bit?

Just try it out and then check the order in the rom.

cYa,

Tauwasser

Offline

#22 2011-01-03 19:29:21

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 404/3,578

Re: Intro to Scripting

Also on the warps thing, when you say the don't work, do you mean they are taking you to the wrong maps, or are they just not doing anything? If they aren't doing anything, make sure they are placed on warp-enabled tiles, such as doors, carpets, stairs, warp pads, etc.

Offline

#23 2011-01-03 19:35:32

EvilOttoJr
Member
Registered: 2010-12-05
Post 48/86

Re: Intro to Scripting

They're not doing anything, and I've checked back with the base rom - they are using the correct tiles (doors) in the correct way. I'll try some ladders, see if that helps.

EDIT: The ladders worked.

EDIT 2: BitFlag Byte 2 is Rag Index, Byte 1 is Rag Bit.

Thanks for all your help everyone!

Last edited by EvilOttoJr (2011-01-03 19:43:40)

Offline

#24 2011-01-03 19:56:12

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 405/3,578

Re: Intro to Scripting

Glad you got it working mate.

Offline

#25 2011-01-03 19:59:38

EvilOttoJr
Member
Registered: 2010-12-05
Post 50/86

Re: Intro to Scripting

Thanks! Also, check the Christmas Hack thread, I'm having an issue with the birds that's relevant to a glitch in the Christmas hack that might be of interest to you.

Offline

Board footer

Powered by FluxBB