Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sliding Door I like - need Multi-user lock help

Merlene Writer
Registered User
Join date: 16 Nov 2007
Posts: 8
12-07-2007 14:58
Hi there,

I'm absolutely hopeless at scripting and I'm beyond grateful for the hard work those of you who can script put into things.

I've used the script below to create sliding doors in a house I'm building and I love how it works. I want to be able to set multiple avatar names to use these doors though and as the script is written, only the owner can lock or unlock the doors. I've no idea how to add multiple users. Thanks in advance:

[script 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.20, 0, 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 = 2.5;
// How long the door stays open

string sSKeyword = "FRONT";
// 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;
}
}
}

[/script code]
Renee Roundfield
Registered User
Join date: 10 Mar 2006
Posts: 278
12-07-2007 20:37
You can declare an access list in the beginning.

list Access = ["Name One", "Name Two"];

Or you could read a notecard into a list.

You could also add a mechanism for adding or removing names from the list to the script.


You will have to change the listen that currently only looks for owner to listen to everyone.

Then test the id received in listen against the list.

name = llKey2Name (id);
integer okay = llListFindList(Access, [name];

then where the test is id == owner, replace with

okay != -1

(-1 is the not found condition)

I'm sending the script to you to test. I am not the best scripter in either world. If I were doing this I would initiate listens by touch instead of having open listens perhaps.
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
12-08-2007 08:58
I think someone modded the multi-user lockable door script I maintained for a while and made it a sliding door.
Merlene Writer
Registered User
Join date: 16 Nov 2007
Posts: 8
12-08-2007 09:45
Renee that worked great! Thank you!
It's exactly what I've been looking for :)

~ Merlene Writer