Scripting to get the time waiting at a platform?

General discussion about Train Simulator, your thoughts, questions, news and views!

Moderator: Moderators

Locked
User avatar
chrisell
Well Established Forum Member
Posts: 533
Joined: Mon May 06, 2002 12:00 am
Location: England, Holland and America
Contact:

Scripting to get the time waiting at a platform?

Post by chrisell »

Anyone know if there's a LUA function to get the duration of a stop in a scenario where the train is waiting at a platform? My door-closing bell is hard-coded to 20 seconds in all my trains but it would be nice if I could query the scenario and find out exactly how long we'll be sitting at a platform.
User avatar
Irishrailguy
Very Active Forum Member
Posts: 1338
Joined: Sun Mar 21, 2010 8:58 pm
Location: Dublin, Ireland

Re: Scripting to get the time waiting at a platform?

Post by Irishrailguy »

Are you looking to get the time at the platform with the doors open? Or just the amount of time remaining stationary at the platform? The latter is probably impossible as there'd be no way to tell whether you've stopped beside a platform or are just stopped at an arbitrary location. The former should be relatively easy though, just invoke a timer in your Update() function to start whenever either of the DoorsOpenClose controls change to the on position, then reset the timer after they close again and you've stored that time somewhere.

Kev
MaikG
Well Established Forum Member
Posts: 545
Joined: Sat Oct 08, 2011 5:04 pm

Re: Scripting to get the time waiting at a platform?

Post by MaikG »

There is no way to request these informations from plattforms or other things. So what is the point of doing this? If you want the bell sounds when the passenger boardings are done, just detach the door animations from the door controllers, lets bell the bell when the door controller jumps to 0 and then animate the doors by script (open and close), like vR does :) Better you control everything from script, also the door bells (SoundBla:SetParameter, "bla", {int}).
User avatar
chrisell
Well Established Forum Member
Posts: 533
Joined: Mon May 06, 2002 12:00 am
Location: England, Holland and America
Contact:

Re: Scripting to get the time waiting at a platform?

Post by chrisell »

MaikG wrote:There is no way to request these informations from plattforms or other things. So what is the point of doing this? If you want the bell sounds when the passenger boardings are done, just detach the door animations from the door controllers, lets bell the bell when the door controller jumps to 0 and then animate the doors by script (open and close), like vR does :) Better you control everything from script, also the door bells (SoundBla:SetParameter, "bla", {int}).
I've tried doing this but it results in the AI trains leaving with the doors still open. Why? The AI trains leave within a second of the controller changing to 0.
So if I trip the bell sound when the controller goes to 0, then wait 5 to 6 seconds, then run the animations. But that means the AI trains sound the bell, then leave the station, and 5 seconds later the doors close.
Did you find a way to stop the AI trains from leaving straight away or do you just live with open doors while the train is moving?
User avatar
AndiS
Very Active Forum Member
Posts: 6207
Joined: Fri Sep 23, 2005 4:43 pm
Location: Jester's cell in ivory tower
Contact:

Re: Scripting to get the time waiting at a platform?

Post by AndiS »

For distinguishing AI from player, there is GetIsPlayer. For AI, you might have some luck using Kevin's idea, starting the closing procedure some 15 seconds after door opening if the fixed duration be 20 seconds.

I must say I have zero experience with AI doors, I only know that AI do the same thing - dashing away at the start of an animation - at switches.

Whoever publishes a working method of slamming down the throttle in unruly AI trains wins the Nobel Prize in Train Simulation.
User avatar
chrisell
Well Established Forum Member
Posts: 533
Joined: Mon May 06, 2002 12:00 am
Location: England, Holland and America
Contact:

Re: Scripting to get the time waiting at a platform?

Post by chrisell »

For the standard waiting time, (20 seconds) it's not a problem. I can run a timer to play the door chime when I want. The problem comes when making timetabled scenarios where you want the player to sit at a platform for a minute (for example). The door chime plays after 15 seconds but then the doors stay open for the full minute. Same for AI trains - if you make them stop at a platform for 40 seconds (for example) the chime sounds after 15 seconds but the doors close at 40 seconds.

A simple Call("Scenariomanager:WaitTime",0) would be awesome if it existed :(
MaikG
Well Established Forum Member
Posts: 545
Joined: Sat Oct 08, 2011 5:04 pm

Re: Scripting to get the time waiting at a platform?

Post by MaikG »

The whole thing is a bit more complex with AI. I have a switch in each wagon script. It switches between player controlled consist and AI controlled, and if AI controlled then there is no delay: bell sounds and doors are closing at same time and a bit faster. The switch self is controlled by the loco (the driven vehicle in most situations). The loco sends a message every 10 sec along the consist and the wagons then switching to player controlled and store this state. If you decouple the switch will release back to AI driven state after 20sec because no loco message comes in anymore. That is the only way to control the two cases of player and AI driven consists in wagons. GetIsPlayer does not work in AI driven consists, and often not in player driven consists. So that is not an option.
User avatar
chrisell
Well Established Forum Member
Posts: 533
Joined: Mon May 06, 2002 12:00 am
Location: England, Holland and America
Contact:

Re: Scripting to get the time waiting at a platform?

Post by chrisell »

MaikG wrote:The whole thing is a bit more complex with AI. I have a switch in each wagon script. It switches between player controlled consist and AI controlled, and if AI controlled then there is no delay: bell sounds and doors are closing at same time and a bit faster. The switch self is controlled by the loco (the driven vehicle in most situations). The loco sends a message every 10 sec along the consist and the wagons then switching to player controlled and store this state. If you decouple the switch will release back to AI driven state after 20sec because no loco message comes in anymore. That is the only way to control the two cases of player and AI driven consists in wagons. GetIsPlayer does not work in AI driven consists, and often not in player driven consists. So that is not an option.
Yeah - I've found GetIsPlayer isn't reliable. I like your solution though - that's neat. I might give that a try. Thanks for the tip :)


FYI this is the train I'm putting the finishing touches on ... :) The sounds for the wheels and flanges have changed during beta test since this video.

This video is hosted by YouTube, a site which is outside of the editorial control of UKTrainSim and as such Parental Control is strongly advised.
To view the video, click on the PLAY button.
If you click anywhere else on this video, you will be taken to a YouTube page, where you may find yourself subjected to content that you feel is offensive.
If you feel THIS video is inappropriate, please report it to a moderator immediately for prompt action.
Anthony061
Established Forum Member
Posts: 319
Joined: Sun Dec 30, 2012 12:21 pm
Location: Cardiff

Re: Scripting to get the time waiting at a platform?

Post by Anthony061 »

Thanks for the reply, I look forward to the Thurbo version :wink: Keep up the good work!
Kindest regards,
Anthony
Locked

Return to “[TS] General Discussion”