Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Door Timeless_Linked_Door_Script  

Timeless_Linked_Door_Script

Timeless Linked Door Script.lsl

Category: Door
By : Timeless Prototype
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Timeless_Linked_Door_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Timeless_Linked_Door_Script_1.lsl
1
2
3 //------------------------------------------------------
4 // Timeless Linked Door Script by Timeless Prototype
5 //------------------------------------------------------
6 // The latest version of this script can always be found
7 // in the Library section of the wiki:
8 // http://www.secondlife.com/badgeo/
9 // This script is free to use, but whereever it is used
10 // the SCRIPT's permissions MUST be set to:
11 // [x] Next owner can modify
12 // [x] Next owner can copy
13 // [x] Next owner can transfer
14 // [x] Allow anyone to copy
15 // [x] Share with group
16
17 //------------------------------------------------------
18 // USAGE INSTRUCTIONS FOR EVERYDAY USE:
19 //------------------------------------------------------
20 // Say the following commands on channel 0:
21 // 'unlock' - Unlocks all doors in range.
22 // 'lock' - Locks all doors in range and allows
23 // only the permitted users to open it.
24 // To open the door, either Touch it, Walk into it or
25 // say 'open' or say 'close'.
26
27 //------------------------------------------------------
28 // USAGE INSTRUCTIONS FOR BUILDERS:
29 //------------------------------------------------------
30 // 1. Copy and paste this script into the door prim and
31 // change the settings (see further down).
32 // 2. The door prim must be linked to at least one other
33 // prim (could be linked to the house for example).
34 // 3. The door prim MUST NOT be the root prim.
35 // 4. Use Edit Linked Parts to move, rotate and size the
36 // door prim for the closed state.
37 // 5. When ready, stand close to the door and say
38 // '/door closed' (this records the closed door
39 // position, rotation and size to the object's
40 // name and description).
41 // 6. Use the Edit Linked parts to move, rotate and size
42 // the door prim for the opened state.
43 // 7. When ready, stand close to the door and say
44 // '/door opened' (this records the opened door
45 // position, rotation and size).
46 // 8. Once recorded it will not accept these commands
47 // again. If you do need to redo the settings then
48 // delete the Name and Description of the door prim
49 // (these are where the position information is
50 // stored), and then follow the steps above again.
51 // Note: deleting the object name won't save, so set
52 // the object name to 'Object' to reset the object
53 // name.
54
55 //------------------------------------------------------
56 // Change these settings to suit your needs.
57 //------------------------------------------------------
58 // To mute any/all of the sounds set the sound string(s)
59 // to "" (empty string).
60 // To get the UUID of a sound, right click on the sound
61 // in your inventory and choose "Copy Asset UUID", then
62 // paste the UUID in here.
63 string doorOpenSound = "cb340647-9680-dd5e-49c0-86edfa01b3ac";
64 string doorCloseSound = "e7ff1054-003d-d134-66be-207573f2b535";
65 string confirmedSound = "69743cb2-e509-ed4d-4e52-e697dc13d7ac";
66 string accessDeniedSound = "58da0f9f-42e5-8a8f-ee51-4fac6c247c98";
67 string doorBellSound = "ee871042-e272-d8ec-3d40-0b0cb3371346"; // Setting to empty stops door announcements too.
68 float autoCloseTime = 120.0; // 0 seconds to disable auto close.
69 integer allowGroupToo = TRUE; // Set to FALSE to disallow same group access to door.
70 list allowedAgentUUIDs = ["8efecbac-35de-4f40-89c1-2c772b83cafa"]; // Comma-separated, quoted list of avatar UUIDs who are allowed access to this door.
71 integer listenChannel = 0;
72
73
74 //------------------------------------------------------
75 // Leave the rest of the settings alone, these are
76 // handled by the script itself.
77 //------------------------------------------------------
78 integer isLocked = FALSE; // Only when the door is locked do the permissions apply.
79 integer isOpen = TRUE;
80 vector openPos = ZERO_VECTOR;
81 rotation openRot = ZERO_ROTATION;
82 vector openScale = ZERO_VECTOR;
83 vector closedPos = ZERO_VECTOR;
84 rotation closedRot = ZERO_ROTATION;
85 vector closedScale = ZERO_VECTOR;
86 key openerKey = NULL_KEY;
87 key closerKey = NULL_KEY;
88 integer isSetup = FALSE;
89 integer listenHandle = 0;
90 string avatarName = "";
91
92 mySayName(integer channel, string objectName, string message)
93 {
94 string name = llGetObjectName();
95 llSetObjectName(objectName);
96 llSay(0, "/me " + message);
97 llSetObjectName(name);
98 }
99
100 mySay(integer channel, string message)
101 {
102 string name = llGetObjectName();
103 llSetObjectName("Door");
104 llSay(0, message);
105 llSetObjectName(name);
106 }
107
108 myOwnerSay(string message)
109 {
110 string name = llGetObjectName();
111 llSetObjectName("Door");
112 llOwnerSay(message);
113 llSetObjectName(name);
114 }
115
116 mySoundConfirmed()
117 {
118 if(confirmedSound != "")
119 {
120 llTriggerSound(confirmedSound, 1.0);
121 }
122 }
123
124 mySoundAccessDenied()
125 {
126 if(accessDeniedSound != "")
127 {
128 llTriggerSound(accessDeniedSound, 1.0);
129 }
130 }
131
132 myGetDoorParams()
133 {
134 isSetup = FALSE;
135 if(llSubStringIndex(llGetObjectDesc(), "door;") == 0 && llSubStringIndex(llGetObjectName(), "door;") == 0)
136 {
137 list nameWords = llParseString2List(llGetObjectName(), [";"], []);
138 list descWords = llParseString2List(llGetObjectDesc(), [";"], []);
139 if(llGetListLength(nameWords) != 4 || llGetListLength(descWords) != 4)
140 {
141 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.");
142 }
143 else
144 {
145 openPos = (vector)llList2String(nameWords, 1);
146 openRot = (rotation)llList2String(nameWords, 2);
147 openScale = (vector)llList2String(nameWords, 3);
148 closedPos = (vector)llList2String(descWords, 1);
149 closedRot = (rotation)llList2String(descWords, 2);
150 closedScale = (vector)llList2String(descWords, 3);
151 isSetup = TRUE;
152 }
153 }
154 }
155
156 mySetDoorParams(vector openPos, rotation openRot, vector openScale, vector closedPos, rotation closedRot, vector closedScale)
157 {
158 llSetObjectName("door;" +
159 (string)openPos + ";" +
160 (string)openRot + ";" +
161 (string)openScale);
162 llSetObjectDesc("door;" +
163 (string)closedPos + ";" +
164 (string)closedRot + ";" +
165 (string)closedScale);
166 isSetup = TRUE;
167 }
168
169 integer myPermissionCheck(key id)
170 {
171 integer hasPermission = FALSE;
172 if(isLocked == FALSE)
173 {
174 hasPermission = TRUE;
175 }
177 {
178 hasPermission = TRUE;
179 }
180 else if(allowGroupToo == TRUE && llSameGroup(id))
181 {
182 hasPermission = TRUE;
183 }
184 else if(llListFindList(allowedAgentUUIDs, [(string)id]) != -1)
185 {
186 hasPermission = TRUE;
187 }
188 return hasPermission;
189 }
190
191 myOpenDoor()
192 {
193 isOpen = FALSE;
194 myToggleDoor();
195 }
196
197 myCloseDoor()
198 {
199 isOpen = TRUE;
200 myToggleDoor();
201 }
202
203 myToggleDoor()
204 {
205 if(isSetup == FALSE)
206 {
207 myOwnerSay("The door prim has not been configured yet. Please read the usage instructions in the door script.");
208 }
209 else if(llGetLinkNumber() == 0 || llGetLinkNumber() == 1)
210 {
211 myOwnerSay("The door prim must be linked to at least one other prim and the door prim must not be the root prim");
212 }
213 else
214 {
215 isOpen = !isOpen;
216 if(isOpen)
217 {
218 if(doorBellSound != "")
219 {
220 llTriggerSound(doorBellSound, 1.0);
221 if(avatarName != "")
222 {
223 mySayName(0, avatarName, "is at the door.");
224 avatarName = "";
225 }
226 }
227 if(doorOpenSound != "")
228 {
229 llTriggerSound(doorOpenSound, 1.0);
230 }
232 // Door API.
233 llMessageLinked(LINK_SET, 255, "cmd|door|opened", NULL_KEY);
234 }
235 else
236 {
237 if(doorCloseSound != "")
238 {
239 llTriggerSound(doorCloseSound, 1.0);
240 }
241 llSetPrimitiveParams([ PRIM_POSITION, closedPos, PRIM_ROTATION, ZERO_ROTATION * closedRot / llGetRootRotation(), PRIM_SIZE, closedScale ]);
242 // Door API.
243 llMessageLinked(LINK_SET, 255, "cmd|door|closed", NULL_KEY);
244 }
245
246 llSetTimerEvent(0.0);
247 if(isOpen == TRUE && autoCloseTime != 0.0)
248 {
249 llSetTimerEvent(autoCloseTime);
250 }
251 }
252 }
253
254 default
255 {
257 {
258 listenHandle = llListen(listenChannel, "", NULL_KEY, "");
259 myGetDoorParams();
260 }
261
262 touch_start(integer total_number)
263 {
264 if(myPermissionCheck(llDetectedKey(0)) == TRUE)
265 {
266 avatarName = llDetectedName(0);
267 myToggleDoor();
268 }
269 else
270 {
271 mySoundAccessDenied();
272 }
273 }
274
275 timer()
276 {
277 myCloseDoor();
278 }
279
280 link_message(integer sender_num, integer num, string str, key id)
281 {
282 // Door API. The API is here in case you want to create PIN entry keypads or whatever.
283 if(num == llGetLinkNumber())
284 {
285 if(str == "cmd|door|doOpen")
286 {
287 myOpenDoor();
288 }
289 else if(str == "cmd|door|doClose")
290 {
291 myCloseDoor();
292 }
293 }
294 if(str == "cmd|door|discover")
295 {
296 llMessageLinked(LINK_SET, 255, "cmd|door|discovered|" + (string)llGetKey(), id);
297 }
298 }
299
300 listen(integer channel, string name, key id, string message)
301 {
302 // Performance note: it's quicker to compare the strings than to compare permissions each time anyone says anything on this channel.
303 if(message == "open")
304 {
305 if(myPermissionCheck(id) == TRUE)
306 {
307 // Only open the door if the person is quite close to this door.
308 openerKey = id;
309 closerKey = NULL_KEY;
310 avatarName = name;
311 llSensor(name, id, AGENT, 5.0, TWO_PI);
312 }
313 else
314 {
315 mySoundAccessDenied();
316 }
317 }
318 else if(message == "close")
319 {
320 if(myPermissionCheck(id) == TRUE)
321 {
322 openerKey = NULL_KEY;
323 closerKey = id;
324 avatarName = name;
325 // Only close the door if the person is quite close to this door.
326 llSensor(name, id, AGENT, 5.0, TWO_PI);
327 }
328 else
329 {
330 mySoundAccessDenied();
331 }
332 }
333 else if(message == "lock")
334 {
335 if(myPermissionCheck(id) == TRUE)
336 {
337 isLocked = TRUE;
338 mySoundConfirmed();
339 }
340 else
341 {
342 mySoundAccessDenied();
343 }
344 }
345 else if(message == "unlock")
346 {
347 if(myPermissionCheck(id) == TRUE)
348 {
349 isLocked = FALSE;
350 mySoundConfirmed();
351 }
352 else
353 {
354 mySoundAccessDenied();
355 }
356 }
357 else if(message == "/door opened" && llSubStringIndex(llGetObjectName(), "door;") == -1)
358 {
360 {
361 mySoundConfirmed();
362 openPos = llGetLocalPos();
363 openRot = llGetLocalRot();
364 openScale = llGetScale();
365 isOpen = TRUE;
366 if(! (closedPos == ZERO_VECTOR && closedRot == ZERO_ROTATION && closedScale == ZERO_VECTOR))
367 {
368 mySetDoorParams(openPos, openRot, openScale, closedPos, closedRot, closedScale);
369 }
370 }
371 else
372 {
373 mySoundAccessDenied();
374 }
375 }
376 else if(message == "/door closed" && llSubStringIndex(llGetObjectDesc(), "door;") == -1)
377 {
379 {
380 mySoundConfirmed();
381 closedPos = llGetLocalPos();
382 closedRot = llGetLocalRot();
383 closedScale = llGetScale();
384 isOpen = FALSE;
385 if(! (openPos == ZERO_VECTOR && openRot == ZERO_ROTATION && openScale == ZERO_VECTOR))
386 {
387 mySetDoorParams(openPos, openRot, openScale, closedPos, closedRot, closedScale);
388 }
389 }
390 else
391 {
392 mySoundAccessDenied();
393 }
394 }
395 }
396
397 sensor(integer num_detected)
398 {
399 if(openerKey != NULL_KEY)
400 {
401 integer i;
402 for (i = 0; i < num_detected; i++)
403 {
404 if(llDetectedKey(i) == openerKey && myPermissionCheck(llDetectedKey(i)) == TRUE)
405 {
406 myOpenDoor();
407 }
408 }
409 openerKey = NULL_KEY;
410 }
411 else
412 {
413 integer i;
414 for (i = 0; i < num_detected; i++)
415 {
416 if(llDetectedKey(i) == closerKey && myPermissionCheck(llDetectedKey(i)) == TRUE)
417 {
418 myCloseDoor();
419 }
420 }
421 closerKey = NULL_KEY;
422 }
423 }
424
425 //------------------------------------------------------
426 // Uncomment the following code if you particularly want
427 // collisions to affect the door state.
428 //------------------------------------------------------
429
430 // collision_start(integer num_detected)
431 // {
432 // integer i;
433 // for (i = 0; i < num_detected; i++)
434 // {
435 // if(myPermissionCheck(llDetectedKey(i)) == TRUE)
436 // {
437 // avatarName = llDetectedName(i);
438 // myOpenDoor();
439 // }
441 // {
442 // mySoundAccessDenied();
443 // }
444 // }
445 // }
446
447 } // End of default state and end of script.
448 // END //

Back to the Best Free Tools in Second Life and OpenSim.