Trains in GTA 2 Mission Scripts

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.

Working Example

There is a sample map created by Pyro to go with this tutorial:

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.

Zones for Trains and Stations

Now, don’t forget to add the zones to it as well. These turn your railway buildings into functioning railway stations, so trains will stop there and people will wait on the platform.

It is highly recommended to use these zone names, exactly as they appear below, same as the original game uses. This setup has worked perfectly for me on my own levels and while helping other people. Tanks In Miami and Cerbera’s MultiSlayer City are good examples.

Zones for a Railway System with 2 Stations
Zone Name Zone Type Description
Railway 1 Station 1 trak00 Platform Pedestrians wait in this Pavement area.
trak00en Entry Point Train slows down before entering the station.
trak00st Stop Point Train engine stops at this point.
trak00ex Exit Point Train speeds up while leaving the station.
Station 2 trak01 Platform Pedestrians wait in this Pavement area.
trak01en Entry Point Train slows down before entering the station.
trak01st Stop Point Train engine stops at this point.
trak01ex Exit Point Train speeds up while leaving the station.
Zones for 2 Railway Systems, each with 2 Stations
Zone Name Zone Type Description
Railway 1 Station 1 trak00 Platform Pedestrians wait in this Pavement area.
trak00en Entry Point Train slows down before entering the station.
trak00st Stop Point Train engine stops at this point.
trak00ex Exit Point Train speeds up while leaving the station.
Station 2 trak01 Platform Pedestrians wait in this Pavement area.
trak01en Entry Point Train slows down before entering the station.
trak01st Stop Point Train engine stops at this point.
trak01ex Exit Point Train speeds up while leaving the station.
Railway 2 Station 1 trak10 Platform Pedestrians wait in this Pavement area.
trak10en Entry Point Train slows down before entering the station.
trak10st Stop Point Train engine stops at this point.
trak00ex Exit Point Train speeds up while leaving the station.
Station 2 trak11 Platform Pedestrians wait in this Pavement area.
trak11en Entry Point Train slows down before entering the station.
trak11st Stop Point Train engine stops at this point.
trak11ex Exit Point Train speeds up while leaving the station.

For an extreme working example, see TM’s 10 Trains Getaway level!

Explanation of Zone Names

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

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.

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.

Putting Trains on the Track

These are always created at a railway station, using the Platform zone type.

Add this to your script file, somewhere near the top:

SET_STATION_INFO (platform_name, passenger_carriages, freight_carriages, boxcar_carriages)

So, your example could look like:

SET_STATION_INFO (trak00, 2, 1, 1)

Train Length

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)

Delayed Trains

Trains tend to get delayed if you create one at every station. They are very careful to avoid following closely behind each other. Simply using NO_TRAIN is the simplest way to cure the big delay at a one station:

SET_STATION_INFO (platform_name, NO_TRAIN)

So you could have one like:

SET_STATION_INFO (trak01, NO_TRAIN)

However, journey times can be fine-tuned. Moving your Entry Point and Exit Point zones will let you make a short distance between stations take longer, balancing it with a longer distance between the other stations. This can get the delays down to only 1 or 2 seconds.

However, big delays can only be solved by big changes to the platform locations, the train route or using NO_TRAIN to simply run fewer trains.

Slow Trains

Especially suited to freight trains, simple changes to the location of the entry and exit zones make the train run at lower speed. Here are the speeds a train can travel at between stations, in their normal sequence:

Speed Description Situation
0.000 Stopped at station. At the Stop Point.
0.200 Departing from station. Between Stop Point and Exit Point.
0.400 On way to next station. Between Exit Point and Entry Point.
0.075 Arriving at next station. Between Entry Point and Stop Point.

Very Slow (0.075) Setup

Move the Exit Point a long way from the Stop Point. The train leaves the station and continues at the very slow speed until it reaches the distant Exit Point.

Slow (0.200) Setup

Move the Entry Point a long way before the next Stop Point. The train will slow down at the Entry Point and remain at that slow speed until it reaches the next platform.

Avoiding High Speed (0.400) Setup

By putting the Stop Point directly after the previous Exit Point, the train will only run at 0.400 for a moment.

However, this makes the train system much slower than driving around in conventional levels.

Underground/Overground Hybrid Setup

When platforms are far apart, you can run the train at high speed underground and run it at lower speeds when above ground.

Move the Exit Point away from the Stop Point, just before the train enters the tunnel. Move the next Entry Point back from the next station, just after the tunnel ends.

You can now watch trains for much longer when they are above ground, which is nice. Also, the journey times between stations are still fairly short thanks to the fast underground sections. That’s also nice!

Working Examples

By using the maximum train carriage length of nine you can make really large freight trains for your map. Check out the Jailbreak map to see a normal train alongside a freight train setup.

The converted GTA1 levels show hybrid underground/overground systems in Liberty City and Vice City. San Andreas features a tram, which runs at low speed on flat ground and goes quickly up and down the slopes. (This reduces journey times and somewhat hides the glitch that trains are invisible on slopes.)

Destroying a Train

If you destroy a train carriage, 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!

Sadly, trains do not respawn automatically. There is also no way to remove the wreckage and place a new train on the tracks. Restarting single-player level (or resuming a saved game) is the only way to restore the train. In multiplayer, you’ll have to restart the level.

(Originally written by Chris “Pyro” Hockley and formatted by Ben “Cerbera” Millard with full permission.)