Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Multi User Lockable Door

Meiyo Sojourner
Barren Land Hater
Join date: 17 Jul 2004
Posts: 144
10-05-2004 00:20
okay... I am far from a guru or anything but this script started off as a quick and dirty solution to let me and my gf be the only ones that could get in our door and kinda grew over the last night or two. Then tonight I had someone asking for the script so I decided to clean it up a little and release it into the wild. :D There's prolly much better out there but I like mine and thought I'd share. Hope it's useful to someone.


CODE

// Nifty Neato Multi User Lockable Door, A Red Visions Script
// Copyright (C) 2004 Meiyo Sojourner
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// (Also available at http://www.gnu.org/copyleft/gpl.html)
//
// WARNING: Removal of the introduction warning message will corrupt the script.
//
// Additional Credits:
//~~~~~~~~~~~~~~~~~~~~~
// Default door open/close operation from a script by Kyle Chaos




//GLOBALS
//=======
// For the messages, use %nn% in place of the name
// of the av that clicked on the door.
// Set the variable to "" to disable the message.
string startup_message =
"Touch door and say 'show help' in the chat for a list of commands";
string open_message = "%nn% is at the door.";
string close_message = "";
string lock_message = "Sorry %nn%, this door is locked";
float open_time = 30.0;
string open_sound = "Door open"; // These can be set to ""
string close_sound = "Door close"; // to disable the sounds.
integer debug_messages = FALSE;
//- - - - - - - - - - - - - - - -
list auth_list = [];
integer door_open = FALSE;
integer locked = FALSE;
integer listen_tag = -1;
float interval = 30.0;
list help_message = [
"**Multi User Lockable Door Commands List **",
" 'show help' - Displays this file",
" 'lock' - Sets the door to Locked mode",
" 'unlock' - Sets the door to Unlocked mode",
" 'add [name]' - Replace [name] with the av you want to add to the list",
" 'remove [name]' - Replace [name] with an av you want to delete",
" 'say list' - Shows who is on the All Access list",
" 'change time [time]' - Replace [time] with the number of seconds",
" you want the door to stay open and listen."
];


