Thread: [Tutorial] Creating Level Scripts
View Single Post
Old August 19th, 2009 (9:56 AM). Edited April 15th, 2010 by Logan.
cooley's Avatar
cooley cooley is offline
///Keepin' it simple
  • Silver Tier
Join Date: Feb 2007
Location: United States
Age: 23
Gender: Male
Nature: Impish
Posts: 1,150
How to create a Level Script
Yes, another tutorial, due to the large amount of level script questions

Note: Before reading, please learn some scripting first.

You all may think that making a level script is really hard, and categorize it in the same field as ASM hacking. Well, it isn’t hard, at all.

This is what a level script looks like:

#dynamic 0x800000

#org @start
 msgbox @string 0x6
 setvar 0x4033 0x1

 #org @string 0x6
 = You see?\nThe level script worked!

The most important part is the "setvar 0x4033 0x1". Without this in this 'type' of level script, then you will get a repeating level script.

Well, that's the tutorial... "I'll add more Later" xD
Nah, only joking :P

Okay, the first thing you would do is head on over to the Header Tab, in A-map. I'm pretty sure, everyone knows where that is.

If you look down a little, you will see this:

Click on add, and then click on "script type". You should see a drop-down menu like this:

All of these are different types of Level scripts. The one you most likely want is the one that is highlighted.

"01 'setmaptile' script" is not the official name, but it's used in the Pokemart in Viridian City. It's purpose is in it's name; which is to setmaptile(s) before the map loads. It's not as fast as:

"04 Validates valus, loads handler to 0x03000F28" which is used to make something happen the instant you walk into the entrance/exit of the map. It's used in the PLAYER's Room to make him face up towards the Nintendo. The best time to use this is in houses or places you warp to, not like routes and towns where you walk into.

"03 On entering map/not on menu close" This is a multipurpose one. You can checkflags, compare vars, and other things and use them to make other things happen. There are a lot of these, so there is also a lot to learn from by decompiling Nintendo's scripts.

Last but not least, "02 Validates values, loads handler to 0x03000EB0". The one that most people use to make a level script. This one, you can literally use almost all the commands, like msgbox, applymovement, fadescreen, etc. But the catch is that I haven't found a way to use it like "checkflag 0x828/if 0x1 goto @done" because once you set the var, it's set... But don't worry, I'll find a way.

Okay, once you've clicked on "02 Validates values....." You will see the script offset and script offset 2 boxes are "$000000". Also the Flag and Value boxes should be 0000 too.

Compile your Level script [make sure it has a setvar 0x(variable) 0x(value) in the script though]

According to score_under:
Originally Posted by score_under
It does not have to be subtracted by 1. The reason we use 0x0 in the Value box is because the var starts at 0. The Value box dictates which value the var has to be to start the script. After the script, you set it to 1 (or indeed any other value if you choose to), and this means it no longer equals zero, so no longer activates.

Click Save map scripts and the Script offset box contents should change.

Save from the File menu(Ctrl+S) and play your ROM.

Wow, the level script really worked!!!

Advance Map overwrites the 0000 that you put into the Value box, with FFFF. And since it's subtracted by 1, and FFFF is the highest number you can insert, the level script glitches up.

To fix this, you go to the header tab, and press Ctrl+H to get professional header view. You should see an area called "Map Options". And within it you should see "Map script offset"

Copy the map script offset, and open your ROM in XSE.
Once done, paste the offset in the "decompile box" and click on "level script"

(This is the old XSE, but they both function similarly.)

After you've pasted the offset, and toggle the level script decompile feature (last button to the right) click decompile or "Shift+Ctrl+D"


  #org 0x71A242
 #raw word 0x0
 #raw word 0x0
 #raw pointer 0x880007D
 #raw word 0xFFFF

  #org 0x71A242
 #raw word 0x0
 #raw word 0x0
 #raw pointer 0x880007D
 #raw word 0x0

This is the important part. The 0xFFFF needs to be 0x0 so change it to 0x0 and compile. You should see the compiler log:

Now your Level script should work, no problems at all...
That was easy, right Staples?

Make a level script inactive until a certain event happens

Okay, so you've had fun with Level scripts, and you're both good friends. But... You walk into a map, and need a level script to activate, but not the first or second time you enter the map, but the 5th time!

Video Demonstration:

For this to work, you will need the cooperation of two maps. For my example I used the Player's room [PALLET TOWN (4.0)] and PALLET TOWN (3.0) map.

In the Player's room the level script is Level script type 03 "On entering map/not on menu close":
#org 0x800000
setvar 0x4010 0x1

I set the var to 0x1 so that the level script in Pallet town is deactivated. Hope you understood that.

This should clear things up. Here is the level script in Pallet Town:
#org 0x800007
setweather 0x4
applymovement MOVE_PLAYER 0x8800052
waitmovement 0xFF
sound 0x15
pause 0x32
msgbox 0x880002B MSG_NORMAL '"Oh, boy[.]\pJust my luck, it's rai..."
setvar 0x4010 0x1

' Strings
#org 0x80002B
= Oh, boy[.]\pJust my luck, it's raining!

' Movements
#org 0x800052
#raw 0x62 'Exclamation Mark (!)
#raw 0xFE 'End of Movements

Pretty simple huh? Basically, the level script won't activate, because the variable has been set already.

Since you enter Your Room before exited your house into Pallet town, the level script in Pallet town wont work. [/DUMBEDDOWN]

You should be outside of your house. I assigned the Daisy(Gary's sister) in Pallet town this script, as seen in the video:

#org 0x800054
msgbox 0x8800064 MSG_NORMAL '"Setting Variable 0x4010 back to 0x..."
setvar 0x4010 0x0

' Strings
#org 0x800064
= Setting Variable 0x4010 back to 0x0\n\c\h08ó. \c\h08ó. \c\h08ó.Done!

Don't mind the
"\c\h08ó" . That's just how I make my msgs. It doesn't affect the outcome at all, just added for special effects :P

And once you talk to DAISY, walk out her house, and it should start raining, just like in the Video :)

I guess that's that...
Anything else you need to know, ask here, I'll see if I can answer!
Thanks for reading!

Reply With Quote