Skip to content

All Comments

8961 to 8980 of 19729

Filter comments

Onboard Music controled by triggers
NoLimits Coaster

Hey MrRC,

thanks for the script.

I modified the .nlvm script with my own .ogg-file names and created a NL2Script with the NL2 Editor.

*public class Onboard_Multi_Music extends Script implements TrackTriggerListener
{
private static final String soundFile1 = "Sound 1.ogg";
private static final String soundFile2 = "Sound 2.ogg";
private static final String soundFile3 = "Sound 3.ogg";

private static final String sound1TriggerName = "Sound 1";
private static final String sound2TriggerName = "Sound 2";
private static final String sound3TriggerName = "Sound 3";

private TrackTrigger sound1Trig;
private TrackTrigger sound2Trig;
private TrackTrigger sound3Trig;

public bool onInit()
{
Coaster coaster = sim.getCoasterForEntityId(getParentEntityId());

 sound1Trig = coaster.getTrackTrigger(sound1TriggerName);
 sound1Trig.addTrackTriggerListener(this);
 
 sound2Trig = coaster.getTrackTrigger(sound2TriggerName);
 sound2Trig.addTrackTriggerListener(this);
 
 sound3Trig = coaster.getTrackTrigger(sound3TriggerName);
 sound3Trig.addTrackTriggerListener(this);

 return true;

}

public void onTrainEntering(TrackTrigger trigger, Train train)
{

   StreamedSound sound1 = StreamedSound.loadFromFile(soundFile1);
   StreamedSound sound2 = StreamedSound.loadFromFile(soundFile2);
   StreamedSound sound3 = StreamedSound.loadFromFile(soundFile3);
 
   if (trigger == sound1Trig)
   {
train.setOnboardStreamedSound(sound1);
     sound1.play();
   }
   else if (trigger == sound2Trig)
   {
     train.setOnboardStreamedSound(sound2);
     sound2.play();
   }
   else if (trigger == sound3Trig)
   {
     train.setOnboardStreamedSound(sound3);
     sound3.play();
   }

}

public void onTrainLeaving(TrackTrigger trigger, Train train)
{
}

}*

But there is always an error:

"Execution time: 3ms
Execute Plugin..
Error in File '....\Users\marku\OneDrive\Dokumente\com.nolimitscoaster.nolimits2\TestPark\Onboard_Multi_Music.nlvm' in Line 1: Unknown type: Script
Error in File '....\Users\marku\OneDrive\Dokumente\com.nolimitscoaster.nolimits2\TestPark\Onboard_Multi_Music.nlvm' in Line 1: Unknown type: TrackTriggerListener
...2 error(s), 0 warning(s)"

Then I added

import com.nolimitscoaster.;*

at the beginning of the script and got another error:

*"Execute Plugin..
Executing Plugin...

Exception: NoSuchMethodError: public static void Onboard_Multi_Music.main()
Execution time: 2ms"*

Is that maybe because of a wrong file system structure?

Windows(C:)

users

me

documents

com.nolimitscoaster.nolimits2
That file includes:

  • Onboard_Multi_Music.nl2script
  • Onboard_Multi_Music.nlvm
  • preview-speakr.png
  • sound1.ogg
  • sound2.ogg
  • sound3.ogg
  • TestPark.nl2park
  • TestPark.nl2park_backup

Sorry for my "stupd" questions. But I´m a absolute beginner in scripting.

View comment
Onboard Music controled by triggers
NoLimits Coaster

public class Onboard_Multi_Music extends Script implements TrackTriggerListener
{
   private static final String soundFile1 = "Launch Sequence.ogg";
   private static final String soundFile2 = "Sound 2.ogg";
   private static final String soundFile3 = "Sound 3.ogg";

   private static final String sound1TriggerName = "LaunchSequence";
   private static final String sound2TriggerName = "Sound 2";
   private static final String sound3TriggerName = "Sound 3";

   private TrackTrigger sound1Trig;
   private TrackTrigger sound2Trig;
   private TrackTrigger sound3Trig;
   
 
   public bool onInit()
   {
     Coaster coaster = sim.getCoasterForEntityId(getParentEntityId());

     sound1Trig = coaster.getTrackTrigger(sound1TriggerName);
     sound1Trig.addTrackTriggerListener(this);
     
     sound2Trig = coaster.getTrackTrigger(sound2TriggerName);
     sound2Trig.addTrackTriggerListener(this);
     
     sound3Trig = coaster.getTrackTrigger(sound3TriggerName);
     sound3Trig.addTrackTriggerListener(this);

     return true;
   }