//TOOL FUNCTIONS
//==============
float debug(string m) // Allows for debug messages
{ // to be easily turned on/off
if (debug_messages)
llSay(0,m);
return TRUE;
}
integer k = FALSE;
//- - - - - - - - - - - - - - - -
float debugList(list l) // List version of the
{ // debug() function
string s = "";
if (debug_messages){
integer i;
for (i = 0; i < llGetListLength(l); i++){
s += llList2String(l,i);
if (i < llGetListLength(l) - 1)
s += ", ";
}
if (s == "") {
llSay(0,"LIST IS EMPTY");
}else{
llSay(0,s);
}
}
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer q(){
llSay(0,"This script is provided free of charge.
Please contact Meiyo Sojourner if you paid for it.");
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer d(){
llSay(0,"This script has been unacceptably modified!
It is now deleting itself.");
llRemoveInventory(llGetScriptName());
return TRUE;
}
//- - - - - - - - - - - - - - - -
float sayList(list l) // Dumps the contents of
{ // the list into the chat
string s = "";
integer i;
for (i = 0; i < llGetListLength(l); i++){
s += llList2String(l,i);
if (i < llGetListLength(l) - 1)
s += ", ";
}
if (s == "") {
llSay(0,"LIST IS EMPTY");
}else{
llSay(0,s);
}
return TRUE;
}
//- - - - - - - - - - - - - - - -
float sayList2(list l) // Dumps the contents of the list
{ // into the chat one line at a time
integer i;
for (i = 0; i < llGetListLength(l); i++){
llSay(0,llList2String(l,i));
}
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer isIn(list test_list, list test_item) // Looks for test_item
{ // in test_list
integer i;
for (i = 0; i < llGetListLength(test_list); i++){
if (llList2String(test_item, 0) == llList2String(test_list, i))
return TRUE;
}
return FALSE;
}
//- - - - - - - - - - - - - - - -
string replace(string main, string old, string new) // Search and replace
{ // function for strings
string temp = "";
list m = llParseString2List(main,["%"],[]);
integer i;
for(i = 0; i < llGetListLength(m); i ++){
string c = llList2String(m,i);
if (c == old){
temp += new;
}else{
temp += c;
}
}
return temp;
}
//- - - - - - - - - - - - - - - -

float stopListening() // Kills the listen function
{ // in order to save resources
if(listen_tag != -1)
llListenRemove(listen_tag);
listen_tag = -1;
return TRUE;
}
//- - - - - - - - - - - - - - - -
float removeName(string target_name) // Searches for and deletes
{ // target_name from auth_list
integer i;
for (i = 0; i < llGetListLength(auth_list); i++){
if (target_name == llList2String(auth_list, i)){
auth_list = llDeleteSubList(auth_list, i, i);
return TRUE;
}
}
return FALSE;
}
//- - - - - - - - - - - - - - - -
integer open(string av_name) // Opens the door.
{
if (open_sound != "")
llTriggerSound(open_sound, 0.5);
if (open_message != "")
llSay(0, replace(open_message,"nn",av_name));
// vv Replace this snippet with custom code to close the door vv
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer close(string av_name) // Closes the door.
{
if (close_sound != "")
llTriggerSound(close_sound, 0.5);
if (close_message != "")
llSay(0, replace(close_message,"nn",av_name));
// vv Replace this snippet with custom code to close the door vv
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
return FALSE;
}
//- - - - - - - - - - - - - - - -




//CODE ENTRY
//==========
default
{
state_entry()
{
k = q();
llRequestAgentData(llGetOwner(), DATA_NAME);
}


dataserver(key queryid, string data) {
auth_list += data;
llSay(0,"Owner added to Authorized List.");
if (startup_message != "")
llSay(0,startup_message);
}


on_rez(integer rez)
{
llResetScript();
}


touch_start(integer total_number)
{
if (!k) d();
list temp = [];
if (!door_open){
if (!locked){
door_open = open(llDetectedName(0));
listen_tag = llListen(0,"","","");
llSetTimerEvent(open_time);
} else if (isIn(auth_list, temp += llDetectedName(0))){
debug("authorized");
door_open = open(llDetectedName(0));
listen_tag = llListen(0,"","","");
llSetTimerEvent(open_time);
} else {
llSay(0, replace(lock_message,"nn",llDetectedName(0)));
}
} else {
door_open = close(llDetectedName(0));
}
debug("TEMP =");
debugList(temp);
debug("AUTH_LIST = ");
debugList(auth_list);
}


timer()
{
stopListening();
if (door_open){
door_open = close("the script");
}
}


listen(integer chan, string name, key id, string msg)
{
list temp = [];
if (isIn(auth_list, temp += name)){
list n = llParseString2List(msg, [" "], []);
string cmd_a = llList2String(n, 0);
string cmd_b = llList2String(n, 1);
string cmd_c = llList2String(n, 2);
if (cmd_a == "lock"){
locked = TRUE;
llSay(0,"Door Locked");
}
if (cmd_a == "unlock"){
locked = FALSE;
llSay(0,"Door Unlocked");
}
if (cmd_a == "add"){
if ((cmd_b == "")||(cmd_c == "")){
llSay(0, "Incorrect Name Format!");
}else{
temp = [];
string new_name = cmd_b + " " + cmd_c;
if(!isIn(auth_list, temp += new_name)){
auth_list += new_name;
llSay(0, new_name + " added to list.");
}else{
llSay(0, new_name + " was already on the list.");
}
}
}
if ((cmd_a == "remove")||(cmd_a == "delete")){
if ((cmd_b == "")||(cmd_c == "")){
llSay(0, "Incorrect Name Format!");
}else{
string kill_name = cmd_b + " " + cmd_c;
if (removeName(kill_name)){
llSay(0,"Name Successfully Removed");
}else{
llSay(0,"Name Not Found!");
}
}
}
if ((cmd_a == "say")&&(cmd_b == "list")){
sayList(auth_list);
}
if ((cmd_a == "show")&&(cmd_b == "help")){
sayList2(help_message);
}
if ((cmd_a == "change")&&(cmd_b == "time")){
float foo = llList2Float(n, 2);
if (foo < 10){
llSay(0, "Invalid Time Specified!");
}else{
open_time = foo;
llSay(0, "Open time changed to " + cmd_c + " seconds.");
}
}
}
}
}
_____________________
I was just pondering the immortal words of Socrates when he said...
"I drank what??"
Meiyo Sojourner
Barren Land Hater
Join date: 17 Jul 2004
Posts: 144
10-05-2004 13:15
Here's a poorly written README for the script. Please excuse my laziness ;) Anyway, feel free to hit me with any comments or suggestions.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This door will take commands from anyone on it's authorized list

It has two modes, locked and unlocked.
- locked mode: only users on the authorized list can open the door
- unlocked mode: anyone and their brother can open the door
The door is initially set to unlocked mode.

When the script is first rezzed it will reset itself.

The authorized list is initially completely empty.
Soon after the object containing the script is rezzed, the name of
the owner is retrieved from the servers and added to the
authorized list. This usually takes only a second if that.
After that is done, the owner can continue with setup.

To open the door... simply click on it.
The door will stay open for the time specified by the script's
variable 'open_time' (which can be changed by voice command)
or it can be closed by clicking on it again.

The 'open_time' variable is also the amount of time the door
will listen for commands. Once this time expires, you must
click the door again before you can issue any other commands.
Closing the door manually does not stop the listening; it will
keep listening for the time specified by 'open_time'. The reason
for this is to cut down on the drain on the server... especially in
talkative areas. ;)
A user can issue commands to the door if and only if they are on
the door's authorized list.
When adding users to the authorized list, make sure to get the
caps right. For example, adding "joeschmo linden" will not let
JoeSchmo Linden have full access to the door.

For a list of commands, say "show help" in the chat window after
clicking on the door.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_____________________
I was just pondering the immortal words of Socrates when he said...
"I drank what??"
Daniel Jacobs
Registered Dork
Join date: 3 Jun 2004
Posts: 4
Milti User Lockable Door
10-07-2004 17:42
I tried it, I liked it ... took a little while to figure out that I had to "touch" the door before it would accept commands, but the instructions say to touch, then type in chat.

Just two questions:

1. Is the owner the only one who can lock the door, or can anyone on the authorized list lock the door?

2. If anyone on the authorized list opens the door, is the door still in locked mode to all others?

It's a nice piece of work, and it's very nice of you to share this with us. Thank you very much!!

Daniel :)
Meiyo Sojourner
Barren Land Hater
Join date: 17 Jul 2004
Posts: 144
10-08-2004 18:30
From: Daniel Jacobs
1. Is the owner the only one who can lock the door, or can anyone on the authorized list lock the door?

2. If anyone on the authorized list opens the door, is the door still in locked mode to all others?


1) Anyone on the authorized list can lock and unlock the door. I considered making an "ultra lock" mode where the owner of the door would be the only one who could issue commands / operate the door but I was afraid that this might be overkill... I might rethink this and add it in as an 'upgrade' if ppl want it.

2) If the door is in locked mode and someone on the authorized list opens it, it will be locked still when the door shuts. (Unless that person issues the "unlock" command of course.) The only thing you'd have to watch out for are tail gaters that come thru the door before it closes itself ;) Doubt this would ever be too much of an issue tho.

Glad you like the script and I hope I answered your questions. :D

-Meiyo
_____________________
I was just pondering the immortal words of Socrates when he said...
"I drank what??"
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
*forgets his key all the time*
12-22-2004 11:59
this is a script i use its pretty simple to use u just drop ur name in the code and anyone elses u want by just addin another name (llKey2Name(id) == "Avie name" and thats pretty much it :) saves the hassle of findin out keys too :)
CODE

default
{
on_rez(integer rez)
{
llResetScript();
}

state_entry()
{
llListen(0,"",NULL_KEY,"");
}

touch_start(integer total_number)
{
llTriggerSound("Door open", 0.5);
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state open;
}

listen(integer chan,string name,key id,string msg)
{
if ( (llKey2Name(id) == "Cid Jacobs") || (llKey2Name(id) == "Ziolla Magpie"))
{
if (msg == "lock")
{
state locked;
}
else if (msg == "")
{
}
}
}
}

state open
{
state_entry()
{
}

touch_start(integer total_number)
{
llTriggerSound("Door close", 0.5);
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state default;
}
}

state locked
{
state_entry()
{
llSay(0, "Door Locked.");
llListen(0,"",NULL_KEY,"");
}

touch_start(integer total_number)
{
llSay(0, "Sorry "+llDetectedName(0)+" this door is locked.");;
}

listen(integer chan,string name,key id,string msg)
{
if ( (llKey2Name(id) == "Cid Jacobs") || (llKey2Name(id) == "Ziolla Magpie"))
{
if (msg == "unlock")
{
llSay(0, "Door Unlocked.");
state default;
}
else if (msg == "")
{
}
}
}
}
Prokofy Neva
Virtualtor
Join date: 28 Sep 2004
Posts: 3,698
01-28-2005 19:18
This script keeps giving me an error on line 325. What to do?
_____________________
Rent stalls and walls for $25-$50/week 25-50 prims from Ravenglass Rentals, the mall alternative.
Tito Gomez
Mi Vida Loca
Join date: 1 Aug 2004
Posts: 921
02-15-2005 12:18
Thank you! Just what i was looking for. The scripts work well.

- T -
_____________________
Heather Nyak
Second Life Resident
Join date: 27 Nov 2004
Posts: 184
02-18-2005 00:14
Hi, when using both scripts my door rotated around the center how can i change that?

Thankyou

Heather
Heather Nyak
Second Life Resident
Join date: 27 Nov 2004
Posts: 184
02-18-2005 00:14
Hiya when i use the script they just rotate around the center of the door what am i doing wrong :)
Yoofaloof Pacer
Registered User
Join date: 12 Apr 2005
Posts: 27
05-11-2005 12:56
Works great, but says cannot find door sounds. Any idea where I would get these from and where would I put them? Cheers!


