I've been adding certain onboard sounds to my rides and I have a few questions for you. Here is my basic script for adding an onboard audio file that is triggered by a track trigger.
Code: Select all
import com.nolimitscoaster.*;
// Original script by Ole Lange
public class OnboardMusicLS extends Script implements TrackTriggerListener
{
private static final String musicFile = "Launch Sequence.ogg";
private static final String startMusicTriggerName = "LaunchSequence";
private static final String stopMusicTriggerName = "ELS";
private TrackTrigger startMusicTrig;
private TrackTrigger stopMusicTrig;
public bool onInit()
{
Coaster coaster = sim.getCoasterForEntityId(getParentEntityId());
if (coaster == null){
System.err.println("This script must be attached to a coaster");
return false;
}
startMusicTrig = coaster.getTrackTrigger(startMusicTriggerName);
if (startMusicTrig == null){
System.err.println("TrackTrigger not found: '" + startMusicTriggerName + "'");
return false;
}
startMusicTrig.addTrackTriggerListener(this);
stopMusicTrig = coaster.getTrackTrigger(stopMusicTriggerName);
if (stopMusicTrig == null){
System.err.println("TrackTrigger not found: '" + stopMusicTriggerName + "'");
return false;
}
stopMusicTrig.addTrackTriggerListener(this);
for (int i=0; i<coaster.getTrainCount(); ++i)
{
StreamedSound music = StreamedSound.loadFromFile(musicFile);
if (music == null){
System.err.println("Music file cannot be found or opened: '" + musicFile + "'");
return false;
}
Train train = coaster.getTrainAt(i);
train.setOnboardStreamedSound(music);
}
return true;
}
public void onTrainEntering(TrackTrigger trigger, Train train)
{
StreamedSound music = train.getOnboardStreamedSound();
if (music != null)
{
if (trigger == startMusicTrig)
{
music.stop();
music.play();
}
else if (trigger == stopMusicTrig){
music.stopFaded(5.0f);
}
}
}
public void onTrainLeaving(TrackTrigger trigger, Train train)
{
}
}
Question one: When I try to add another set of script to this file for another trigger, NL says it wont allow for more than one class definition per file. any way around this so I can reduce the amount of script files included in the package?
Question two: Is there any way to get scripts and sounds in different folders rather than only in the root folder and still have them work? I'd like to be organized that way.