Trains in GTA 2 Coding
I've been told I’m probably the only person who ever had working trains in my maps, but I had so many questions about “How do I get trains to work in my new maps?” The answer is actually quite simple. Just make sure you have the following on your map.
Landscape Setup
Train tracks which are set to field and have a green direction arrow. To make it go up/down hills, you have to have one block with a track tile on it, set to the 1 block slope setting. Obviously, cover it up with a roof or something. Now, corners are what is probably making the game crash. My advice is that you should leave at least one block clear around the corner, and cover it up too. Now, don’t forget to add the zones to it as well. Use the following guide as an example of what to do and name it:
| Zone Type | Zone Name |
|---|---|
| Platform | trak00
|
| Entry Point | trak00en
|
| Exit Point | trak00ex
|
| Stop Point | trak00st
|
Note: It is highly recommended to use these as the zone names as well and use the same two-letter endings. It has worked perfectly for me on my own levels and while helping other people. Tanks In Miami and Cerbera’s MultiSlayer are good examples.
The platform is where the peds stand and should be placed next to the track. Do not place it on the track, it must be on the pavement blocks to one side.
Placement of the Zones
For hassle-free train setup in the map editor, I would recommend the following placement of the zone types (depends on your map and surrounding objects/buildings etc):
Platform
Placed right next to the track (see above note) and on "Pavement" tiles. I usually have the platform approximately four or six tiles long but only one wide, depending on size of the station. I normally centered it so I might have one or two blocks free either side. This is based on your station facing east/west, but GTA 2 allows you to have platforms on east/west as well as north/south, thus proving more flexible than its GTA1 counterpart!
Stop Point
This is where the front of the train will stop. I normally set it three or four tiles ahead of the platform, but this varies greatly on how many carriages you have and your map layout.
Entry Point
Where the train slows down before the platform (but not stops). I place this about ten blocks before the platform so that if a player is on a train, he knows he’s nearing a station and will get ready. The speed of the train is approximately halved after crossing this zone.
Exit Point
Where the train, after leaving the platform (still travelling slowly), will go back to full speed. I place this about the same distance as the entry point (about ten blocks) but its upto you how quickly it resumes speed.
Code Setup
Add this in your script file:
SET_STATION_INFO ( platform name , number passenger , number freight , number boxcar )
So, your example could look like:
SET_STATION_INFO ( trak00 , 2 , 1 , 1 )
GTA 2 supports upto a maximum of nine carriages for each train and any combination could be used. You could have nine passenger carriages. Or maybe two passenger carriages, five freight carriages and two boxcar carriages like this:
SET_STATION_INFO (trak00 , 2 , 5 , 2 )
Finally, if you don’t want a train to appear on that platform, just follow this example:
SET_STATION_INFO ( platform name , NO_TRAIN )
So you could have one like:
SET_STATION_INFO ( trak01 , NO_TRAIN )
If you destroy a train, all sections of it will be destroyed. If you had another trains running, they would either stop (before they left a station) or if you timed it right, it would run straight into the back of the destroyed one, and it would also be destroyed! There is no way to remove the wreckage and place a new train on the tracks other than by restarting the map.
Working Example
There is a sample map created by Pyro to go with this tutorial:
- Pyro’s Train Example - 24kB winRAR archive.
(Originally written by Chris “Pyro” Hockley and formatted by Ben “Cerbera” Millard with full permission.)