Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Lockable sliding door

Phil Metalhead
Game Foundry Leaɗer
Join date: 11 Mar 2003
Posts: 291
04-14-2003 21:59
To make a sliding door that can lock, just put the following code on the object you want to be your door:

CODE
key owner;
// Will be used to retrieve owner's key.

integer iChan = 1000;
// Channel door will listen on if other doors are touched;
// also the channel this door will broadcast on.

integer iSteps = 15;
// How many steps the door will open in, used to provide the
// illusion of sliding. Fewer steps means it opens faster,
// but more steps will make it "slide" smoother.

vector vOffset = <0.0, 0.15, 0.0>;
// Indicates how far the door will move with each step.
// Multiply by iSteps to calculate the total distance the
// door will move.

vector vBase;
// Used to "un-stick" the door if something blocks it.
// Not sure if this is needed since 0.5.1, objects don't
// seem to block the door any more. Leaving it in just
// in case, though. I think attempting to edit the door
// while it's moving may make it stick. This will solve
// that problem as well.

float fOpenTime = 1.5;
// How long the door stays open

string sSKeyword = "open1";
// Keyword door broadcasts when it's touched, to make
// other doors open. You can chain these to make multiple
// doors open when any one is touched.
// NEVER make sSKeyword and sRKeyword the same, or you may
// get some doors stuck in an infinite loop, continuously
// re-triggering each other.

string sRKeyword = "open2";
// Keyword door listens for from other doors. Will open
// when it "hears" this keyword.
// Again, NEVER make sSKeyword and sRKeyword the same.

integer bMove = FALSE;
// Is the door moving?

integer bLock = FALSE;
// Is the door locked?

integer bVerbose = FALSE;
// Confirm when owner locks/unlocks the door.

//*********************************************
// open() -- the meat and taters of the code,
// makes the door actually move.
//*********************************************
open()
{
bMove = TRUE;
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
llSleep(fOpenTime);
basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
if (llGetPos() != vBase) {
llSetTimerEvent(5);
} else {
bMove = FALSE;
}
}

default
{
//***************************************************
// state_entry() -- set up our global variables and
// initialize the listen events.
//***************************************************
state_entry()
{
vBase = llGetPos();
owner = llGetOwner();
llListen(0,"",owner,"");
llListen(iChan,"",NULL_KEY,sRKeyword);
}

//***************************************************
// listen() -- listen for other doors opening, and
// if owner wants to lock/unlock doors.
//***************************************************
listen(integer chan, string name, key id, string msg)
{
if (chan == iChan && msg == sRKeyword) {
if (!bMove && !bLock) open();
if (bLock && bVerbose) llSay(0,"Locked!");
}
if (chan == 0 && id == owner && msg == "lock") {
bLock = TRUE;
if (bVerbose) llWhisper(0,"Locked!");
}
if (chan == 0 && id == owner && msg == "unlock") {
bLock = FALSE;
if (bVerbose) llWhisper(0,"Unlocked!");
}
}

//********************************************
// touch_start() -- what to do when someone
// touches the door.
//********************************************
touch_start(integer count)
{
if (bLock) {
llSay(0,"Locked!");
} else {
if (!bMove) {
llWhisper(iChan,sSKeyword);
open();
}
}
}

//****************************************************
// timer() -- this is only used to un-stick the door
// (see vBase definition above).
//****************************************************
timer()
{
llSetPos(vBase);
if(llGetPos() == vBase) {
llSetTimerEvent(0);
bMove = FALSE;
}
}
}


CREDITS
the code originated from an example in the Linden Scripting Language Reference, but has been heavily modified by myself.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread:
04-25-2005 08:48
/15/2b/1907/1.html
_____________________
i've got nothing. ;)
TXGorilla Falcone
KWKAT Planetfurry DJ
Join date: 4 May 2004
Posts: 176
04-28-2005 13:52
2 questions...
First: Can this be used in Child prim in a linked set
Second: Can this be used by a group?
_____________________
Drunken Monkeys danceing on the tables.
Falling from the sky just like in a fable.
Sue Stonebender
Piano Craftsman
Join date: 7 Jan 2005
Posts: 219
Thanks!
05-09-2005 10:57
Thanks, Phil! Really appreciate you sharing this script and how easy it is to adapt it. Renders nice and smoothly too.

Thanks a bunch,

Sue.
_____________________
bingbangboom Bixby
Registered User
Join date: 17 Aug 2004
Posts: 92
05-14-2005 15:47
Do you have one that anyone can use... not so much a lock but just a sliding door script? Thanks
Rmike Javelin
Muskrat Pilot
Join date: 20 Mar 2005
Posts: 159
Need East-West move
05-23-2005 11:39
Phil,

First - thanks for the clear comments on the script- I'm a raw beginner, and it helps a lot.

I have my door sliding, but it moves in the North-South direction. I need East-West motion.
This has to be a real no-brainer, but it's over me head!!
I tried rotating my door 90 deg. on the Z axis, but movement is same (kinda cool, actually, you have to jump in and move aside before the door comes back to push you :)

Anyone :confused:

Edit-- Yay!!! I found it! :D

I found that the 3 values in vOffset are for E-W, N-S, and vertical move. This is obviously one of the first things to learn in the LSL. So now.. I Got it! :rolleyes:

From: someone
vector vOffset = <0.0, 0.15, 0.0>;
// Indicates how far the door will move with each step.
// Multiply by iSteps to calculate the total distance the
// door will move.


So I changed vOffset to <0.15, 0.0, 0.0>

Look mom, I can CRAWL!! :D
Rico Plisskin
Registered User
Join date: 17 Feb 2005
Posts: 104
06-13-2005 17:49
there a way to add sound effects of door for this script?
Simonetos Ventura
Simonetos
Join date: 17 Jul 2006
Posts: 2
04-10-2007 01:31
Hello my friend!!!
Very nice script and usefull :) !!! Congratulations!!!
I just want to ask you a favor. I would like to have the possibility to
add avatars that they can use this door. Can you add this part of script?

Thank you very much!!!
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-10-2007 13:56
From: Simonetos Ventura
Hello my friend!!!
Very nice script and usefull :) !!! Congratulations!!!
I just want to ask you a favor. I would like to have the possibility to
add avatars that they can use this door. Can you add this part of script?

Thank you very much!!!



Generic locks have been covered previously in a number of threads. try this one
The basics are you need to maintain a list of avatars who are allowed to use the door and then when activated check that the activator is or isnt allowed and react accordingly.
The list can be hardcoded or read from anotecard.