Change font size
It is currently Sat Dec 15, 2018 1:04 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 1 post ]
Author Message
 Post subject: Elevator
PostPosted: Sun Oct 05, 2008 1:38 am 
Site Admin
User avatar

Joined: Sat Feb 02, 2008 5:27 pm
Posts: 843
ELEVATOR:
{L_CODE}:
// 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"]; // the main menu

float BOTTOM = 22.200;
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 center to control Elevator",<1,1,1>,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*FLOOR_HEIGHT);
            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:
{L_CODE}:
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");
    }
}


Last edited by Nebadon Izumi on Mon Jul 13, 2009 12:45 am, edited 1 time in total.
Updated to work with actual floor heights and not be hard coded to 10m floors


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 1 post ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net