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 Door_Script_for_linked_Objects_with  

Door_Script_for_linked_Objects_with

This has an API so you can put a PIN number in the door to control access or as the script says "whatever".

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

the Zip file

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

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