Join us in Phaze Demesnes

LSL Script Library Home   Add a script Show All
Category: Contributor: Description
Door Anonymous door Locking.lsl
Door Lock 
door Locking.lsl

Download this script - Please use this link to get this script. If you see all the code on one long line, please use Wordpad or another editor, such as LSLEdit.exe. The .LSL file you will download is an ordinary text file.

1 // CATEGORY:Door
2 // DESCRIPTION:Door Lock
3 // ARCHIVED BY:Ferd Frederix
4
5
6
7 //GLOBALS
8 //=======
9 // For the messages, use %nn% in place of the name
10 // of the av that clicked on the door.
11 // Set the variable to "" to disable the message.
12 string startup_message =
13 "Touch door and say 'show help' in the chat for a list of commands";
14 string open_message = "%nn% is at the door.";
15 string close_message = "";
16 string lock_message = "Sorry %nn%, this door is locked";
17 float open_time = 30.0;
18 string open_sound = "Door open"; // These can be set to ""
19 string close_sound = "Door close"; // to disable the sounds.
20 integer debug_messages = FALSE;
21 //- - - - - - - - - - - - - - - -
22 list auth_list = [];
23 integer door_open = FALSE;
24 integer locked = FALSE;
25 integer listen_tag = 1;
26 float interval = 0.0;
27 list help_message = [
28 "Multi user lockable Door Commands List",
29 " 'show help' - Displays this menu",
30 " 'lock' - locks the door to everyone not on the admit list",
31 " 'unlock' - Unlocks the door",
32 " 'add [name]' - Replace [name] with the av you want to add to the list",
33 " 'remove [name]' - Replace [name] with an av you want to delete",
34 " 'say list' - Shows who is on the All Access list",
35 " 'change time [time]' - Replace [time] with the number of seconds",
36 " you want the door to stay open and listen."
37 ];
38
39
40 //TOOL FUNCTIONS
41 //==============
42 float debug(string m) // Allows for debug messages
43 { // to be easily turned on/off
44 if (debug_messages)
45 llSay(0,m);
46 return TRUE;
47 }
48 integer k = FALSE;
49 //- - - - - - - - - - - - - - - -
50 float debugList(list l) // List version of the
51 { // debug() function
52 string s = "";
53 if (debug_messages){
55 for (i = 0; i < llGetListLength(l); i++){
56 s += llList2String(l,i);
57 if (i < llGetListLength(l) - 1)
58 s += ", ";
59 }
60 if (s == "") {
61 llSay(0,"LIST IS EMPTY");
62 }else{
63 llSay(0,s);
64 }
65 }
66 return TRUE;
67 }
68 //- - - - - - - - - - - - - - - -
69 integer q(){
70 llSay(0,"");
71 return TRUE;
72 }
73 //- - - - - - - - - - - - - - - -
74 integer d(){
75 llSay(0,"");
76 return TRUE;
77 }
78 //- - - - - - - - - - - - - - - -
79 float sayList(list l) // Dumps the contents of
80 { // the list into the chat
81 string s = "";
83 for (i = 0; i < llGetListLength(l); i++){
84 s += llList2String(l,i);
85 if (i < llGetListLength(l) - 1)
86 s += ", ";
87 }
88 if (s == "") {
89 llSay(0,"LIST IS EMPTY");
90 }else{
91 llSay(0,s);
92 }
93 return TRUE;
94 }
95 //- - - - - - - - - - - - - - - -
96 float sayList2(list l) // Dumps the contents of the list
97 { // into the chat one line at a time
99 for (i = 0; i < llGetListLength(l); i++){
100 llSay(0,llList2String(l,i));
101 }
102 return TRUE;
103 }
104 //- - - - - - - - - - - - - - - -
105 integer isIn(list test_list, list test_item) // Looks for test_item
106 { // in test_list
108 for (i = 0; i < llGetListLength(test_list); i++){
109 if (llList2String(test_item, 0) == llList2String(test_list, i))
110 return TRUE;
111 }
112 return FALSE;
113 }
114 //- - - - - - - - - - - - - - - -
115 string replace(string main, string old, string new) // Search and replace
116 { // function for strings
117 string temp = "";
118 list m = llParseString2List(main,["%"],[]);
119 integer i;
120 for(i = 0; i < llGetListLength(m); i ++){
122 if (c == old){
123 temp += new;
124 }else{
125 temp += c;
126 }
127 }
128 return temp;
129 }
130 //- - - - - - - - - - - - - - - -
131
132 float stopListening() // Kills the listen function
133 { // in order to save resources
134 if(listen_tag != -1)
135 llListenRemove(listen_tag);
136 listen_tag = -1;
137 return TRUE;
138 }
139 //- - - - - - - - - - - - - - - -
140 float removeName(string target_name) // Searches for and deletes
141 { // target_name from auth_list
143 for (i = 0; i < llGetListLength(auth_list); i++){
144 if (target_name == llList2String(auth_list, i)){
145 auth_list = llDeleteSubList(auth_list, i, i);
146 return TRUE;
147 }
148 }
149 return FALSE;
150 }
151 //- - - - - - - - - - - - - - - -
152 integer open(string av_name) // Opens the door.
153 {
154 if (open_sound != "")
155 llTriggerSound(open_sound, 0.5);
156 if (open_message != "")
157 llSay(0, replace(open_message,"nn",av_name));
158 // vv Replace this snippet with custom code to close the door vv
159 rotation rot = llGetRot();
160 rotation delta = llEuler2Rot(<0,0,PI/4>);
161 rot = delta * rot;
162 llSetRot(rot);
163 llSleep(0.25);
164 rot = delta * rot;
165 llSetRot(rot);
166 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
167 return TRUE;
168 }
169 //- - - - - - - - - - - - - - - -
170 integer close(string av_name) // Closes the door.
171 {
172 if (close_sound != "")
173 llTriggerSound(close_sound, 0.5);
174 if (close_message != "")
175 llSay(0, replace(close_message,"nn",av_name));
176 // vv Replace this snippet with custom code to close the door vv
177 rotation rot = llGetRot();
178 rotation delta = llEuler2Rot(<0,0,-PI/4>);
179 rot = delta * rot;
180 llSetRot(rot);
181 llSleep(0.25);
182 rot = delta * rot;
183 llSetRot(rot);
184 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
185 return FALSE;
186 }
187 //- - - - - - - - - - - - - - - -
188
189
190
191
192 //CODE ENTRY
193 //==========
194 default
195 {
197 {
198 k = q();
200 }
201
202
203 dataserver(key queryid, string data) {
204 auth_list += data;
205 llSay(0,"Owner added to Authorized List.");
206 if (startup_message != "")
207 llSay(0,startup_message);
208 }
209
210
212 {
214 }
215
216
217 touch_start(integer total_number)
218 {
219 if (!k) d();
220 list temp = [];
221 if (!door_open){
222 if (!locked){
223 door_open = open(llDetectedName(0));
224 listen_tag = llListen(0,"","","");
225 llSetTimerEvent(open_time);
226 } else if (isIn(auth_list, temp += llDetectedName(0))){
227 debug("authorized");
228 door_open = open(llDetectedName(0));
229 listen_tag = llListen(0,"","","");
230 llSetTimerEvent(open_time);
231 } else {
232 llSay(0, replace(lock_message,"nn",llDetectedName(0)));
233 }
234 } else {
235 door_open = close(llDetectedName(0));
236 }
237 debug("TEMP =");
238 debugList(temp);
239 debug("AUTH_LIST = ");
240 debugList(auth_list);
241 }
242
243
244 timer()
245 {
246 stopListening();
247 if (door_open){
248 door_open = close("the script");
249 }
250 }
251
252
254 {
255 list temp = [];
256 if (isIn(auth_list, temp += name)){
257 list n = llParseString2List(msg, [" "], []);
258 string cmd_a = llList2String(n, 0);
259 string cmd_b = llList2String(n, 1);
260 string cmd_c = llList2String(n, 2);
261 if (cmd_a == "lock"){
262 locked = TRUE;
263 llSay(0,"Door Locked");
264 }
265 if (cmd_a == "unlock"){
266 locked = FALSE;
267 llSay(0,"Door Unlocked");
268 }
269 if (cmd_a == "add"){
270 if ((cmd_b == "")||(cmd_c == "")){
271 llSay(0, "Incorrect Name Format!");
272 }else{
273 temp = [];
274 string new_name = cmd_b + " " + cmd_c;
275 if(!isIn(auth_list, temp += new_name)){
276 auth_list += new_name;
277 llSay(0, new_name + " added to list.");
278 }else{
279 llSay(0, new_name + " was already on the list.");
280 }
281 }
282 }
283 if ((cmd_a == "remove")||(cmd_a == "delete")){
284 if ((cmd_b == "")||(cmd_c == "")){
285 llSay(0, "Incorrect Name Format!");
286 }else{
287 string kill_name = cmd_b + " " + cmd_c;
288 if (removeName(kill_name)){
289 llSay(0,"Name Successfully Removed");
290 }else{
291 llSay(0,"Name Not Found!");
292 }
293 }
294 }
295 if ((cmd_a == "say")&&(cmd_b == "list")){
296 sayList(auth_list);
297 }
298 if ((cmd_a == "show")&&(cmd_b == "help")){
299 sayList2(help_message);
300 }
301 if ((cmd_a == "change")&&(cmd_b == "time")){
302 float foo = llList2Float(n, 2);
303 if (foo < 10){
304 llSay(0, "Invalid Time Specified!");
305 }else{
306 open_time = foo;
307 llSay(0, "Open time changed to " + cmd_c + " seconds.");
308 }
309 }
310 }
311 }
312 }// END //