Train Simulator Classic 2024

Train Simulator Classic 2024

Not enough ratings
Mission scripting reference.
By Kyrah Abattoir
This is a work in progress documentation of how to interact with the game through scripts. Feel free to contribute/correct me in comments.
   
Award
Favorite
Favorited
Unfavorite
Getting scripts to run on your mission.
In your mission folder, create a text file called ScenarioScript.lua

It has to be complied before the mission will recognise it, you can do that from the timetable editor's script section.
The events
OnEvent
Everytime you call for an event through your scenario it will execute this function and return the event name in "event".
This is your main way of getting your script called.
function OnEvent( event ) { }
Taking actions with SysCall()
SysCall is your main way of affecting your mission, but it's syntax is fairly difficult to figure out without documentations, the basic structure is the following:
SysCall("call name", argument1, argument2, ..., argmentN)
ScenarioManager
ScenarioManager allow you to control many aspects if the scenario itself:

TriggerDeferredEvent
Allow you to call an event at a later time
SysCall("ScenarioManager:TriggerDeferredEvent", event, time);

LockControls
Lock the player's controls.
SysCall ( "ScenarioManager:LockControls");

UnlockControls
Unlock the player's controls.
SysCall ( "ScenarioManager:UnlockControls");

TriggerScenarioFailure
Cause the scenario to end as a failure, showing a popup window with the reason.
SysCall("ScenarioManager:TriggerScenarioFailure", reason);

TriggerScenarioFailure
Cause the scenario to end as a success, showing a popup window with the reason.
SysCall("ScenarioManager:TriggerScenarioComplete", reason);

ShowMessage
Allow you to show a simple message window.
SysCall ( "ScenarioManager:ShowMessage", message );

ShowInfoMessageExt
Allow you to show message windows formatted in HTML, the html files must be placed in a language coded folder subfolder, ex: "En" for english.
SysCall ( "ScenarioManager:ShowInfoMessageExt", UniqueID, HtmlFileName, unknown, message_position, message_size, unknown); --message_size: SMALL = 0 REG = 1 LRG = 2 --message_position(bitfield): TOP = 1 VCENTER = 2 BOTTOM = 4 LEFT = 8 CENTER = 16 RIGHT = 32

PlayVideoMessage
Play a video.
SysCall("ScenarioManager:PlayVideoMessage", VideoName, Mode, bool_pause_game, Controls, 0); --Mode: FULLSCREEN = 0 FRONT_AND_CENTERED = 1 VIDEO_CALL = 2 --Controls(bitfield): PLAY = 1 PAUSE = 2 STOP = 4 SEEK = 8

IsVideoMessagePlaying
Check if the specified video is still playing.
playing = SysCall("ScenarioManager:IsVideoMessagePlaying", VideoName);

IsAtDestination
Check if a service is at a specific destination.
serviceAtDestination = SysCall("ScenarioManager:IsAtDestination", serviceName, stopName);

BeginConditionCheck
Starts a repeating event usually to detect a specific change.
SysCall ( "ScenarioManager:BeginConditionCheck", eventName);

EndConditionCheck
Stop repeating event usually to detect a specific change.
SysCall ( "ScenarioManager:BeginConditionCheck", eventName);

PlayDialogueSound
Play a sound file.
SysCall ( "ScenarioManager:PlayDialogueSound", "audiofile.wav");

GetSeason
Retrieve the season the scenario is currently on.
value = SysCall("ScenarioManager:GetSeason"); --value: spring = 0, summer = 1, autumn = 2, winter = 3

SecondsAfterMidnight= SysCall ("ScenarioManager:GetTimeOfDay")
Get the number of seconds since midnight.
value = SysCall ("ScenarioManager:GetTimeOfDay");
PlayerEngine
This reference the train driven by the player

LockControl
Allow you to lock a specific control on the player engine.
SysCall ( "PlayerEngine:LockControl", controlName, index, bool/locked);

SetControlValue
Set a control to a specific value. (index is usually zero)
SysCall ( "PlayerEngine:SetControlValue", controlName, index, value); --controlName: Reverser, DynamicBrake, TrainBrakeControl

GetControlValue
Get the value of a control. (index is usually zero)
value = SysCall("PlayerEngine:GetControlValue", controllerName, index);

GetSpeed
Get the player engine speed.
value = math.abs( SysCall( "PlayerEngine:GetSpeed" ) );

GetCurrentSpeedLimit
Get tje player's currently effective speed limit.
value = SysCall( "PlayerEngine:GetCurrentSpeedLimit" );

CameraManager
Used to manipulate the camera.
ActivateCamera
Turn on one of the stock camera.
SysCall ( "CameraManager:ActivateCamera", CameraName, Duration ); --possible cam names: "CouplingCamera", "CabCamera", "TrackSideCamera", "FreeCamera", "YardCamera", "HeadOutCamera"

JumpTo
Move the camera to a specific coordinate.
SysCall ( "CameraManager:JumpTo", Latitude, Longitude, Height );

LookAt
Look at an object.
SysCall ( "CameraManager:LookAt", ObjNum/ObjName );
9 Comments
Nicko 4 May, 2021 @ 8:32am 
I know it's an old thread but has anyone tried, recently, to use SetControlValue for an AI train, replacing the PlayerEngine node with another locomotive ID? It seems nothing happens. Are there any clues?
mbenn42 16 Mar, 2016 @ 2:38am 
Thanks for the notes, and to Skifans for the link to the documentation! Has anyone had any luck using the IsAtDestination call? I can't get it to work, and this article seems to the only reference to it anywhere on t'internet :-O

I'm suspicious that the documentation refers to 'destination should be the unique internal name'; I've tried using the name of the track marker, but that doesn't seem to work :-(
Skifans 11 Jun, 2015 @ 11:10am 
Well you have done a very good job. I don't know if its new.
Kyrah Abattoir  [author] 11 Jun, 2015 @ 10:58am 
Oh, is that new? I pretty much had to reverse engineer half of these functions.
Skifans 11 Jun, 2015 @ 4:41am 
The later of these also includes an exelent example if you want to see how to use them before trying to build your own.
Skifans 11 Jun, 2015 @ 4:40am 
Just wanted to say a great guide for those of us who use this scripting in scenarios. I would though like to point out that a full list of comand can be found by going to C:\Program Files (x86)\Steam\SteamApps\common\RailWorks\dev\Docs and looking in the ...EnglineScripts.pdf and ...ScenarioScripts.pdf
smiling man thumbs up 30 May, 2015 @ 4:53am 
I tried that, but my .wav wasn't played. I wish the devs would tell us these things, I wanna do announcements!
Kyrah Abattoir  [author] 30 May, 2015 @ 4:49am 
I'm not sure i think is basically plays the sound file you specified? there is only 1 argument so that seems reasonable.
smiling man thumbs up 29 May, 2015 @ 11:14pm 
So how does the 'PlayDialogueSound' command work?