Elevator Script (Video)

Various OpenSIM Demonstrations

Elevator Script (Video)

Postby nebadon on Tue Oct 07, 2008 4:17 pm

(click link to view video)

during my testing of scripts wandered across this script from Jeff Heaton for making Elevators, as you can see in the video they work quite well. and since it was working so well i figured i would share it with you all, here it is:

Elevator Script:
Code: Select all
// From the book:
//
// Scripting Recipes for Second Life
// by Jeff Heaton (Encog Dod in SL)
// ISBN: 160439000X
// Copyright 2007 by Heaton Research, Inc.
//
// This script may be freely copied and modified so long as this header
// remains unmodified.
//
// For more information about this book visit the following web site:
//
// http://www.heatonresearch.com/articles/series/22/

integer CHANNEL = 42; // dialog channel
list MENU_MAIN = ["Floor 1", "Floor 2", "Floor 3", "Floor 4", "Floor 5", "Floor 6", "Floor 7", "Floor 8", "Floor 9", "Floor 10","Roof"]; // the main menu

float BOTTOM = 22.260;
float FLOOR_HEIGHT = 10;
float SPEED = 2;
float target;


default
{
    state_entry()
    {
        llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
        llSitTarget(<0,-0.5,0.5>, llEuler2Rot(<0,0,-90>) );
        llSetText("Sit Here to Ride Elevator",<0,0,0>,1.0);
        target = BOTTOM;
    }
   
    listen(integer channel, string name, key id, string message)
    {
        integer idx = llListFindList(MENU_MAIN, [message]);
        if( idx!=-1 )
        {
            llSay(0,"Elevator heading to " + message + "." );
            target = BOTTOM + (idx*10);
            state moving;
        }
    }

    changed(integer Change)
    {
        llDialog(llAvatarOnSitTarget(), "Where to?", MENU_MAIN, CHANNEL);
    }
   
}

state moving
{
   
   
    state_entry()
    {
        llSetTimerEvent(0.1);
    }
   
    timer()
    {
        vector pos = llGetPos();
       
        if( pos.z!=target )
        {
            if( pos.z>target )
            {
                pos.z = pos.z - SPEED;
            }
            else
            {
                pos.z = pos.z + SPEED;
            }
        }
       
        if(  llFabs(pos.z - target) < SPEED )
        {
            pos.z = target;
            llSetTimerEvent(0);
            llSetPos(pos);
            llSay(0,"Elevator has reached its target." );
            state default;
        }   
       
        llSetPos(pos);
       
    }
}


Call Elevator Button:
Code: Select all
integer CHANNEL = 42; // dialog channel

default
{
    state_entry()
    {
        llSetText("Touch to Call Elevator",<0,0,0>,1.0);
    }

    touch_start(integer total_number)
    {
               
        llRegionSay(42, "Floor 1");
    }
}


Enjoy :ugeek:
nebadon
Site Admin
 
Posts: 20
Joined: Mon Feb 11, 2008 5:46 pm


Return to OpenSIM Video Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron