0255c6c22cdbe6cdc1fe9a08ddcf7a7ffbe85658
[feisty_meow.git] / huffware / huffotronic_eepaw_knowledge_v60.9 / TL_Door_fredmod_v4.4.lsl
1 
2 // fred huffhines mods:
3 //
4 // took away the universal skeleton key that was lodged in this script.
5 //
6 // stopped considering door's scale; this is not usually needed, plus we were blowing
7 //      past the SL limit on object names.
8 //
9 // moved to only storing a couple digits after the decimal point; this is another
10 //      crucial thing to limit the size of the object name.
11 //
12 // added a "toggle" command that behaves like touch, in that the door will be opened
13 //      or closed based on current state.
14 //
15 // made the sensor distance required before the door will listen to someone into a
16 //      configurable parameter, instead of the woefully tiny, hard-coded 5 meters.
17 //
18 // added debugging flag and switchable logging for debugging mode.
19 //
20 // *original license and author info below...*
21 //
22 // plus, timeless prototype said this about using the script in osgrid and elsewhere:
23 //      "hi, thanks for asking, yes you may use the door script in other grids."
24 //
25 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
26 // do not use it in objects without fully realizing you are implicitly accepting that license.
27 //
28 // more fred huffhines mods: (circa march 2012)
29 //   added PASS_COMMANDS flag, which can be used to pass along any commands we
30 // hear to anyone else on our same channel within the object.
31 //   added stifling of commands heard so they don't get re-sent, causing endless
32 // loops of door openings.
33
34
35 //------------------------------------------------------
36 // Timeless Linked Door Script by Timeless Prototype
37 //------------------------------------------------------
38 // The latest version of this script can always be found
39 // in the Library section of the wiki:
40 // http://www.secondlife.com/badgeo/
41 // This script is free to use, but whereever it is used
42 // the SCRIPT's permissions MUST be set to:
43 // [x] Next owner can modify
44 // [x] Next owner can copy
45 // [x] Next owner can transfer
46 // [x] Allow anyone to copy
47 // [x] Share with group
48
49 //------------------------------------------------------
50 // USAGE INSTRUCTIONS FOR EVERYDAY USE:
51 //------------------------------------------------------
52 // Say the following commands on channel 0:
53 // 'unlock'     - Unlocks all doors in range.
54 // 'lock'       - Locks all doors in range and allows
55 //                only the permitted users to open it.
56 // To open the door, either Touch it, Walk into it or
57 // say 'open' or say 'close'.
58
59 //------------------------------------------------------
60 // USAGE INSTRUCTIONS FOR BUILDERS:
61 //------------------------------------------------------
62 // 1. Copy and paste this script into the door prim and
63 //    change the settings (see further down).
64 // 2. The door prim must be linked to at least one other
65 //    prim (could be linked to the house for example).
66 // 3. The door prim MUST NOT be the root prim.
67 // 4. Use Edit Linked Parts to move, rotate and size the
68 //    door prim for the closed state.
69 // 5. When ready, stand close to the door and say
70 //    '/door closed' (this records the closed door
71 //    position, rotation and size to the object's
72 //    name and description).
73 // 6. Use the Edit Linked parts to move, rotate and size
74 //    the door prim for the opened state.
75 // 7. When ready, stand close to the door and say
76 //    '/door opened' (this records the opened door
77 //    position, rotation and size).
78 // 8. Once recorded it will not accept these commands
79 //    again. If you do need to redo the settings then
80 //    delete the Name and Description of the door prim
81 //    (these are where the position information is
82 //    stored), and then follow the steps above again.
83 //    Note: deleting the object name won't save, so set
84 //    the object name to 'Object' to reset the object
85 //    name.
86
87 //------------------------------------------------------
88 // Change these settings to suit your needs.
89 //------------------------------------------------------
90 // To mute any/all of the sounds set the sound string(s)
91 // to "" (empty string).
92 // To get the UUID of a sound, right click on the sound
93 // in your inventory and choose "Copy Asset UUID", then
94 // paste the UUID in here.
95 string      doorOpenSound       = "Door open";
96 string      doorCloseSound      = "Door close";
97 string      confirmedSound      = "69743cb2-e509-ed4d-4e52-e697dc13d7ac";
98 string      accessDeniedSound   = "58da0f9f-42e5-8a8f-ee51-4fac6c247c98";
99 string      doorBellSound       = ""; // Setting to empty stops door announcements too.
100 float       autoCloseTime       = 120.0; // 0 seconds to disable auto close.
101 integer     allowGroupToo       = TRUE; // Set to FALSE to disallow same group access to door.
102 list        allowedAgentUUIDs   = []; // Comma-separated, quoted list of avatar UUIDs who are allowed access to this door.
103 // was allowing this sneaky guy: "8efecbac-35de-4f40-89c1-2c772b83cafa"
104 integer     listenChannel       = 10106;
105 float       RESPONSE_DISTANCE   = 120.0;  // how far to allow a command from users with permission.
106 integer     DEBUGGING           = FALSE;
107 integer     PASS_COMMANDS       = TRUE;
108     // if true, then we will order other doors to open when we do.
109     // we use the listenChannel as the id to pass commands on, so that only the doors listening to
110     // the same place will hear our commands.
111 integer     command_is_a_response  = FALSE;
112     // if this is true, then the door open and close must not re-echo their actions.
113
114 //------------------------------------------------------
115 // Leave the rest of the settings alone, these are
116 // handled by the script itself.
117 //------------------------------------------------------
118 integer     isLocked            = FALSE; // Only when the door is locked do the permissions apply.
119 integer     isOpen              = TRUE;
120 vector      openPos             = ZERO_VECTOR;
121 rotation    openRot             = ZERO_ROTATION;
122 vector      closedPos           = ZERO_VECTOR;
123 rotation    closedRot           = ZERO_ROTATION;
124 key         openerKey           = NULL_KEY;
125 key         closerKey           = NULL_KEY;
126 integer     isSetup             = FALSE;
127 integer     listenHandle        = 0;
128 string      avatarName          = "";
129
130 // zooms the sub-prim to a new rotation and position.
131 jump_to_position(vector position, rotation new_rot)
132 {
133     list config_blast = [ 
134         PRIM_SIZE, llGetScale(), ///????
135         // first jump away from where we started, trying to get past an opensim bug.
136 //        PRIM_POSITION, ZERO_VECTOR,
137 //        PRIM_POSITION, ZERO_VECTOR,
138 //        PRIM_POSITION, ZERO_VECTOR,
139 //        PRIM_POSITION, ZERO_VECTOR,
140 //        PRIM_POSITION, ZERO_VECTOR,
141         PRIM_ROTATION, ZERO_ROTATION * new_rot / llGetRootRotation(),
142 //        PRIM_POSITION, position,
143 //        PRIM_POSITION, position,
144 //        PRIM_POSITION, position,
145 //        PRIM_POSITION, position,
146 //        PRIM_POSITION, position,
147         PRIM_POSITION, position
148         ];
149     llSetLinkPrimitiveParams(llGetLinkNumber(), config_blast);
150 if (DEBUGGING) llOwnerSay("want pos=" + (string)position + ", got=" + (string)llGetLocalPos()
151 + ", and want rot=" + (string)new_rot + ", got=" + (string)llGetLocalRot());
152 }
153
154 mySayName(integer channel, string objectName, string message)
155 {
156     string name = llGetObjectName();
157     llSetObjectName(objectName);
158     llSay(0, "/me " + message);
159     llSetObjectName(name);
160 }
161
162 mySay(integer channel, string message)
163 {
164     string name = llGetObjectName();
165     llSetObjectName("Door");
166     llSay(0, message);
167     llSetObjectName(name);
168 }
169
170 myOwnerSay(string message)
171 {
172     string name = llGetObjectName();
173     llSetObjectName("Door");
174     llOwnerSay(message);
175     llSetObjectName(name);
176 }
177
178 mySoundConfirmed()
179 {
180     if (confirmedSound != "")
181     {
182         llTriggerSound(confirmedSound, 1.0);
183     }
184 }
185
186 mySoundAccessDenied()
187 {
188     if (accessDeniedSound != "")
189     {
190         llTriggerSound(accessDeniedSound, 1.0);
191     }
192 }
193
194 myGetDoorParams()
195 {
196     isSetup = FALSE;
197     if (llSubStringIndex(llGetObjectDesc(), "D;") == 0 && llSubStringIndex(llGetObjectName(), "D;") == 0)
198     {
199         list nameWords = llParseString2List(llGetObjectName(), [";"], []);
200         list descWords = llParseString2List(llGetObjectDesc(), [";"], []);
201         if (llGetListLength(nameWords) != 3 || llGetListLength(descWords) != 3)
202         {
203             myOwnerSay("The door prim's name and/or description has invalid syntax and/or number of parameters. Delete the door prim's name and description and setup the door prim again.");
204         }
205         else
206         {
207             openPos = (vector)llList2String(nameWords, 1);
208             openRot = (rotation)llList2String(nameWords, 2);
209             closedPos = (vector)llList2String(descWords, 1);
210             closedRot = (rotation)llList2String(descWords, 2);
211             isSetup = TRUE;
212         }
213 //llSay(0, "got open pos=" + (string)(openPos) + " rot=" + (string)(openRot));
214 //llSay(0, "got close pos=" + (string)(closedPos) + " rot=" + (string)(closedRot));
215         
216     }
217 }
218
219 // if open_state is true, the parms are for an open door.
220 mySetDoorParams(integer open_state, vector Pos, rotation Rot)
221 {
222     if (open_state) {
223         // parms for open state.
224         llSetObjectName("D;" + vector_chop(Pos) + ";" + rotation_chop(Rot));
225     } else {
226         // parms for closed state.
227         llSetObjectDesc("D;" + vector_chop(Pos) + ";" + rotation_chop(Rot));
228     }
229     isSetup = TRUE;
230 }
231
232 integer myPermissionCheck(key id)
233 {
234     integer hasPermission = FALSE;
235     if (isLocked == FALSE) {
236         if (DEBUGGING) llOwnerSay("perm--unlocked: okay");
237         hasPermission = TRUE;
238     } else if (llGetOwnerKey(id) == llGetOwner()) {
239         if (DEBUGGING) llOwnerSay("perm--is owner: okay");
240         hasPermission = TRUE;
241     } else if (allowGroupToo == TRUE && llSameGroup(id)) {
242         if (DEBUGGING) llOwnerSay("perm--same group: okay");
243         hasPermission = TRUE;
244     } else if (llListFindList(allowedAgentUUIDs, [(string)id]) != -1) {
245         if (DEBUGGING) llOwnerSay("perm--in list: okay");
246         hasPermission = TRUE;
247     } else {
248         if (DEBUGGING) llOwnerSay("perm--not found anywhere: bad perms");
249     }
250     return hasPermission;
251 }
252
253 myOpenDoor()
254 {
255     isOpen = FALSE;
256     myToggleDoor();
257 }
258
259 myCloseDoor()
260 {
261     isOpen = TRUE;
262     myToggleDoor();
263 }
264
265 myToggleDoor()
266 {
267     if (isSetup == FALSE)
268     {
269         myOwnerSay("The door prim has not been configured yet. Please read the usage instructions in the door script.");
270     }
271     else if (llGetLinkNumber() == 0 || llGetLinkNumber() == 1)
272     {
273         myOwnerSay("The door prim must be linked to at least one other prim and the door prim must not be the root prim");
274     }
275     else
276     {
277         isOpen = !isOpen;
278 if (DEBUGGING) llOwnerSay("door open state is now=" + (string)isOpen);
279         if (isOpen)
280         {
281 if (DEBUGGING) llOwnerSay("opening the door.");
282             if (doorBellSound != "")
283             {
284                 llTriggerSound(doorBellSound, 1.0);
285                 if (avatarName != "")
286                 {
287                     mySayName(0, avatarName, "is at the door.");
288                     avatarName = "";
289                 }
290             }
291             if (doorOpenSound != "")
292             {
293                 llTriggerSound(doorOpenSound, 1.0);
294             }
295             jump_to_position(openPos, openRot);
296 //            list config_blast = [ PRIM_POSITION, llGetLocalPos() + <4, 4, 4>,
297 //                PRIM_ROTATION, ZERO_ROTATION * openRot / llGetRootRotation(),
298 //                PRIM_POSITION, openPos
299 ////                PRIM_SIZE, llGetScale() 
300 //                ];
301 //            llSetPrimitiveParams(config_blast);
302 //if (DEBUGGING) llOwnerSay("want pos=" + (string)openPos + ", got=" + (string)llGetLocalPos()
303 //+ ", and want rot=" + (string)openRot + ", got=" + (string)llGetLocalRot());
304
305             if (PASS_COMMANDS && !command_is_a_response) {
306                 // Door API.
307                 llMessageLinked(LINK_SET, listenChannel, "cmd|door|open", llGetKey());
308             }
309             command_is_a_response = FALSE;  // took care of that one.
310         }
311         else
312         {
313 if (DEBUGGING) llOwnerSay("closing the door.");
314             if (doorCloseSound != "")
315             {
316                 llTriggerSound(doorCloseSound, 1.0);
317             }
318             jump_to_position(closedPos, closedRot);
319 //            list config_blast = [ 
320 //                PRIM_ROTATION, ZERO_ROTATION * closedRot / llGetRootRotation(),
321 //                PRIM_POSITION, closedPos
322 ////                PRIM_SIZE, llGetScale()
323 //                ];
324 //            llSetPrimitiveParams(config_blast);
325 //if (DEBUGGING) llOwnerSay("want pos=" + (string)closedPos + ", got=" + (string)llGetLocalPos()
326 //+ ", and want rot=" + (string)closedRot + ", got=" + (string)llGetLocalRot());
327             if (PASS_COMMANDS && !command_is_a_response) {
328                 // Door API.
329                 llMessageLinked(LINK_SET, listenChannel, "cmd|door|close", llGetKey());
330             }
331             command_is_a_response = FALSE;  // took care of that one.
332         }
333         
334         llSetTimerEvent(0.0);
335         if (isOpen == TRUE && autoCloseTime != 0.0)
336         {
337             llSetTimerEvent(autoCloseTime);
338         }
339     }
340 }
341
342 //////////////
343 // from hufflets...
344
345 // returns the index of the first occurrence of "pattern" inside
346 // the "full_string".  if it is not found, then a negative number is returned.
347 integer find_substring(string full_string, string pattern)
348 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
349
350 // returns text for a floating point number, but includes only
351 // three digits after the decimal point.
352 string float_chop(float to_show)
353 {
354     integer mant = llAbs(llRound(to_show * 1000.0) / 1000);
355     string neg_sign;
356     if (to_show < 0.0) neg_sign = "-";
357     string dec_s = (string)((llRound(to_show * 1000.0) - mant * 1000) / 1000.0);
358     dec_s = llGetSubString(llGetSubString(dec_s, find_substring(dec_s, ".") + 1, -1), 0, 2);
359     // strip off all trailing zeros.
360     while (llGetSubString(dec_s, -1, -1) == "0")
361         dec_s = llDeleteSubString(dec_s, -1, -1);
362     string to_return = neg_sign + (string)mant;
363     if (llStringLength(dec_s)) to_return += "." + dec_s;
364     return to_return;
365 }
366
367 // returns a prettier form for vector text, with chopped floats.
368 string vector_chop(vector to_show)
369 {
370     return "<" + float_chop(to_show.x) + ","
371         + float_chop(to_show.y) + ","
372         + float_chop(to_show.z) + ">";
373 }
374
375 // similarly, for a rotation.
376 string rotation_chop(rotation to_show)
377 {
378     return "<" + float_chop(to_show.x) + ","
379         + float_chop(to_show.y) + ","
380         + float_chop(to_show.z) + ","
381         + float_chop(to_show.s) + ">";
382 }
383
384 //////////////
385 // huffware script: auto-retire, by fred huffhines, version 2.5.
386 // distributed under BSD-like license.
387 //   !!  keep in mind that this code must be *copied* into another
388 //   !!  script that you wish to add auto-retirement capability to.
389 // when a script has auto_retire in it, it can be dropped into an
390 // object and the most recent version of the script will destroy
391 // all older versions.
392 //
393 // the version numbers are embedded into the script names themselves.
394 // the notation for versions uses a letter 'v', followed by two numbers
395 // in the form "major.minor".
396 // major and minor versions are implicitly considered as a floating point
397 // number that increases with each newer version of the script.  thus,
398 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
399 // and "hazmap v3.2" is a more recent version.
400 //
401 // example usage of the auto-retirement script:
402 //     default {
403 //         state_entry() {
404 //            auto_retire();  // make sure newest addition is only version of script.
405 //        }
406 //     }
407 // this script is partly based on the self-upgrading scripts from markov brodsky
408 // and jippen faddoul.
409 //////////////
410 auto_retire() {
411     string self = llGetScriptName();  // the name of this script.
412     list split = compute_basename_and_version(self);
413     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
414     string basename = llList2String(split, 0);  // script name with no version attached.
415     string version_string = llList2String(split, 1);  // the version found.
416     integer posn;
417     // find any scripts that match the basename.  they are variants of this script.
418     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
419 //log_it("invpo=" + (string)posn);
420         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
421         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
422             // found a basic match at least.
423             list inv_split = compute_basename_and_version(curr_script);
424             if (llGetListLength(inv_split) == 2) {
425                 // see if this script is more ancient.
426                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
427                 // must make sure that the retiring script is completely the identical basename;
428                 // just matching in the front doesn't make it a relative.
429                 if ( (llList2String(inv_split, 0) == basename)
430                     && ((float)inv_version_string < (float)version_string) ) {
431                     // remove script with same name from inventory that has inferior version.
432                     llRemoveInventory(curr_script);
433                 }
434             }
435         }
436     }
437 }
438 //
439 // separates the base script name and version number.  used by auto_retire.
440 list compute_basename_and_version(string to_chop_up)
441 {
442     // minimum script name is 2 characters plus a version.
443     integer space_v_posn;
444     // find the last useful space and 'v' combo.
445     for (space_v_posn = llStringLength(to_chop_up) - 3;
446         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
447         space_v_posn--) {
448         // look for space and v but do nothing else.
449 //log_it("pos=" + (string)space_v_posn);
450     }
451     if (space_v_posn < 2) return [];  // no space found.
452 //log_it("space v@" + (string)space_v_posn);
453     // now we zoom through the stuff after our beloved v character and find any evil
454     // space characters, which are most likely from SL having found a duplicate item
455     // name and not so helpfully renamed it for us.
456     integer indy;
457     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
458 //log_it("indy=" + (string)space_v_posn);
459         if (llGetSubString(to_chop_up, indy, indy) == " ") {
460             // found one; zap it.  since we're going backwards we don't need to
461             // adjust the loop at all.
462             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
463 //log_it("saw case of previously redundant item, aieee.  flattened: " + to_chop_up);
464         }
465     }
466     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
467     // ditch the space character for our numerical check.
468     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
469     // strip out a 'v' if there is one.
470     if (llGetSubString(chop_suffix, 0, 0) == "v")
471         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
472     // if valid floating point number and greater than zero, that works for our version.
473     string basename = to_chop_up;  // script name with no version attached.
474     if ((float)chop_suffix > 0.0) {
475         // this is a big success right here.
476         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
477         return [ basename, chop_suffix ];
478     }
479     // seems like we found nothing useful.
480     return [];
481 }
482 //
483 //////////////
484
485 default
486 {
487     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
488     on_rez(integer parm) { state rerun; }
489 }
490 state rerun { state_entry() { state default; } }
491
492 state real_default
493 {
494     state_entry()
495     {
496         auto_retire();
497         listenHandle = llListen(listenChannel, "", NULL_KEY, "");
498         myGetDoorParams();
499         myCloseDoor();
500     }
501     
502     on_rez(integer parm) { llResetScript(); }
503
504     touch_start(integer total_number)
505     {
506         command_is_a_response = FALSE;
507         if (myPermissionCheck(llDetectedKey(0)) == TRUE)
508         {
509             avatarName = llDetectedName(0);
510             myToggleDoor();
511         }
512         else
513         {
514             mySoundAccessDenied();
515         }
516     }
517     
518     timer()
519     {
520         myCloseDoor();
521     }
522     
523     link_message(integer sender_num, integer num, string str, key id)
524     {
525         // Door API. The API is here in case you want to create PIN entry keypads or whatever.
526         if (num == listenChannel) {
527             if (id == llGetKey()) return;  // don't listen to our own commands.
528             command_is_a_response = TRUE;
529             if (str == "cmd|door|open") myOpenDoor();
530             else if (str == "cmd|door|close") myCloseDoor();
531             else if (str == "cmd|door|discover")
532                 llMessageLinked(LINK_SET, listenChannel, "cmd|door|discovered|" + (string)llGetKey(),
533                     llGetKey());
534             else command_is_a_response = FALSE;
535 //hmmm: above protocol seems redundant, but sending back the original id (like this did before)
536 //      in the id field does not fit in with our usual schemes very well.
537         }
538     }
539     
540     listen(integer channel, string name, key id, string message)
541     {
542 //        if (DEBUGGING) llOwnerSay("heard: " + message);
543         command_is_a_response = FALSE;  // don't get involved with the link message checking.
544
545         // Performance note: it's quicker to compare the strings than to compare permissions each time anyone says anything on this channel.
546         if (message == "open")
547         {
548             if (myPermissionCheck(id) == TRUE)
549             {
550                 // Only open the door if the person is quite close to this door.
551                 openerKey = id;
552                 closerKey = NULL_KEY;
553                 avatarName = name;
554                 llSensor(name, id, AGENT, RESPONSE_DISTANCE, TWO_PI);
555             }
556             else
557             {
558                 mySoundAccessDenied();
559             }
560         }
561         else if (message == "close")
562         {
563             if (myPermissionCheck(id) == TRUE)
564             {
565                 openerKey = NULL_KEY;
566                 closerKey = id;
567                 avatarName = name;
568                 // Only close the door if the person is quite close to this door.
569                 llSensor(name, id, AGENT, RESPONSE_DISTANCE, TWO_PI);
570             }
571             else
572             {
573                 mySoundAccessDenied();
574             }
575         }
576         else if (message == "lock")
577         {
578             if (myPermissionCheck(id) == TRUE)
579             {
580                 isLocked = TRUE;
581                 mySoundConfirmed();
582             }
583             else
584             {
585                 mySoundAccessDenied();
586             }
587         }
588         else if (message == "unlock")
589         {
590             if (myPermissionCheck(id) == TRUE)
591             {
592                 isLocked = FALSE;
593                 mySoundConfirmed();
594             }
595             else
596             {
597                 mySoundAccessDenied();
598             }
599         }
600         else if (message == "toggle")
601         {
602             if (myPermissionCheck(id) == TRUE)
603             {
604                 avatarName = name;
605                 myToggleDoor();
606             }
607             else
608             {
609                 mySoundAccessDenied();
610             }
611         }
612         else if (message == "/door opened" && llSubStringIndex(llGetObjectName(), "D;") == -1)
613         {
614             if (llGetOwnerKey(id) == llGetOwner())
615             {
616                 mySoundConfirmed();
617                 openPos = llGetLocalPos();
618                 openRot = llGetLocalRot();
619                 isOpen = TRUE;
620                 mySetDoorParams(TRUE, openPos, openRot);
621 //llSay(0, "set open pos=" + (string)(openPos) + " rot=" + (string)(openRot));
622             }
623             else
624             {
625                 mySoundAccessDenied();
626             }
627         }
628         else if (message == "/door closed" && llSubStringIndex(llGetObjectDesc(), "D;") == -1)
629         {
630             if (llGetOwnerKey(id) == llGetOwner())
631             {
632                 mySoundConfirmed();
633                 closedPos = llGetLocalPos();
634                 closedRot = llGetLocalRot();
635                 isOpen = FALSE;
636                 mySetDoorParams(FALSE, closedPos, closedRot);
637 //llSay(0, "set close pos=" + (string)(closedPos) + " rot=" + (string)(closedRot));
638             }
639             else
640             {
641                 mySoundAccessDenied();
642             }
643         }
644     }
645     
646     sensor(integer num_detected)
647     {
648         if (openerKey != NULL_KEY)
649         {
650             integer i;
651             for (i = 0; i < num_detected; i++)
652             {
653                 if (llDetectedKey(i) == openerKey && myPermissionCheck(llDetectedKey(i)) == TRUE)
654                 {
655                     myOpenDoor();
656                 }
657             }
658             openerKey = NULL_KEY;
659         }
660         else
661         {
662             integer i;
663             for (i = 0; i < num_detected; i++)
664             {
665                 if (llDetectedKey(i) == closerKey && myPermissionCheck(llDetectedKey(i)) == TRUE)
666                 {
667                     myCloseDoor();
668                 }
669             }
670             closerKey = NULL_KEY;
671         }
672     }
673
674 //------------------------------------------------------
675 // Uncomment the following code if you particularly want
676 // collisions to affect the door state.    
677 //------------------------------------------------------
678
679 //    collision_start(integer num_detected)
680 //    {
681 //        integer i;
682 //        for (i = 0; i < num_detected; i++)
683 //        {
684 //            if (myPermissionCheck(llDetectedKey(i)) == TRUE)
685 //            {
686 //                avatarName = llDetectedName(i);
687 //                myOpenDoor();
688 //            }
689 //            else if (llDetectedType(i) & AGENT)
690 //            {
691 //                mySoundAccessDenied();
692 //            }
693 //        }
694 //    }
695
696 }
697