EDIT:No worries, worked it out! Thanks!
Timmy Night
Cliff View Owner
Join date: 4 Apr 2005
Posts: 291
05-17-2005 19:34
Will this work in a sliding door or does modification need to be done?
_____________________
"I'm villifying you for God's sake - pay attention!" Sir Peter O'Toole as King Henry II in "The Lion In Winter"
WindFairie Rosencrans
Registered User
Join date: 4 Feb 2005
Posts: 72
05-21-2005 23:00
Nice work...I also been looking to find the script like this..
but I think if the script is set to be changeable from Lock and to unlock and vice versa setting Only by the owner..it would be more useful
Just it is something I d like more:P

Very kind of you to share this with the community :) thnx
Azazel Czukor
Deep-fried & sanctified
Join date: 30 Jan 2005
Posts: 417
05-28-2005 05:10
From: Timmy Night
Will this work in a sliding door or does modification need to be done?



Timmy, I've modded this script a few different ways depending on what type of door I want, and I have a sliding version of it. It requires a little specific modding (you have to put in the start and end location coords but I have a tool for that too). I'll drop you a copy inworld. If anyone else wants one, just IM me.


-Az
_____________________
Vote YES on Prop 348 - confirmation popup message on all land sales - don't get screwed over! Click here to vote! Or, Click here to discuss!


