With all these many flagstops on our route (and in the GN public timetables), we were wondering if there is a way to replicate this in TS. To make it so that the player won't know by looking at the task list if they'll have to stop at for example Winton, Reiter, or Scenic -- and to make it so that it would be different each time the scenario is run.
I remembered that Wayne Campbell achieved something just like that in his passenger scenarios on the B&O Kingwood Branch route (which is also full of flagstops) and which I thus used as the starting point for my investigation -- and more than that, I learned very much by studying Wayne's work.
And here's how it all works. I'll show the mechanics at work with a simple test scenario that covers all the basics and that should be fairly straightforward to replicate.
1) Prerequisites
- GN Cascadian Route with Everett expansion
- good knowledge of the RW scenario editor
- some basic knowledge of Lua scripting in RW
- not being afraid to hack your scenario files with a text editor
2) Set Up the Scenario
- Create a new Standard Scenario, choose Merritt as the start location and place the scenario marker near the depot.
- Place an engine next to the depot and make it the player train.
- Next to the player train, place a large object of your choice. Double click on it and have a look at its properties on the right-hand panel window. See the empty text input field on the panel? This is where you can name your object for the scenario's script. In this example, name it "MyMagicObject".
- Save your work, exit the scenario editor and return to the main menu.
- Download this file: and open it with a good text editor (ConText, Notepad++, or similar)
- Open your new scenario's ScenarioProperties.xml in a text editor. Scroll to near the end of file, look for the lines: "<NamedEntity>" and its corresponding closing tag </NamedEntity>. In between the two, you'll see your "MyMagicObject" from before.
- Now copy all contents from the xml file you downloaded before and paste them into your ScenarioProperties just before the closing </NamedEntity> tag. Check that you haven't left empty lines, then save the xml file. (Ignore the strange tabulator spacing in the pasted content, RW will take care of that when you next save the scenario).
Script the Scenario
- Now go back into RW and load your scenario in the editor.
- Add a Trigger Instruction ("pop-up message") to your service. Give it a delay of five seconds. Leave the Trigger Message box empty but enter "TheMagicHappens" into the Trigger Event box.
- Set up a new "ScenarioScript.lua" in your scenario's folder.
- Paste the following code into your OnEvent function:
- Code: Select all
function OnEvent(event)
-- Merritt Flagstop Test
if (event == "TheMagicHappens") then
flagstoptest1 = math.random(10)
-- creates a random int between 1 and 10
if flagstoptest1 > 4 then
-- 60% chance for the following
SysCall ( "ScenarioManager:ShowMessage", "Random Success?", "YES! Train Order Board now at Y/Y. Magic Object has disappeared.", 0 )
SysCall( "MyMagicObject:setNearPosition", 0,0,0 )
-- this moves the named object to the center of the tile (so it's hidden)
SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","red1",0 )
-- MerrittTOeb is another named object and part of the list you pasted into your ScenarioProperties
SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","orange1",1 )
SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","green1",0 )
SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","red1",0 )
SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","orange1",1 )
SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","green1",0 )
else
SysCall ( "ScenarioManager:ShowMessage", "Random Success?", "NO! Train Order Board at R/R. Magic Object is still there.", 0 )
SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","red1",1 )
SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","orange1",0 )
SysCall( "MerrittTOeb:1 Head Signal:ActivateNode","green1",0 )
SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","red1",1 )
SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","orange1",0 )
SysCall( "MerrittTOwb:1 Head Signal:ActivateNode","green1",0 )
end
end
end
- Compile your script in the editor (second button from the right in Timetable View), save your scenario and click play.
And you're done! You should now have a functioning scenario with a 60% chance for the train order signal to switch to yellow/yellow and a 40% chance for red/red.
Here's an upload of the scenario I wrote for this test (script included):
-- unpack this into your Cascadian route's Scenarios folder: RailWorks\Content\Routes\a078a51f-90eb-41f3-a8b4-0354f66504d2\Scenarios
And here's the complete list of all the flag stop signals that you can use in this fashion after you've pasted the contents of the attached .xml file into your ScenarioProperties file: .
The ActivateNode command is actually from the signal script but as you can see, it works in the scenario too when called from the SysCall command. Kudos to Wayne for figuring that one out! "1 Head Signal" is the name of the child object in question and is the same for all train order signals on our route. green1/orange1/red1 are the names of the anim states for CLEAR, CAUTION and STOP which you can activate (1) or deactivate (0). You don't actually need to run all three colors, just the ones that need changing (so if train order signal is green by default and you want to switch it to red by script, you'd just have to do ActivateNode for "red1",1 and "green1",0.
Have fun scripting!
None of this would have been possible without the great tutorials on Matt P.'s blog:
http://trainsimlive.blogspot.com/2015/02/
...and the DTG dev docs online collection:
https://sites.google.com/a/railsimdev.c ... C-Overview
Cheers
Michael