Not signed in (Sign In)

Discussion Tag Cloud

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthornolimiters
    • CommentTimeAug 24th 2017
     
    ^ I would like to know that too!
    •  
      CommentAuthorbestdani
    • CommentTimeAug 24th 2017 edited
     

    /**
    * Save as: AttachToRail.nlvm
    *
    * Attaches a scene object to a coaster rail when the scene object uses
    * this script.
    * Enter "update" (without quotes) as the object name in its property dialoge
    * inside the NL2 Editor to move it with the coaster track on transfer tables,
    * switches and so on.
    */
    import com.nolimitscoaster.*;

    public class AttachToRail extends Script{
    private static final float TRACK_SEARCH_RADIUS = 3.0f;
    private static final String UPDATE_KEYWORD = "update";

    private SceneObject sco;
    private TrackPos trackPos;

    public final bool onInit(){
    sco = sim.getSceneObjectForEntityId(getParentEntityId());
    if(sco == null){
    System.throwRuntimeException(
    "This script has to be attached to a Scene Object!"
    );
    }

    trackPos = sim.findNearestCoasterTrack(
    sco.getTranslation(), TRACK_SEARCH_RADIUS
    );
    if(trackPos == null){
    System.throwRuntimeException(
    "Could not find a coaster track within a "
    + TRACK_SEARCH_RADIUS
    + "m range!"
    );
    }

    sco.setMatrix(trackPos.getCenterRailsMatrix());

    bool doUpdatePerFrame = sco.getName().equals(UPDATE_KEYWORD);
    return doUpdatePerFrame;
    }

    public final void onNextFrame(float tick){
    sco.setMatrix(trackPos.getCenterRailsMatrix());
    }
    }
  1.  
    Thank you!
    •  
      CommentAuthornolimiters
    • CommentTimeAug 24th 2017 edited
     
    Thanks for the script!
    But it doesn't work for me. I attached the "AttachToRail.nlvm" to the object in the NL2SCO editor. And named the object "update" in the Scene Object Instance Properties.
    Placed the object within the range of the track. But when the trackswitch moves, the object doesn't move with it.

    EDIT: FIXED It doen't work because of multiple instance, which not all used as a moving object.

    EDIT 2: But I have placement problems now, it appears at a different spot then where I placed it in the Editor.
  2.  
    you will have to adjust the position of it with the nlsco editor until its right.
    •  
      CommentAuthornolimiters
    • CommentTimeAug 24th 2017
     
    ^Ahh thanks!
    •  
      CommentAuthorrcth
    • CommentTimeSep 5th 2017
     
    I have a lot of objects in my Blender file and I named them including spaces. However this causes a few problems in NL2 with scripting. If I remove all spaces in a name, my script can find the SceneObjectElement, however it can't with spaces. Am I doing something wrong or is it a NL2 limitation?
    • CommentAuthorMrRC
    • CommentTimeSep 5th 2017
     
    u can use _ (underscore) that does work with NL2.
    •  
      CommentAuthorbestdani
    • CommentTimeSep 5th 2017 edited
     
    ^^ That's not a NL2 limitation or problem. It's what the blender COLLADA exporter does. NL2 can handle elements with white spaces in their names without problems.

    I don't know if this is a COLLADA format specification restriction but blender's COLLADA exporter replaces all white spaces with an underscore as well as the automatically added "." character for example. Anyway if you edit the names in this file manually to restore whitespaces NL2 can handle these without problems.

    I recommend to check the exported element names for example by reimporting the COLLADA file into a new blender session, or using a model inspector (the NL2SCO clipping menu works fine to check this):
    http://i.imgur.com/Fl2UaqT.png

    Really ugly things happen by the way when you have the same name with one time with white spaces and one time with underscores (nobody would hopefully do this for practical purposes), the exporter will then replace the characters and not check if this name already exists.
    •  
      CommentAuthorrcth
    • CommentTimeSep 6th 2017
     
    Okay thank you for the answers. I'll remember that for the next time.
    • CommentAuthoriHack97
    • CommentTimeSep 14th 2017
     
    I know that nl2 scripting is pretty similar to Java/C++, but i'm still wondering what I should learn to use Telemetry
  3.  
    ^Java
    •  
      CommentAuthorrcth
    • CommentTimeSep 15th 2017 edited
     
    There's a Java example for the telemetry server.

    Also, NL2 scripting engine is more C# than C++. :P
    • CommentAuthorMrRC
    • CommentTimeOct 3rd 2017 edited
     
    A question for all scripters.

    I have a park with several different coaster styles.

    I have a script with tracktriggers to make an object rotate, but the object is 60 m from the coastertrack in a different part of the park.
    My script is picking the wrong coaster id and saying tracktriggers NOT found.

    I need it to work with only 1 specified coasterstyle id for triggering this object. (coaster id = 47)

    The coaster thats triggering is a hidden coaster just for triggering the object.


    https://pastebin.com/H8qiHSce

    plz help ....
    •  
      CommentAuthorrcth
    • CommentTimeOct 4th 2017
     
    Coaster coaster = sim.getCoaster("NAME OF COASTER");

    Much simpler than using IDs.
    • CommentAuthorMrRC
    • CommentTimeOct 4th 2017
     
    @ rcth

    Yes tnx, thats much easier to use.
    •  
      CommentAuthorZingo
    • CommentTimeOct 16th 2017
     
    I was wondering if someone knows a easy/good way to make certain parts of an object move/rotate while being attached to another object. So for example an arm on a body while the body also moves. Any other way then keyframe it/do in in a 3d program?
    •  
      CommentAuthorbestdani
    • CommentTimeOct 16th 2017 edited
     
    This actually works straight forwad, if the parenting in the 3d model has been done and exported correctly like in this example:



    import com.nolimitscoaster.*;

    public class RotationDemo extends Script{
    SceneObjectElement parent, child;
    private float rotation;

    public bool onInit(){
    SceneObject sco = sim.getSceneObjectForEntityId(getParentEntityId());
    parent = sco.getElementForName("parent");
    child = sco.getElementForName("child");
    return true;
    }

    public void onNextFrame(float tick){
    rotation += 3 * tick;
    parent.setRotation(0, rotation, 0);
    child.setRotation(0, 0, 1.337f * rotation);
    }
    }


    The same holds if you move / rotate a whole scene object for all the parts within the object.
    •  
      CommentAuthorZingo
    • CommentTimeOct 16th 2017
     
    Ow, wow, that indeed looks easier than I thought. I'm going to try that later this week. Thanks man!
    • CommentAuthorMrRC
    • CommentTimeOct 24th 2017 edited
     
    EDIT : Help no longer needed, is solved.

    Who has a simple timerscript that switch 3 lights (red, yellow, green) and starts the timer with 1 trigger ?
    • CommentAuthoriHack97
    • CommentTimeOct 26th 2017
     
    Is it possible to use "setRotation()" with this orientation?

  4.  
    ^ You need to apply the transformation in Blender. Press Ctrl+A and "Apply Rotation". The gizmo should then be level.

    You'll probably want to merge most of those objects before exporting.
    • CommentAuthoriHack97
    • CommentTimeOct 26th 2017 edited
     
    ^Because i want those vehicles to do this



    but when i add the "sco.setRotation()" method, it does this

  5.  
    ^ There are two things you should fix on your exported model:

    1. Currently, all of the pieces of the ride are separate objects. Select all of the objects which will have the same rotation applied to them (i.e. the cars, the support arms, guide wires and any part of the central tower that should spin) and merge them (Ctrl+J).

    2. You also have a transformation applied to the object (the RGB "gizmo" is tilted off-axis). Press Ctrl+A and "Apply Rotation", and the gizmo should now point straight up.

    •  
      CommentAuthorbestdani
    • CommentTimeOct 26th 2017 edited
     
    but when i add the "sco.setRotation()" method, it does this
    I guess you rather should use SceneObjectElement.setRotation(...) for every arm and for this it is required to keep every arm a separate piece / element (?! to ^) in the model and you should not join them.

    I also think it makes sense to keep the orientation as it is in your model, when I remember correctly nl2 does not care about this very much, you would have to calculate / set the rotation axis relative to the scene object axis for the element rotation to work correctly.
    (I think to use the SceneObjectElement.setRotation(float angle, nlvm.math3d.Vector3f axis) variant with the correct rotation axis for each element in the sco coordinates might be the best one for this purpose.)
  6.  
    Hello, I'm making an attraction that plays music and plays a movie on a particular piece of music. Does anyone know a script that automatically plays a video on the right piece of music
  7.  
    looking to see if anyone can help me with a script thatll make a coaster im working on function like ZDT's Switchback coaster.
    •  
      CommentAuthorNemesisRider
    • CommentTimeNov 11th 2017 edited
     
    Having some major issues with trying to edit the current "External Camera Script" so it changes based on a timer (e.g. look at Target1, wait 5 seconds, look at Target2) instead of focusing on the closest target. Could anyone help with this?
    •  
      CommentAuthorbestdani
    • CommentTimeNov 11th 2017
     
    ^ Unfortunately I guess it's hardly possible to help for anyone without the information what you did and where you got stuck.
  8.  


    This is the object in question - it's one of the default NL2 objects. This is the section I think I need to edit, from the unaltered script.

    if (_autoLookAt)
    {
    Vector3f cameraPos = new Vector3f(mTemp.elemAt(3, 0), mTemp.elemAt(3, 1), mTemp.elemAt(3, 2));
    Vector3f v = new Vector3f((float)_defaultLookAtPositionX, (float)_defaultLookAtPositionY, (float)_defaultLookAtPositionZ);

    int nNearestTarget = findNearestPosition(cameraPos, v);

    // Targets have switched. Take a snapshot of the last target
    if (_lastNearestTarget != nNearestTarget)
    {
    if (_lastNearestTarget != -1)
    {
    _lastNearestTargetPos = _lastTargetPos;
    _lastTargetPos = null;
    _curMorphTime = 0;
    }

    _lastNearestTarget = nNearestTarget;
    }

    // morph between last position and current position
    if (_lastNearestTargetPos != null && nNearestTarget != -1)
    {
    float fMorphT = _curMorphTime / (float)_totalMorphTime;

    _curMorphTime += tick;

    if (fMorphT >= 1)
    {
    // reached the target
    _curMorphTime = 0;
    _lastNearestTargetPos = null;
    }
    else
    {
    fMorphT = (float)com.nolimitscoaster.Tools.quinticRamp(fMorphT);

    // interpolate
    v.x = fMorphT * v.x + (1-fMorphT) * _lastNearestTargetPos.x;
    v.y = fMorphT * v.y + (1-fMorphT) * _lastNearestTargetPos.y;
    v.z = fMorphT * v.z + (1-fMorphT) * _lastNearestTargetPos.z;
    }
    }

    _lastTargetPos = new Vector3f(v.x, v.y, v.z);

    v.x -= cameraPos.x;
    v.y -= cameraPos.y;
    v.z -= cameraPos.z;

    v.normalize();

    Matrix4x4f mInv = new Matrix4x4f();

    mInv.initMatrix(mTemp);
    mInv.invert();

    mInv.multVector3x3(v, v);


    float fAlpha = (float)Math.atan2(v.y, Math.sqrt(v.x*v.x + v.z*v.z));
    float fBeta = (float)Math.atan2(v.x, -v.z);

    Matrix4x4f mRot = new Matrix4x4f();

    mRot.initYRot(-fBeta);
    mTemp.multRight(mRot);

    mRot.initXRot(fAlpha);
    mTemp.multRight(mRot);
    }

    _rideView.setCameraMatrix(mTemp);

    if (_hideCameraWhenUsingCam)
    {
    setVisibleToAllElements(_sco, !_rideView.isActive());
    }
    }


    Honestly, I'm way out of my depth here. Apologies if this still isn't much help - I have never edited a script to this extent before.
    •  
      CommentAuthorbestdani
    • CommentTimeNov 11th 2017 edited
     
    From a short glimpse on the script I guess the main task would be replacing the method that is used in this line

    int nNearestTarget = findNearestPosition(cameraPos, v);

    by a new method that switches the position based on a timer. The timer is just a variable that must be added at the beginning of the script where all the other variables are located

    private float timer = 0;

    The new function could look like this:

    private int getNextPositionAfter(float changingTime, float tick){
    // !!!
    // it's important that the timer is intialized with 0
    // and lastNearestTarget with -1 to make this work at it's first call in the
    // onNextFrame method
    // !!!

    //count down timer and check if it passed 0.
    timer -= tick;
    if(timer <= 0){
    //set timer to the changingTime value
    timer += changingTime;

    //the next position is
    int positionIndex = _lastNearestTarget + 1;

    //basically it's done now already, we just have to prevent an index that
    // is larger than the actual number of cameras, so that the script
    // does not stop with an runtime error when accessing the target
    if(positionIndex < _targets.size()){
    //we did not reached the end
    return positionIndex;
    }else{
    //we reached the end, so we could stop now or go to the first target
    //I do the second option:
    return 0;
    }
    }else{
    //timer end not reached, so just return the last target
    return _lastNearestTarget;
    }
    }


    with that function added to the script, the replaced line should look like this:

    int nNearestTarget = getNextPositionAfter(5.0f, tick);

    to switch to the next target every 5 seconds.

    I think we should not mind that the naming of the "nNearestTarget" variable does not really make sense anymore ;-)

    I did not test anything, so there might be typos or bugs in my (3 minute) code or even some general error with my idea.
  9.  
    Is it possible to script an uploaded park to only walk and run? Maybe you can script a terrain setting for this?
    •  
      CommentAuthorbestdani
    • CommentTime2 days ago
     
    That's not possible.
    •  
      CommentAuthorKingRCT3
    • CommentTime2 days ago
     
    You mean disable the flying view? You can script something to stick in front of the camera (a black image for instance), but I don't know if a script can differentiate the change of views.
    •  
      CommentAuthorKevan
    • CommentTime1 day ago edited
     
    You might be able to use


    Externalrideview.isInWalkMode();

    Checks if the player is in walk mode
    If the view is active, the last state is returned that was present before the user switched to the view. If the view is not active, the current state is returned.
    Returns:
    true = player is/was in walk mode, false otherwise



    And if false attach a black cube to

    Sim.getViewPos(nlvm.math3d.Vector3f pos);
    •  
      CommentAuthorbestdani
    • CommentTime1 day ago
     
    ^ This would also be triggered when the player enters a coaster, so it normally does not help much (I tested it in the past ;-)).
    •  
      CommentAuthorKevan
    • CommentTime1 day ago
     
    What about something like this.

    OnNextFrame(){
    if( currentlyWalking ){
    if( Button.isPressed( Button.CHANGE_VIEW_MODE) ){
    if(!wasQPressedInLastFrame){
    currentlyWalking = false;
    wasQPressedInLastFrame = true;
    }
    }else{
    wasQPressedInLastFrame = false;
    }

    //Do your stuff here to block the view or something

    }else{
    if( Button.isPressed( Button.CHANGE_VIEW_MODE) ){
    if(!wasQPressedInLastFrame){
    currentlyWalking = true;
    wasQPressedInLastFrame = true;
    }
    }else{
    wasQPressedInLastFrame = false;
    }
    }
    }
    •  
      CommentAuthorbestdani
    • CommentTime1 day ago edited
     
    From walk mode I guess one usually enters a coaster with 'e' which can't be queried, CHANGE_VIEW_MODE is 'q' in the default settings. I think the only chance to go around this would be by checking if the view position is very close to a coaster car, but I think such workaround solutions aren't very good, I think it would be rather better to have a native "restrict to walk mode" option for parks, but these might be a problem for VR usage, since walking is supposed to trigger massive motion sickness.

    Unless something like that is implemented, I guess the best solution is.... ;-)


    public class DisplayMessage extends com.nolimitscoaster.Script{
    public bool onInit(){

    //pops up and will be printed in red when the script get launched (put on a coaster for example)
    System.err.println(
    "Hey mister! In this park you should only use the walk mode and never fly around or it's your own fault if you miss something or you cannot enjoy everything properly since some features rely on that you do so!"
    );

    return false;
    }
    }
    •  
      CommentAuthorKevan
    • CommentTime1 day ago
     
    I understood the question as just not allowing flying inside the simulator. My script allows for riding coaster and walking/running. but does not allow flying.
    •  
      CommentAuthorbestdani
    • CommentTime22 hours ago
     
    Ehm yes, rereading my comment I realized I somewhat missed the point. I meant when you entered a coaster (with 'E') that, that you could trick the script when you press 'Q' again in the ride view. The script would have registered a mode change and show a black box, when you leave the ride at this point, you would have even contradicting states between the script status and the real status.

    A combination of checking the keyboard press and the ERV walk view query could improve this, but I think in the end, pausing the sim and changing the mode could always introduce trouble with this kind of workarounds.
  10.  
    Thank you, guys. Kevan seems to be on to something?