"The weapon of choice is snark." - Hamlet Linden
Simon Metalhead
Rock Star
Join date: 26 May 2003
Posts: 187
09-07-2005 11:49
Hmm, i know this is kinda old but has anyone modified this script to use with a double door? Ie. instead of it giving you twice the spam and having to click on each door to open them both, have it so you can give commands to both doors and when you click either one, it'll open them both?
_____________________
Come visit me at Natoma (0,0)
_________________________________
Come check out www.rock66.com and sign up! We have given away lots of L$ in our SL Arcade contests! Keep an eye out for more upcoming contests!
Qubius Quinn
Join date: 5 Jun 2005
Posts: 8
09-09-2005 21:15
I hope this is not considered inappropriate but I thought this was a good point to mention my project (closed source... sorry). It handles double doors (one click for both doors), sliding doors (without modification to the code) and patches a security hold I discovered in other type of lockable systems (including this one). I made a full version and a cheap demo version with locking disabled (although it works great as a functioning door).

Again I hope the community doesn't find my post distasteful... I really appreciate your work Meiyo and the open source community but like many other residents like to role play. My role playing in SL is running a virtual business. It's more for fun then the money.
Qubius Quinn
Join date: 5 Jun 2005
Posts: 8
09-09-2005 21:28
I hope this is not considered inappropriate but I thought this was a good point to mention my project (closed source... sorry). It handles double doors (one click for both doors), sliding doors (without modification to the code) and patches a security hold I discovered in other type of lockable systems (including this one). I made a full version and a cheap demo version with locking disabled (although it works great as a functioning door).

