Join us in Phaze Demesnes

LSL Script Library Home   Add a script Show All
Category: Contributor: Description
Door Encog Dod AutoDoor
AutoDoor
AutoDoor

Download this script - Please use this link to get this script. If you see all the code on one long line, please use Wordpad or another editor, such as LSLEdit.exe. The .LSL file you will download is an ordinary text file.

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
23 door(integer what)
24 {
25 rotation rot;
26 rotation delta;
27 vector eul;
28
30
31 if ( what == DOOR_OPEN )
32 {
33 llTriggerSound("doorOpen", 1);
34 eul = <0, 0, 90*DIRECTION>; //90 degrees around the z-axis, in Euler form
35
36 } else if ( what == DOOR_CLOSE)
37 {
38 llTriggerSound("doorClose", 1);
39 eul = <0, 0, 90*-DIRECTION>; //90 degrees around the z-axis, in Euler form
40 }
41
42 eul *= DEG_TO_RAD; //convert to radians rotation
43 rot = llGetRot();
44 delta = llEuler2Rot(eul);
45 rot = delta * rot;
46 llSetRot(rot);
47 }
48
49
50 default
51 {
52 on_rez(integer start_param)
53 {
55 }
56
58 {
59 originalPos = llGetPos();
60 llSensorRepeat("", "",AGENT, 5, PI, 1);
61 }
62
63 sensor(integer num_detected)
64 {
65 door(DOOR_OPEN);
66 state open_state;
67 }
68
69 moving_end()
70 {
71 originalPos = llGetPos();
72 }
73 }
74
75 state open_state
76 {
78 {
79 llSensorRepeat("", "",AGENT, 5, PI, 1);
80 }
81
82 no_sensor()
83 {
84 door(DOOR_CLOSE);
85 llSetPos(originalPos);
86 state default;
87 }
88
89 sensor(integer num_detected)
90 {
91 }
92
93
95 {
96 door(DOOR_CLOSE);
97 state default;
98 }
99 }