You've not said which Trainz version you're using, but if using TRS2006 SP1 or higher, have a look at TPR's
SCS2006 (
Scenario Creation System) <kuid:[FONT=Verdana, Arial]
41009:1046>[/FONT], which provides an in-session rule that has a whole programming language worth of functionality for constructing scenarios. The rule and it's dependents all available on the DLS.