Again I hope the community doesn't find my post distasteful... I really appreciate your work Meiyo and the open source community but like many other residents like to role play. My role playing in SL is running a virtual business. It's more for fun then the money.
Cletus Fardel
Registered User
Join date: 5 Oct 2005
Posts: 6
10-05-2005 08:38
nice job. great for that late night activity some of you partake in
Imuy Anubis
Registered User
Join date: 26 Jun 2004
Posts: 4
11-01-2005 09:13
From: Simon Metalhead
Hmm, i know this is kinda old but has anyone modified this script to use with a double door? Ie. instead of it giving you twice the spam and having to click on each door to open them both, have it so you can give commands to both doors and when you click either one, it'll open them both?


I'm looking for this too. If anyone can give me a hand, it would be much appreciated.

Thx in advance,

Imuy.
Imuy Anubis
Registered User
Join date: 26 Jun 2004
Posts: 4
11-01-2005 09:18
From: Simon Metalhead
Hmm, i know this is kinda old but has anyone modified this script to use with a double door? Ie. instead of it giving you twice the spam and having to click on each door to open them both, have it so you can give commands to both doors and when you click either one, it'll open them both?



I'm looking for this too. If somebody wants to give me a hand, it would be much appreciated.

Thx in Advance,

Imuy Anubis.
Rodrick Harrington
Registered User
Join date: 9 Jul 2005
Posts: 150
11-07-2005 11:47
http://www.slexchange.com/modules.php?name=Marketplace&file=item&ItemID=27466

Both modified to work with double doors, and adds an enforcer level so authorized people can only access a locked door, not change the authorized list or lock and unlock the door. It's free :) if you want I can drop you a copy off in game.

--edit I put the link to the gift version on accident (costs $1L so you can have it delivered to another) fixed link to the truely free version
_____________________
Joey Fizz
Registered User
Join date: 3 May 2005
Posts: 3
in need help
11-23-2005 19:56
i need a lockable swinging door for a counter
_____________________
Joey Fizz
Cappy Loudon
Registered User
Join date: 8 Mar 2006
Posts: 1
quick note
03-22-2006 05:21
I quickly glanced over this and noticed one thing right off the bat.

Your function to remove a name from the list can be improved with a built-in function llListFindList().

CODE
float removeName(string target_name) // Searches for and deletes 
{ // target_name from auth_list
integer i;
for (i = 0; i < llGetListLength(auth_list); i++){
if (target_name == llList2String(auth_list, i)){
auth_list = llDeleteSubList(auth_list, i, i);
return TRUE;
}
}
return FALSE;
}


Corrected script:
CODE
float removeName(string target_name) // Searches for and deletes 
{ // target_name from auth_list
integer i;
i = llListFindList(auth_list, [target_name]);
if (i != -1) {
auth_list = llDeleteSubList(auth_list, i, i);
return TRUE;
}
return FALSE;
}


Two more comments/questions:
1. Why use float as return type instead of integer?
2. I'd suggest you use llToLower() when checking/adding/removing names in the list.

Just my 2cp :)

Christophe
Jax Montgomery
Registered User
Join date: 16 May 2006
Posts: 0
Thank you so much
07-02-2006 18:10
First time I came to this forum and this script was exactly what I was looking for. Haven't tried it yet but will try it very soon.

Of course, as I see the flexibility this script provides for simple security, i wonder why more rental property owners don't use something like this. Am getting so tired of seeing rental units that only allow one person on the authorized list for locking and unlocking doors. That option is fine if you're renting alone but what if you have a roomate? What don't more property owners implement this type of scripts on their doors?

