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  

Timeless_Linked_Door

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

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