Main script (GTA2)
Main Page > GTA2 > Modding Tutorial > Main script
Every GTA2 level needs its own script to play it. These scripts are stored as *.scr files in the GTA2/data folder.
Contents
LEVELSTART and LEVELEND
Before you can start making a script for your new level, you first should understand how they work. GTA2 scripts are divided in two parts: the "declaration" part and the "programming" part. These parts are separated from eachother with the command LEVELSTART: everything before this command is the declaration part, and everything after it is the program part. Because there is a LEVELSTART, there should also be a LEVELEND. This command goes at the very end of the script.
So the basis of every script looks like this:
LEVELSTART LEVELEND
PLAYER_PED
This script is still useless, because we don't have a character to control in the game. So the next thing we have to script is a playerped. This is done with this command:
PLAYER_PED name = ( X.x , Y.y , Z.z ) remap rotation
Name: | The script name of the playerped. Everything you create in the script needs a unique name, so you can refer to it later. Make sure you give everything a recognisable name, so you can easily find them when your map starts to get bigger. | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
( X.x , Y.y , Z.z ): | The coordinates on which the playerped spawns at the start of the game. The coordinates can be found by selecting a block in the map editor and view the coordinates at the bottom right corner of the editor. Keep in mind that the coordinates of the inside of a block are shown. So, when you click on a tile on the ground, the block below ground level will be selected. Using these coordinates will mean your playerped will spawn below ground! The X and Y coordinates also have a deviation of 0.5. If you want your playerped on 165, 98, 2, your coordinates will be ( 165,5 , 98,5 , 2,0 ). | ||||||||||||||||||||||||||
Remap: | The remap is the appearance of the playerped. Every remap has a number, which are listed below. |
| |||||||||||||||||||||||||
Rotation: | Which direction the playerped should face, in degrees from 0 to 359. 0 is South (See the compass at the right). |
This is a declaration command and thus goes before LEVELSTART. It should be one of the very first codes in your script.
Example
If you want to create a standard playerped at the coordinates 126,5 , 112,5 , 2, facing west, the command will look like this:
PLAYER_PED playera = ( 126.5 , 112.5 , 2.0 ) 25 270
When placed in the script, it will look like this:
PLAYER_PED playera = ( 126.5 , 112.5 , 2.0 ) 25 270 LEVELSTART LEVELEND
"Declare" and "set"
The PLAYER_PED command is a so-called "declare & set"-command, which means it creates and places the playerped at the same time at the start of the game. However, you may want to create something midgame in stead of at the start. To do this, you have to use separate "declare" and "set" commands.
This isn't possible with the PLAYER_PED command (because you cannot create more players midgame), so in this tutorial we use the CHAR_DATA command, which is used to create characters (more about this in Creating Characters).
Declare & set
A standard declare & set command may look like this:
CHAR_DATA peda = ( 126.5 , 112.5 , 2.0 ) 21 270 DUMMY
This command is used to create a pedestrian at the start of the game. The command goes before LEVELSTART.
Set
If you want to create the pedestrian midgame, for example, during a mission, you have to use this command:
peda = CREATE_CHAR ( 126.5 , 112.5 , 2.0 ) 21 270 DUMMY END
This "set" command should be placed where you want the script to create the pedestrian, in an IF, for example. This can be after LEVELSTART!
Declare
If you use a set command, you'll also need to "declare" the pedestrian with a "declare" command. This tells the script to reserve "space" for a pedestrian that will be created later. A declare command looks like this:
CHAR_DATA peda
As you see, it's a very short command. The only thing you have to add is the name (in this case "peda"), which has to match the name in the set command. Declare commands have to be before LEVELSTART.
Adding notes to the script
Your script may be very basic at the moment, but when it gets larger and more complex you may want to add notes to keep track of the many lines of code. To prevent the compiler from seeing your notes (which will cause it to crash), you'll need to use /*, */ and //.
Everything on a line after // will be ignored by the compiler. Text on a new line (after an enter) will be compiled again. This method is very useful to add simple notes after a command.
Everything between /* and */ will also be ignored, but this includes new lines. This method can be used to add multiple lines or to (temporarily) disable large pieces of code.
Examples
PLAYER_PED playera = ( 126.5 , 112.5 , 2.0 ) 25 270 //start point of player a //PLAYER_PED playera = ( 147.5 , 88.5 , 3.0 ) 25 180 //possible alternative for start point LEVELSTART /*A lot of code will be added here later on For now, it's still empty.*/ LEVELEND
Remaps
0 | Cop |
---|---|
1 | Green SWAT cop |
2 | Red SWAT cop |
3 | Yellow SWAT cop |
4 | Soldier |
5 | Redneck #1 |
6 | Redneck #2 |
7 | SRS Scientist |
8 | Zaibatsu member |
9 | Hare Krishna member |
10 | Russian |
11 | Loonie |
12 | Elvis |
13 | Yakuza |
14 | Fire fighter |
15 | Car jacker |
16 | Medic |
17 | Pickpocket |
18 | Blue pedestrian |
19 | Light blue pedestrian |
20 | Red pedestrian |
21 | Pedestrian |
22 | Prisoner |
23 | Poisened pedestrian |
24 | Poisened pedestrian |
25 | Claude Speed (default playerped) |
26 | Naked pedestrian |
27 t/m 52 | Other normal pedestrians |
Mapping | Map Editor · Buildings · Roads · Water & animations · Slopes · Flat tiles · Collision info · Level edge · Zones · Putting a level ingame | |
---|---|---|
Scripting | Declarering: | Main script · Script Compiler · Code lists · Commands · Vehicles · Objects · Sounds · Characters |
Programming: | IF · WHILE · COUNTERs · Subroutines · THREAD TRIGGERs · Kill Frenzies | |
Both | Manual · Lighting · Car shops · Cranes & crushers · Gangs · Subway · Multiplayer levels | |
File types | .gci · .gmp · .gxt · .mis · .mmp · .scr · .seq · .tmp · .sty | |
Other | Texting · Physics · Creating vehicles · Terminology · Installing levels |