Thanks again. I tip my hat to you.
Itazura Radio
Registered User
Join date: 10 May 2006
Posts: 52
08-25-2006 08:21
If anyone has Azazel Czukor's version (or any other version) of this script modded for a sliding door can you send a copy to me in world? I've been looking for a good sliding door script forever.
violetann Petion
Registered User
Join date: 27 Dec 2005
Posts: 67
09-24-2006 11:23
From: Timmy Night
Will this work in a sliding door or does modification need to be done?


slider version...
not perfect in some bits since i made it one click only... i never close doors.

From: someone

// Nifty Neato Multi User Lockable Door, A Red Visions Script
// Copyright (C) 2004 Meiyo Sojourner
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// (Also available at http://www.gnu.org/copyleft/gpl.html)
//
// WARNING: Removal of the introduction warning message will corrupt the script.
//
// Additional Credits:
//~~~~~~~~~~~~~~~~~~~~~
// Default door open/close operation from a script by Kyle Chaos
// moded for slider by violetann petion



//GLOBALS
//=======
// For the messages, use %nn% in place of the name
// of the av that clicked on the door.
// Set the variable to "" to disable the message.

integer iSteps = 10;
vector vOffset = <0.30, 0.0, 0.0>;
integer bMove = FALSE;
float fOpenTime = 1.5;
vector vBase;

string startup_message =
"Touch door and say 'show help' in the chat for a list of commands";
string open_message = "%nn% is at the door.";
string close_message = "";
string lock_message = "Sorry %nn%, this door is locked";
float open_time = 30.0;
string open_sound = "Door open"; // These can be set to ""
string close_sound = "Door close"; // to disable the sounds.
integer debug_messages = FALSE;
//- - - - - - - - - - - - - - - -
list auth_list = [];
integer door_open = FALSE;
integer locked = FALSE;
integer listen_tag = -1;
float interval = 30.0;
list help_message = [
"**Multi User Lockable Door Commands List **",
" 'show help' - Displays this file",
" 'lock' - Sets the door to Locked mode",
" 'unlock' - Sets the door to Unlocked mode",
" 'add [name]' - Replace [name] with the av you want to add to the list",
" 'remove [name]' - Replace [name] with an av you want to delete",
" 'say list' - Shows who is on the All Access list",
" 'change time [time]' - Replace [time] with the number of seconds",
" you want the door to stay open and listen."
];



//TOOL FUNCTIONS
//==============
float debug(string m) // Allows for debug messages
{ // to be easily turned on/off
if (debug_messages)
llSay(0,m);
return TRUE;
}



