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_with_timer  

Door_Script_with_timer

Door Script with timer.lsl

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

the Zip file

Download all files for Door_Script_with_timer
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Door_Script_with_timer_1.lsl
1
2 // ==========================================================================
3 // Basic Door Script
4 // Original Script By Unknown
5 // Modifications made by Zanlew Wu 01-Apr-2003
6 //
7 //============================================
8 // Declare global constants.
9 //
10 integer SW_OPEN = FALSE; // used to signify door swinging open
11 integer SW_CLOSE = TRUE; // used to signify door swinging closed
12 integer SW_NORMAL = TRUE; // used to signify a normal swing
13 integer SW_REVERSE = FALSE; // used to signify a reverse swing
14 //
15 // Note that it is hard to call a given swing outward or inward as that has
16 // a lot to do witht he rotation and/or orientation of the door, which
17 // swing direction is correct/desired, and whether you are referring to the
18 // swing from the "out" side of the door or the "in" side of the door. It
19 // was easier by convention to call the swings normal and reverse.
20
21 //============================================
22 // Declare global fields.
23 //
24 key gfOwnerKey; // Owner of the elevator object
25 integer gfDoorClosed; // Current state of the door (Open, Closed)
26 integer gfDoorSwing; // Deteremines which way the door swings (In, Out)
27
28 //============================================
29 // gmInitFields
30 //
31 gmInitFields()
32 {
33 //
34 // Get the owner of the door.
35 //
36 gfOwnerKey = llGetOwner();
37
38 //
39 // Close doors by default.
40 //
41 gfDoorClosed = TRUE;
42
43 //
44 // Set the door swing.
45 //
46 gfDoorSwing = SW_NORMAL;
47
48 return;
49 }
50 //
51 // End of gmInitVars
52 //============================================
53
54 //============================================
55 // gmSwingDoor
56 //
57 gmSwingDoor(integer direction)
58 {
59 //-----------------------
60 // Local variable defines
61 //
62 rotation rot;
63 rotation delta;
64 float piVal;
65
66 //
67 // First thing we need to do is decide whether we are applying a
68 // negative or positive PI value to the door swing algorythm. The
69 // positive or negative makes the difference on which direction the door
70 // swings. Additionally, since we allow the doors to modify their swing
71 // direction (so the same door can be placed for inward or outward
72 // swing, we have to take that into account as well. Best to determine
73 // that value first. The rest of the formula does not change regardless
74 // of door swing direction.
75 //
76 // So we have two variables to pay attention to: open/close and swing
77 // in/out. First we start with open/close. We will presume the
78 // following:
79 // SW_OPEN: +PI
80 // SW_CLOSE: -PI
81 // This also presumes that the door has a standard swing value of
82 // SW_NORMAL.
83 //
84 // A door that has had it's swing changed would have those values
85 // reversed:
86 // SW_OPEN: -PI
87 // SW_CLOSE: +PI
88 //
89 // The variable passed into this method determines if the intent were
90 // to open the door or close it.
91 //
92 // The global field gfDoorSwing will be used to modify the PI based on
93 // whether the door normally swings in or out.
94 //
95 if(direction == SW_OPEN)
96 {
97 //
98 // Ok, we know the door is opening. Assign a +PI value to piVal.
99 //
100 piVal = PI/4;
101 //
102 // Now check to see if the door has it's swing reversed.
103 //
104 if(gfDoorSwing == SW_REVERSE)
105 {
106 //
107 // Yep, it's reversed and we are opening the door, so replace
108 // piVal with a -PI value.
109 //
110 piVal = -PI/4;
111 }
112 } else
113 {
114 //
115 // So we know we are closing the door this time. Assign a -PI value
116 // to piVal.
117 //
118 piVal = -PI/4;
119 //
120 // Now check to see if the door has it's swing reversed.
121 //
122 if(gfDoorSwing == SW_REVERSE)
123 {
124 //
125 // Yep, it's reversed and we are closing the door, so we need to
126 // assing a +PI value to piVal.
127 //
128 piVal = PI/4;
129 }
130 }
131
132 //
133 // This formula was part of the original script and is what makes
134 // the door swing open and closed. This formula use a Pi/-Pi to
135 // move the door one quarter-circle in total distance.
136 //
137 // The only change I've made to this function is to replace the hard-
138 // coded PI/-PI values with a variable that is adjusted
139 // programmatically to suit the operation at hand.
140 //
141 rot = llGetRot();
142 delta = llEuler2Rot(<0,-piVal,0> );
143 rot = delta * rot;
144 llSetRot(rot);
145 llSleep(0.25);
146 rot = delta * rot;
147 llSetRot(rot);
148
149 return;
150 }
151 //
152 // End of gmSwingDoor
153 //============================================
154
155 //============================================
156 // gmCloseDoor
157 //
158 // The close command is used to close doors. If the doors are
159 // locked, the doors cannot be closed. (Note: presumably, this
160 // script does not allow doors to be opened AND locked at the same
161 // time). If the doors are already closed, they cannot be
162 // re-closed. These checks will be made before performing a door
163 // close operation. Once the door is successfully closed, the
164 // door's state will be updated.
165 //
166 gmCloseDoor()
167 {
168 //
169 // First let's check to see if the door is already closed. If it
170 // is, let the user know.
171 //
172 if(gfDoorClosed == TRUE)
173 {
174 //
175 // Yep, it was already closed.
176 //
177 llSay(0, "This door is already closed.");
178 return;
179 }
180
181 //
182 // Now we generate the proper sound for the door closing.
183 //
184 llTriggerSound("open_creaky_door", 0.2);
185
186 //
187 // Now we call the method gmSwingDoor with the SW_CLOSE argument (since
188 // we are closing the door.
189 //
190 gmSwingDoor(SW_CLOSE);
191
192 //
193 // Now that the door is closed, set the door's state.
194 //
195 gfDoorClosed = TRUE;
196
197 return;
198 }
199 //
200 // End of gmCloseDoor
201 //============================================
202
203 //============================================
204 // gmOpenDoor
205 //
206 // The open command is used to open the doors. If the doors are
207 // locked, the doors cannot be opened. If the doors are already
208 // opened, they cannot be re-opened. These checks will be made
209 // before performing a door open operation. Once the door is
210 // successfully opened, the door's state will be updated.
211 //
212 gmOpenDoor()
213 {
214 //
215 // First let's check to see if the door is open already. If it is,
216 // let the user know.
217 //
218 if(gfDoorClosed == FALSE)
219 {
220 //
221 // Yep, it was already open.
222 //
223 llSay(0, "This door is already open.");
224 return;
225 }
226
227 //
228 // Now we generate the proper sound for the door closing.
229 //
230 llTriggerSound("open_creaky_door", 0.2);
231
232 //
233 // Now we call the method gmSwingDoor with the SW_OPEN argument (since
234 // we are opening the door.
235 //
236 gmSwingDoor(SW_OPEN);
237
238 //
239 // Now that the door is opened, set the door's state.
240 //
241 gfDoorClosed = FALSE;
242 return;
243 }
244 //
245 // End of gmOpenDoor
246 //============================================
247
248
249 //============================================
250 // Default State
251 //
252 // This is the state that is automatically bootstrapped when the object
253 // is first created/rez'd, or the world or environment resets.
254 //
255 default
256 {
257 //
258 // state_entry() is the first method executed when the state it resides
259 // in is run. So State A, B, and C all can have state_entry methods,
260 // and if they do, they are run when their respective states are called
261 // and or executed.
262 //
264 {
265 //
266 // Perform global field initialization
267 //
268 gmInitFields();
269
270 //
271 // We are listening for two different commands. This script is set
272 // up to accept spoken commands only from the object owner.
273 //
274 llListen(999, "", "", "");
275
276 }
277
278 //listen(integer channel, string name, key id, string msg)
279 link_message(integer sender_num, integer num, string msg, key id)
280 {
281
282 //llOwnerSay("door heard :" + msg);
283
284 //-----------------------
285 // Local variable defines
286 //
287 string operName;
288 string ownerName;
289
290 //
291 // Ideally, we want the door only to work on spoken commands
292 // from the owner. To accomplish this task, we need to check the
293 // id of the owner and the person issuing the command to see if
294 // they match.
295 //
296 // Alternately, commands can be issued from the control panel,
297 // which can be used by anyone. Later on, it will be presumed that
298 // access to the control panel will be controlled.
299 //
300
301 //
302 // First get the string names of the owner and the operator so they
303 // can be compared.
304 //
305 operName = llKey2Name(id);
306 ownerName = llKey2Name(gfOwnerKey);
307
308
309
310 //----------------------------------------
311 // OPEN DOOR
312 //
313 if(msg == "open")
314 {
315 gmOpenDoor();
316 }
317
318 //----------------------------------------
319 // CLOSE DOOR
320 //
321 if(msg == "close")
322 {
323 gmCloseDoor();
324 }
325 }
326
327 }
328 // END //

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