Train Simulator Classic

Train Simulator Classic

View Stats:
Train mass
Hi. Does anyone know how to display consist weight as a popup window using lua script? I've tried using manuals and online tutorials but to no avail. I know there is a function called "PlayerEngine:GetConsistTotalMass" but I don't know how to show its results as a message to a driver. I'd be grateful for any help.
< >
Showing 1-15 of 19 comments
Hi ssbn, you need to read out the train mass into a variable for example:
TrainMass = SysCall("PlayerEngine:GetConsistTotalMass")
Then you can show it either as a pop-up message or as an "alert"-message in the top right corner.
A great source for LUA-scripts in TS are the comprehensive and superb workshops created by Rudolf-Jan which you find here:
http://members.uktrainsim.com/filelib-info.php?form_fileid=33231
Workshop-1 explains all what is required to create a scenario, #2 is for advanced creators and #3 shows a lot about LUA-commands. Hope this helps.
Hi Coasty. I am familiar with the fine work of Rudolf Heijink and his "Scenario authors guide" in which he includes a couple of "ready to use" lua templates. Unfortunately, even using those templates I wasn't able to make any progress. I feel like I'm missing something rather obvious. Anyway, thank you for your advice.
Hi ssbn, if you use the example in my previous post, the current train mass is stored in the variable "TrainMass" => to show it, you may have a look at page-42 of Rudolf-Jan's Workshop #3....you just need to customise the text (and variable) for your purposes....then it gets shown in the upper right corner. Hope this helps - otherwise I may not really understand your issue to either read out the train-mass....or to show it?!
Hi ssbn i have also been asking for the weight of the total consist to be displayed, as in real life a freight train driver in the uk has a drivers slip which shows the consist weight and length of the train using standard length units, where one SLU is 21 feet and maximum speed of the train and brake force of the train, including any hazardous goods included in the consist. If you can get the total train weight shown i would be interested as it will make the sim even more realistic.
Hi, theskipper 98! Thanks to Coasty's suggestions and Rudolf's "Scenario authors guide" I've managed to get information about the mass of the consist to show in a message window when the scenario starts. As I suspected I overcomplicated things which resulted in way too many lines of lua code when in fact you only need few. If you'd like I can send you my "ScenarioScipt" file.
Hi ssbn i would be grateful if you could send me a copy of your ScenarioScript file as i have always wanted this to be added to the sim. Thanks and I am pleased to hear that it's working for you.
Hi ssbn, Great to read that it finally works for you. ....you can do the same with the train length by using this line: TrainLength = SysCall("PlayerEngine:GetConsistLength").
Hi ssbn and Coasty i have in my ScenarioScript.lua the following code but the train report and consist length is not shown when starting the sim. Can you please give me some advice on what i am doing wrong thank you.

function GetTrainLength(consist) result= SysCall(consist .. ':GetConsistLength' ) if(result==nil) then result= 0 end return result end
function GetConsistMass(consist) result= SysCall(consist ..':GetConsistTotalMass' ) if(result==nil) then result= 0 end return result end
function GetConsistId(consist) result= SysCall(consist .. ':GetRVNumber') if(result==nil) then result= 0 end return result end
function ReportConsistData(consist) if (consist==nil) then consist="PlayerEngine" end
length= GetTrainLength(consist) mass= GetConsistMass(consist) id= GetConsistId(consist)
if(mass==0 or length==0) then SysCall ( "ScenarioManager:ShowInfoMessageExt", "Train report", "Error, train report not available", 30, MSG_TOP+MSG_LEFT, MSG_SMALL, TRUE); else message= string.format("%s%s%s%d%s%d%s ","Train number= ",id," Consist length= ",length," metres, consist mass = ",mass," tons") SysCall ( "ScenarioManager:ShowInfoMessageExt", "Train report", message, 30, MSG_TOP+MSG_LEFT, MSG_REG, TRUE); end end
Hi theskipper98. My ScenarioScript file looks like that:
-- Message positions
MSG_TOP = 1
MSG_VCENTRE = 2
MSG_BOTTOM = 4
MSG_LEFT = 8
MSG_CENTRE = 16
MSG_RIGHT = 32

-- Message box size
MSG_SMALL = 0
MSG_REG = 1
MSG_LRG = 2

-- Pause
TRUE = 1
FALSE = 0

function OnEvent(event)
if event=="start" then
mass= SysCall ( "PlayerEngine:GetConsistTotalMass" );
SysCall ( "ScenarioManager:ShowInfoMessageExt", "Train Report", mass, 20, 9, 1, TRUE);
end
end
It's simple but it works. As for your question about the code you posted, I had the same issue - after restarting scenario I didn't get any message. For me, it looked like the script was not run. So I added this at the end:
function OnEvent (event)
if event=="start" then
ReportConsistData("consist")
end
end.
This time the message was displayed - "Train report not available" Well, at least it's doing something, I guess...
Hi ssbn thank you so much for helping me with your script, i shall re edit mine with yours and will let you know how i get on.
Hi ssbn i have tried your script and it works perfectly. One of my Canadian freight trains weighed 8000 tons lol. Thanks to you i now know how much tonnage i am hauling:) Thank you.
Isn't the length and weight of a consist displayed in the consist editor window?
Hi Zoronov yes you are correct that the consist weight is shown when creating a consist in the editor window, but with the added script you can see the weight of the consist when running any scenario that you have added the script too when starting the scenario. But don't forget that you need to add a script box in the scenario editor of the player train and write start in the script box which will allow the weight in tons to be shown from the script that was added to the scenarioscript.lua that you add to the scenario folder of the route that you want added.
This is amazing info and will work great with new searchlight sd40s. Thank you.
Here is another reference for train consist message as a whole, length and mass. If event EVENT_1 triggered in scenario, works perfecly. Actually event can be triggered with the same name in a scenario everytime consist changes to see the new values.

-- Message positions
MSG_TOP = 1
MSG_VCENTRE = 2
MSG_BOTTOM = 4
MSG_LEFT = 8
MSG_CENTRE = 16
MSG_RIGHT = 32

-- Message box size
MSG_SMALL = 0
MSG_REG = 1
MSG_LRG = 2

-- Pause
TRUE = 1
FALSE = 0

function OnEvent(event)
if event=="EVENT_1" then
mass= SysCall ( "PlayerEngine:GetConsistTotalMass" );
leng= SysCall ( "PlayerEngine:GetConsistLength" );
length= leng * 3.281
message= string.format("%s%d%s%d%s%d%s ","Consist Length= ",leng," metres, ",length," feet\nConsist Mass = ",mass," tons")
SysCall ( "ScenarioManager:ShowInfoMessageExt", "Train Report", message, 30);
end
end
< >
Showing 1-15 of 19 comments
Per page: 1530 50

Date Posted: Nov 18, 2018 @ 10:36am
Posts: 19