Board index Roller Coaster Games NoLimits Coaster 2 NoLimits Coaster 2 Scripting [NL2 Script] Onboard Audio

[NL2 Script] Onboard Audio

Post your Nolimits 2 scripts here! Also any discussion regarding scription for NoLimits Coaster 2 should be placed in this forum

Post June 20th, 2014, 7:23 pm
Turbo User avatar
Moderator
Moderator

Posts: 3771
Points on hand: 5,506.00 Points
Bank: 21,857.68 Points
Location: WA, USA

What's up people

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.
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.
Coaster Count: 582 // Top Five: 1. Helix 2. Nemesis 3. Big Bad Wolf 4. Boulder Dash 5. Balder

Coasterkidmwm wrote:
4 G's to the taint was a bit much for me because I'm not a power bottom like Turbo

Post June 20th, 2014, 7:38 pm

Posts: 2318
Points on hand: 4,657.00 Points
Bank: 6,667.00 Points
Location: pennsylvania, USA
I have yet to touch the scripting in NL2 but if I remember from my programming class, if NL2 allows for arrays, you can put each sound into that array can then call it up when you need it
What are these for?

Post June 22nd, 2014, 5:06 pm
TTD03 User avatar
True Addicts
True Addicts

Posts: 7307
Points on hand: 738.00 Points
Bank: 111,265.11 Points

Post June 22nd, 2014, 8:59 pm
Turbo User avatar
Moderator
Moderator

Posts: 3771
Points on hand: 5,506.00 Points
Bank: 21,857.68 Points
Location: WA, USA

lol well I'm glad it could be of help.

As to my questions, does anyone have answers?
Coaster Count: 582 // Top Five: 1. Helix 2. Nemesis 3. Big Bad Wolf 4. Boulder Dash 5. Balder

Coasterkidmwm wrote:
4 G's to the taint was a bit much for me because I'm not a power bottom like Turbo

Post June 23rd, 2014, 12:19 pm
TTD03 User avatar
True Addicts
True Addicts

Posts: 7307
Points on hand: 738.00 Points
Bank: 111,265.11 Points
Not from me :P, my level of scripting is as about as good as the aim of a shotgun by a baby :P

Post July 2nd, 2014, 11:31 am
Turbo User avatar
Moderator
Moderator

Posts: 3771
Points on hand: 5,506.00 Points
Bank: 21,857.68 Points
Location: WA, USA

TO ALL WHO MIGHT USE MY PREVIOUS CODE, DO NOT! This one is better haha, it allows you to add separate sound files to your ride through the use of multiple track triggers.

So, in order for this to work you need to save this code in a .nlvm file through notepad or something similar. once done, you need to change the following:

  1. After public class you must change what I have "OnboardMusicInfinity" to whatever your file name is.
  2. I have shown an example in soundFile1 and sound1TriggerName of what you need to do for adding your multiple sound clips to your ride. soundFile's should be the full file name of your sound file's and TriggerName's should be the name of your NL2 Track Triggers.
  3. If you have more than 3 items you wish to add, you may do so by following the format given for soundFile's and soundTriggerName's.

import com.nolimitscoaster.*;

public class OnboardMusicInfinity 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)
   {
   }

}


EDIT: WOOOO! 2000th POST!
Coaster Count: 582 // Top Five: 1. Helix 2. Nemesis 3. Big Bad Wolf 4. Boulder Dash 5. Balder

Coasterkidmwm wrote:
4 G's to the taint was a bit much for me because I'm not a power bottom like Turbo

Post July 2nd, 2014, 11:33 am
TTD03 User avatar
True Addicts
True Addicts

Posts: 7307
Points on hand: 738.00 Points
Bank: 111,265.11 Points
Nice script, I might actually use it :P
And congrats on 2000 posts, I know I am creeping up to there mighty quickly as well!

Post September 12th, 2020, 3:25 pm

Posts: 15
Points on hand: 587.00 Points
Location: Florida
Does anyone know how to make a OnBoard Audio selections


Return to NoLimits Coaster 2 Scripting

 


  • Related topics
    Replies
    Views
    Last post
cron