integer k = FALSE;
//- - - - - - - - - - - - - - - -
float debugList(list l) // List version of the
{ // debug() function
string s = "";
if (debug_messages){
integer i;
for (i = 0; i < llGetListLength(l); i++){
s += llList2String(l,i);
if (i < llGetListLength(l) - 1)
s += ", ";
}
if (s == "";) {
llSay(0,"LIST IS EMPTY";);
}else{
llSay(0,s);
}
}
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer q(){
llSay(0,"This script is provided free of charge.
Please contact Meiyo Sojourner if you paid for it.";);
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer d(){
llSay(0,"This script has been unacceptably modified!
It is now deleting itself.";);
llRemoveInventory(llGetScriptName());
return TRUE;
}
//- - - - - - - - - - - - - - - -
float sayList(list l) // Dumps the contents of
{ // the list into the chat
string s = "";
integer i;
for (i = 0; i < llGetListLength(l); i++){
s += llList2String(l,i);
if (i < llGetListLength(l) - 1)
s += ", ";
}
if (s == "";) {
llSay(0,"LIST IS EMPTY";);
}else{
llSay(0,s);
}
return TRUE;
}
//- - - - - - - - - - - - - - - -
float sayList2(list l) // Dumps the contents of the list
{ // into the chat one line at a time
integer i;
for (i = 0; i < llGetListLength(l); i++){
llSay(0,llList2String(l,i));
}
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer isIn(list test_list, list test_item) // Looks for test_item
{ // in test_list
integer i;
for (i = 0; i < llGetListLength(test_list); i++){
if (llList2String(test_item, 0) == llList2String(test_list, i))
return TRUE;
}
return FALSE;
}
//- - - - - - - - - - - - - - - -
string replace(string main, string old, string new) // Search and replace
{ // function for strings
string temp = "";
list m = llParseString2List(main,["%"],[]);
integer i;
for(i = 0; i < llGetListLength(m); i ++){
string c = llList2String(m,i);
if (c == old){
temp += new;
}else{
temp += c;
}
}
return temp;
}
//- - - - - - - - - - - - - - - -

float stopListening() // Kills the listen function
{ // in order to save resources
if(listen_tag != -1)
llListenRemove(listen_tag);
listen_tag = -1;
return TRUE;
}
//- - - - - - - - - - - - - - - -
float removeName(string target_name) // Searches for and deletes
{ // target_name from auth_list
integer i;
for (i = 0; i < llGetListLength(auth_list); i++){
if (target_name == llList2String(auth_list, i)){
auth_list = llDeleteSubList(auth_list, i, i);
return TRUE;
}
}
return FALSE;
}
//- - - - - - - - - - - - - - - -
integer open(string av_name) // Opens the door.
{
bMove = TRUE;
integer i;
vector basepos = llGetPos();

if (open_sound != "";)
llTriggerSound(open_sound, 0.5);
if (open_message != "";)
llSay(0, replace(open_message,"nn",av_name));
// vv Replace this snippet with custom code to close the door vv

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;
}

return TRUE;
}





//CODE ENTRY
//==========
default
{
state_entry()
{
vBase = llGetPos();
k = q();
llRequestAgentData(llGetOwner(), DATA_NAME);
}


dataserver(key queryid, string data) {
auth_list += data;
llSay(0,"Owner added to Authorized List.";);
if (startup_message != "";)
llSay(0,startup_message);
}


on_rez(integer rez)
{
llResetScript();
}


touch_start(integer total_number)
{
if (!k) d();
list temp = [];
if (!locked){
door_open = open(llDetectedName(0));
listen_tag = llListen(0,"","","";);

} else if (isIn(auth_list, temp += llDetectedName(0))){
debug("authorized";);
door_open = open(llDetectedName(0));
listen_tag = llListen(0,"","","";);

} else {
llSay(0, replace(lock_message,"nn",llDetectedName(0)));

}
debug("TEMP =";);
debugList(temp);
debug("AUTH_LIST = ";);
debugList(auth_list);
}




listen(integer chan, string name, key id, string msg)
{
list temp = [];
if (isIn(auth_list, temp += name)){
list n = llParseString2List(msg, [" "], []);
string cmd_a = llList2String(n, 0);
string cmd_b = llList2String(n, 1);
string cmd_c = llList2String(n, 2);
if (cmd_a == "lock";){
locked = TRUE;
llSay(0,"Door Locked";);
}
if (cmd_a == "unlock";){
locked = FALSE;
llSay(0,"Door Unlocked";);
}
if (cmd_a == "add";){
if ((cmd_b == "";)||(cmd_c == "";)){
llSay(0, "Incorrect Name Format!";);
}else{
temp = [];
string new_name = cmd_b + " " + cmd_c;
if(!isIn(auth_list, temp += new_name)){
auth_list += new_name;
llSay(0, new_name + " added to list.";);
}else{
llSay(0, new_name + " was already on the list.";);
}
}
}
if ((cmd_a == "remove";)||(cmd_a == "delete";)){
if ((cmd_b == "";)||(cmd_c == "";)){
llSay(0, "Incorrect Name Format!";);
}else{
string kill_name = cmd_b + " " + cmd_c;
if (removeName(kill_name)){
llSay(0,"Name Successfully Removed";);
}else{
llSay(0,"Name Not Found!";);
}
}
}
if ((cmd_a == "say";)&&;(cmd_b == "list";)){
sayList(auth_list);
}
if ((cmd_a == "show";)&&;(cmd_b == "help";)){
sayList2(help_message);
}
if ((cmd_a == "change";)&&;(cmd_b == "time";)){
float foo = llList2Float(n, 2);
if (foo < 10){
llSay(0, "Invalid Time Specified!";);
}else{
open_time = foo;
llSay(0, "Open time changed to " + cmd_c + " seconds.";);
}
}}}}
1 2