   public void onTrainEntering(TrackTrigger trigger, Train train)
   {
     
       StreamedSound sound1 = StreamedSound.loadFromFile(soundFile1);
       StreamedSound sound2 = StreamedSound.loadFromFile(soundFile2);
       StreamedSound sound3 = StreamedSound.loadFromFile(soundFile3);
     
       if (trigger == sound1Trig)
       {
    train.setOnboardStreamedSound(sound2);
         sound1.play();
       }
       else if (trigger == sound2Trig)
       {
         train.setOnboardStreamedSound(sound2);
         sound2.play();
       }
       else if (trigger == sound3Trig)
       {
         train.setOnboardStreamedSound(sound3);
         sound3.play();
       }
   }

   public void onTrainLeaving(TrackTrigger trigger, Train train)
   {
   }

}

U might need some tweaking like, soundfile names and triggernames
Let me know if u need help with this.

View comment
Onboard Music controled by triggers
NoLimits Coaster

Hi MrRC,

im using the original script included in NL2.

SCRIPT START

import com.nolimitscoaster.*;

public class OnboardMusic extends Script implements TrackTriggerListener
{

private static final String _errprefix = "Onboard Music";

private SceneObject _sco;

private TrackTrigger _startTrig;
private TrackTrigger _stopTrig;

public bool onInit()
{
String errPrefix = _errprefix;
_sco = sim.getSceneObjectForEntityId(getParentEntityId());
if (_sco == null) return false;

// hide all elements
_sco.setElementsVisible(false);

String scoName = _sco.getName();
if (scoName.length() != 0)
{
  errPrefix = errPrefix + " (" + scoName + ')';
}
errPrefix = errPrefix + ": ";

ResourcePath filePath = _sco.getResourcePathParameter("soundfile");
if (filePath == null)
{
  System.err.println(errPrefix + "No sound file selected"); 
  return false;
}  

System.out.println("Soundfile: " + filePath);

Coaster coaster = _sco.getCoasterParameter("coaster");
if (coaster == null)
{
  System.err.println(errPrefix + "No coaster selected");
  return false;
}

int nNumTrains = coaster.getTrainCount();
if (nNumTrains == 0)
{
  System.err.println(errPrefix + "Coaster has no trains");
  return false;
}

_startTrig = _sco.getTrackTriggerParameter("starttrigger");
if (_startTrig == null)
{
  System.err.println(errPrefix + "No start trigger selected");
  return false;
}

_startTrig.addTrackTriggerListener(this);
 
_stopTrig = coaster.getTrackTrigger("stoptrigger");
if (_stopTrig != null)
{
  _stopTrig.addTrackTriggerListener(this);
}

Integer ivalue = _sco.getIntegerParameter("train");
if (ivalue == null)
{
  System.err.println(errPrefix + "No train index set");
  return false;
}

int trainIndex = ivalue.intValue();

if (trainIndex <= 0 || trainIndex > nNumTrains)
{
  System.err.println(errPrefix + "Invalid train index = " + trainIndex + ", allowed values: 1..."+nNumTrains);
  return false;
}

float gain = 1;

Double dval = _sco.getDoubleParameter("gain");
if (dval != null)
{
  gain = dval.floatValue();
}

 
 
StreamedSound music = StreamedSound.loadFromResource(filePath);
if (music == null)
{
  System.err.println(errPrefix + "Music file cannot be found or opened: '" + filePath + "'");
  return false;
}

music.setGain(gain);
   
Train train = coaster.getTrainAt(trainIndex-1);     
 
train.setOnboardStreamedSound(music);
 
return true;

}

public void onTrainEntering(TrackTrigger trigger, Train train)
{
StreamedSound music = train.getOnboardStreamedSound();
if (music != null)
{
if (trigger == _startTrig)
{
music.stop();
music.play();
}
else if (trigger == _stopTrig)
{
music.stopFaded(5.0f);
}
}
}

public void onTrainLeaving(TrackTrigger trigger, Train train)
{
}

}

SCRIPT END

And I made a little mistake in my last post. The Result is:

Trigger 1 >>> Start .ogg file B
Trigger 2 >>> nothing, keeps playing file B
Trigger 3 >>> Restart .ogg file B
Trigger 4 >>> nothing, keeps playing file B

So every Start Trigger is startimg file B and the stop triggers do nothing.
I Already tried to change "music.stopFaded(5.0f);" ti "music.stop()". But it also didn´t work.

View comment
8961 to 8980 of 19729