Simple Second Life elevator script

5 February 2009

Yesterday, Dad and I worked on a simple elevator script for Second Life.

Well, actually, it wasn’t technically on Second Life — rather, it was on my OpenSim node attached to OSGrid, but this script should work on Second Life as well. Note that I haven’t actually tested it on Second Life, and OpenSim translates LSL to C# and compiles it with Mono, so behaviour may not be smooth on Second Life.

But anyways, here’s the script:

vector LIFT_TOP    = <112.,112.,81.5>;
vector LIFT_BOTTOM = <112.,112.,27.>;

Travelator(vector start, vector finish)
{
    float  distance = 0;
    float  progress = 0;
    float increment = 1;

    vector direction = finish - start;
    vector dir_normal = llVecNorm(direction);
    distance = llVecDist(finish, start);

    vector next_pos = start;

    llSetPos(next_pos);

    do
    {
        progress += increment;
        if (progress >= distance)
        {
            llSetPos(finish);
            return;
        }
        next_pos += increment * dir_normal;
        llSetPos(next_pos);
    } while (progress <= distance);

}

default
{
    state_entry()
    {
        llWhisper(0, "Going down...");
        Travelator(LIFT_TOP, LIFT_BOTTOM);
    }

    touch_start(integer num_detected)
    {
        state top;
    }
}

state top
{
    state_entry()
    {
        llWhisper(0, "Going up...");
        Travelator(LIFT_BOTTOM, LIFT_TOP);
    }

    touch_start(integer num_detected)
    {
        state default;
    }
}

The constants LIFT_TOP and LIFT_BOTTOM are the coordinates of the top and bottom points of the elevator. This script does not support multiple storeys or call buttons -- rather, it's something you should build upon, rather than use out of the box.

Have fun.

20 replies

  • Adalace says:

    Thx for sharing. Example works fine.

  • Much thanks for this script! It works great for a single platform for carrying avies up and down.

    I tried to have a linked railing on the platform of about 5 prims total, with the base of the platform the root prim. When I used the script every time the base got above about 10 meters, the avies would fall off. However the same base by itself let the avies ride the whole way up and down without falling through.

    Any ideas why this prim in a linked set would behave differently than when it’s by itself?

    • Jeremy says:

      Hey dude. Not really sure about that — the unofficial documentation on llSetPos() says that for “child prims in a linked set, the position is relative to the parent prim’s position”.

      And I’ve run my elevator as part of a linked prim set, which worked fine, so I can’t really tell you what’s going wrong. I’m certainly no scripting guru.

      Sorry about that.

  • Marcis Xevion says:

    Can you call the elevator with a button (prim). I know you can with other scripts.

    • Jeremy says:

      Should be easy enough to implement. Add a call to llListen() within state_entry(), and turn the touch_start() handler into a listen() handler.

      Then, create a button prim that calls llSay() and sends the message to whatever channel you told the elevator to listen on.

    • Trixx says:

      Should be easy enough to implement. Add a call to llListen() within state_entry(), and turn the touch_start() handler into a listen() handler.

      Then, create a button prim that calls llSay() and sends the message to whatever channel you told the elevator to listen on.

      I’ve tried and tried, and for the life of me, I can’t figure out how to do that. I know how to script the call buttons, but I can’t figure out how to put it in the actual elevator script. I’m an LSL newb, but I do know my way around Java and C.

      If you could please give me an example of how to add llListen and all that good stuff with some example vectors (ideally an example script), I would forever be in your debt.

      Thank you so much for creating/sharing this, and it works perfectly so far for me even though its been three years.

      Cheers!

    • Jeremy says:

      Sorry, I don’t even understand myself what I wrote above. I haven’t done LSL for years, so I can’t really help you.

    • Trixx says:

      Oh, well. Thank you very much for taking the time to respond. :)

  • Harry Aubos says:

    If I had omore floors, how would I install them?

    and then how Do i make a control panel inside the elevator that has all the floors listed?

    Thanks!

    • Harry Aubos says:

      By the Control panel question, How do I make it so that when you press say, 3 on the panel, how do I make the elevator goto the LIFT_MIDDLE? or what ever te floor is called

    • Jeremy says:

      This script is probably a bit too simplistic to handle multiple floors. By me posting it here, it’s kind of like “use it if you can, don’t if you can’t”.

      With regards to a control panel, see what I wrote to Marcis above.

  • Kushaba says:

    Ah i’ve been looking for this script! thank you very much
    now this script is touch activated correct?

  • saberwind says:

    For anyone currently working on learning this stuff, like me:

    this code no longer works.

    Goes up and down on touch event, but refuses to carry an Avatar. Same problem with my own code. Like mine, should work if you Sit on the prim first, making your Avatar part of the linkset.

    I’m still trying to find the proper resolution, possibly physics engine calls?

  • Madryoch says:

    Excuse me i am new to this but when i use the script and my toon is on the platform he falls through it.

    On top of that is there a way for me to create a touch oriented script that instead of making an item move upwards make it rotate?

    Thanx in advance

    George

    • Jeremy says:

      I haven’t tested the script in ages. In all possibility, changes to the sim physics engine on LL’s end may mean that tweaks are required.

      As for rotating, I’d start here.

  • Geoff says:

    Hi
    A scripting noob here, but would like to make the elevator rise and fall a lot slower… Any idea on what I need to do to the script??
    Thanks
    Geoff

  • Geoff says:

    I’m not that much of a noob!!… I did that and the object did not return fully to its lower position!!… despite resets and trying many times…
    I wouldn’t ask otherwise!!
    Geoff

    • Jeremy says:

      Hmm, sadly I don’t have Second Life any more so I’m quite useless at debugging it. This script is far from perfect — even when I ran it, it was rather jerky when moving.

      If you do figure it out, let me know.

      I think an elevator based on llMoveToTarget() would be better.

Leave a reply

Change your avatar.