Board index Roller Coaster Games NoLimits Coaster 2 NoLimits Coaster 2 Scripting Doesn't know how to code | Requesting scripting master

Doesn't know how to code | Requesting scripting master

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


Posts: 216
Points on hand: 3,149.00 Points
Location: USA

I really want to add lights to my coaster trains but I have no idea how to code it. I would really appreciate it if someone could write me a script to do this. Also, do I need to have any NL2SCO objects?


Posts: 191
Points on hand: 764.00 Points
It??s easier as you might think.

import com.nolimitscoaster.*;
import nlvm.math3d.*;


public class attach_object1 extends Script
{
   private static final float xOffset = 0; // left/right
   private static final float  yOffset = 0; //up/down
   private static final float  zOffset = 0; //back/forth
   private static final float range = 5;   // The first train within this range of the scene object will receive the attachment. (range is in meters)
   private static final int carToAttach = 0; // Defines the car on the train that will receive the attachment. (0 = lead car or zero car)
   
   private SceneObject sco;   // Scenery object handle.
   private Train train;   // Train handle.
   private Vector3f posOut = new Vector3f(0,0,0);   // Will store the scenery object's position based on the car's position.
   private Vector3f pitchHeadBankOut = new Vector3f(0,0,0);   // Will store the scenery object's orientation based on the car's orientation.
   private Matrix4x4f carMatrix = new Matrix4x4f();   // Will store the car's orientation.
   
   float xOffset_cam1 = 0;
   float yOffset_cam1 = 0;
   float zOffset_cam1 = 0;
   ExternalRideView pov;
   
   public bool onInit()
   {                           
      sco = sim.getSceneObjectForEntityId(getParentEntityId());
      if (sco == null)
      {
         System.err.println("BoatTripCar1.nlvm: This script must be assigned to a scene object.");
         return false;
      }
      
      TrackPos trackPos = sim.findNearestCoasterTrack(sco.getTranslation(), range);
      if (trackPos == null)
      {
         System.err.println("BoatTripCar1.nlvm: No track found within range of " + range + " meters.");
         return false;
      }
      
      Coaster coaster = trackPos.getCoaster();
      train = coaster.findNearestTrain(sco.getTranslation(), range);
      if (train == null)
      {
         System.err.println("BoatTripCar1.nlvm: No train found within range of " + range + " meters.");
         return false;
      }
      
      
      pov = sim.createExternalRideView();
      pov.setEnterWarpPointEnabled(true);
      pov.setLabel("Enter POV Cam");
      
      return true;
   }

   Matrix4x4f matrixCamera = new Matrix4x4f();
   
   public void onNextFrame(float tick)
   {
      train.getCarMatrix(carToAttach, carMatrix);
      Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
      Matrix4x4f matrix = new Matrix4x4f();
      matrix.initTrans(xOffset, yOffset, zOffset);
      carMatrix.multRight(matrix);
      Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
      sco.setRotation(pitchHeadBankOut);
      sco.setTranslation(posOut);
      Matrix4x4f matrixCamera = new Matrix4x4f();
      matrixCamera.initTrans(xOffset_cam1, yOffset_cam1, zOffset_cam1);
      carMatrix.multRight(matrixCamera);
      pov.setEnterWarpPoint(posOut,(float)10);
      pov.setCameraMatrix(carMatrix);
   
   }
}


1. Save the code as: attach_object1.nlvm ..

2. You need a simple object like a small cube or something else to attach this object to a train.
If you make it with skethcup, the green axis is facing forwards in NL2! Maybe you`ll adding some lamp models, later.

3. Create a .nl2sco with the cube and add in the scenery tab the attach_object1.nlvm in the script tab

4. Place the created .nl2sco in a range of 5 meter near the train. Start the simulator mode.

5. You??ll now see where your object is attaching to the train. If you want to correct the position, it??s better to move the object in your modeler to the right place instead of manipulation the script ;) Remember, the green axis in sketchup is the facing forward direction.

6. If your object is placed correctly, open the .nl2sco file and add some lights to the object (light tab).

7. You should be done,.. if anything went wrong,.. feel free to post a picture.

The script is having a POV cam, too. So you can use the object also to "ride-check" unfroozen coasters ;) You maybe just have to correct the position of the POV by changing the X,y,Z axis as described in the script:

 float xOffset_cam1 = 0.0f; // left /right
        float yOffset_cam1 = 0.0f; // up / down
   float zOffset_cam1 = 0.0f; // back / forth


Make sure yoou don??t delete the "f" (float) behind the values.
That means that you can enter any number:
1.0 would be one meter.
1.5f would be 1.5 meter.
2.453232.. would be 2.453232 meter... :D

One important point: put all your stuff (script, textures, 3d model, nl2sco) in one common folder! Within your project folder. It doesn??t work if they are spread all over the place ;)

TTD03 User avatar
True Addicts
True Addicts

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


Return to NoLimits Coaster 2 Scripting

 


  • Related topics
    Replies
    Views
    Last post