/* This is a small addition to CCjLoco class that will / / allow panto sounds to be played when the Num 1 key / / is pressed or the panto icon on the hud is pressed / / / / This does not work on AI trains / / / / The sound files to be played are pantoup.wav / / and pantodown.wav respectively, located in a folder / / called "sounds" / / / / The soundfiles should be made to match the length / / of the panto animation. */ include "cjscripts.gs" class CCjLocoWithPantoSound isclass CCjLoco { Train myTrain; // this updates on couples and decouples and can be referenced whenever the train is needed Asset selfAsset; // the asset of this train public void Init(void) { inherited(); selfAsset = me.GetAsset(); myTrain = me.GetMyTrain(); me.Sniff(myTrain, "Train", "", true); // This sets the handler for the very first time and initialises myTrain AddHandler(me, "Train", "NotifyPantographs", "PantographHandler"); AddHandler(me, "Vehicle", "Coupled", "SniffUpdateTrain"); AddHandler(me, "Vehicle", "Decoupled", "SniffUpdateTrain"); } void SniffUpdateTrain(Message msg) { // This turns off the old sniff and sets one for the new train if a new train is detected Train oldTrain = myTrain; myTrain = GetMyTrain(); if(oldTrain) { if(oldTrain != myTrain) { me.Sniff(oldTrain, "Train", "", false); me.Sniff(myTrain, "Train", "", true); } } else { me.Sniff(myTrain, "Train", "", true); } } void PantographHandler(Message msg) { // if any train presses panto button if (msg.src == myTrain) { // If its our train if(myTrain.GetPantographState() = 0) { // two goes down World.PlaySound(selfAsset, "sounds/pantodown.wav", 1000.0f, 10.0f, 200.0f, me, "a.pant1"); } else if(myTrain.GetPantographState() = 1) { // one goes up World.PlaySound(selfAsset, "sounds/pantoup.wav", 1000.0f, 10.0f, 200.0f, me, "a.pant0"); } else if(myTrain.GetPantographState() = 2) { // one goes down World.PlaySound(selfAsset, "sounds/pantodown.wav", 1000.0f, 10.0f, 200.0f, me, "a.pant0"); } else if(myTrain.GetPantographState() = 3 { // two goes up World.PlaySound(selfAsset, "sounds/pantoup.wav", 1000.0f, 10.0f, 200.0f, me, "a.pant1"); } } } };