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 SmartDoor  

SmartDoor

SmartDoor

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

the Zip file

Download all files for SmartDoor
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. SmartDoor_1.lsl
1 // From the book:
2 //
3 // Scripting Recipes for Second Life
4 // by Jeff Heaton (Encog Dod in SL)
5 // ISBN: 160439000
6 X// Copyright 2007 by Heaton Research, Inc.
7 //
8 // This script may be freely copied and modified so long as this header
9 // remains unmodified.
10 //
11 // For more information about this book visit the following web site:
12 //
13 // http://www.heatonresearch.com/articles/series/22/
14
15 float TIMER_CLOSE = 5.0;
16 integer DIRECTION = -1; // direction door opens in. Either 1 (outwards) or -1 (inwards);
17
18 integer DOOR_OPEN = 1;
19 integer DOOR_CLOSE = 2;
20
21 vector originalPos;
22 string text;
23 list allow;
24
25 door(integer what)
26 {
27 rotation rot;
28 rotation delta;
29 vector eul;
30
32
33 if( what == DOOR_OPEN )
34 {
35 llTriggerSound("doorOpen", 1);
36 eul = <0, 0, 90*DIRECTION>; //90 degrees around the z-axis, in Euler form
37
38 } else if( what == DOOR_CLOSE)
39 {
40 llTriggerSound("doorClose", 1);
41 eul = <0, 0, 90*-DIRECTION>; //90 degrees around the z-axis, in Euler form
42 }
43
44 eul *= DEG_TO_RAD; //convert to radians rotation
45 rot = llGetRot();
46 delta = llEuler2Rot(eul);
47 rot = delta * rot;
48 llSetRot(rot);
49 }
50
51 string pop()
52 {
53 string result;
54 integer i = llSubStringIndex(text, " ");
55
56 if( i!=-1 )
57 {
58 i -=1;
59 result = llGetSubString(text,0,i);
60 text = llGetSubString(text,i+2,-1);
61 return result;
62 }
63 else
64 {
65 result = text;
66 text = "";
67 }
68
69 text = llStringTrim(text, STRING_TRIM);
70 result = llStringTrim(result, STRING_TRIM);
71
72 return result;
73 }
74
75
76 default
77 {
78 on_rez(integer start_param)
79 {
81 }
82
84 {
85 originalPos = llGetPos();
86 llListen(0, "", NULL_KEY, "");
87 }
88
89 touch_start(integer total_number)
90 {
91 key who = llDetectedKey(0);
92 integer shouldOpen = 0;
93
94 if( who==llGetOwner() )
95 shouldOpen = 1;
96
98 if( llListFindList(allow,[name]) != -1 )
99 shouldOpen = 1;
100
101 if( shouldOpen == 1 )
102 {
103 llSay(0,"Hello " + llDetectedName(0) );
104 door(DOOR_OPEN);
105 state open_state;
106 }
107 else
108 {
109 llSay(0,llDetectedName(0) + " is at the door." );
110 llTriggerSound("doorbell", 0.8);
111 }
112 }
113
114 moving_end()
115 {
116 originalPos = llGetPos();
117 }
118
119 listen(integer channel, string name, key id, string message)
120 {
121 if( id==llGetOwner() )
122 {
123
124 text = message;
125 string prefix = llToLower(pop());
126
127 if( prefix=="door" )
128 {
129 string command = pop();
130 if( command=="" )
131 {
132 llSay(0,"I am the smart door!");
133 }
134 else if( command=="clear" )
135 {
136 llSay(0,"Clearing access list.");
137 allow = [];
138 }
139 else if( command=="add" )
140 {
141 if( llStringLength(text)> 0 )
142 {
143 text = llToUpper(text);
144 allow+=[text];
145 llSay(0,"Adding " + text );
146 }
147 else
148 {
149 llSay(0,"You must also specify an avatar when using add.");
150 }
151 }
152 else if( command=="list" )
153 {
154 integer length = llGetListLength(allow);
155 if( length==0 )
156 {
157 llSay(0,"No one, other than my owner, may open me.");
158 }
159 else
160 {
161 integer i;
162 llSay(0,"The following people have access to open me:");
163 for (i = 0; i < length; ++i)
164 {
165 llSay(0,llList2String(allow, i));
166 }
167 }
168 }
169 else
170 {
171 llSay(0,"I did not understand that command, say \"door\" for a list of commands.");
172 }
173 }
174 }
175
176 }
177 }
178
179 state open_state
180 {
182 {
183 llSetTimerEvent(TIMER_CLOSE);
184 }
185
187 {
188 door(DOOR_CLOSE);
189 llSetPos(originalPos);
190 state default;
191 }
192
193 timer()
194 {
195 door(DOOR_CLOSE);
196 llSetPos(originalPos);
197 state default;
198 }
199
201 {
202 door(DOOR_CLOSE);
203 state default;
204 }
205 }

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