Swing Door Opener BRIGADOON-0006
This script controls the opening and closing of a door (or window)
Loading...
Searching...
No Matches
swing_door_open.lsl
Go to the documentation of this file.
1/* \file swing_door_opener.lsl
2 * \version 1.0
3 * \date
4 * This script is designed to run in the Open Simulator (or Second Life) environment. The door/window
5 * can be opened or closed by touch, or by remote control from the door_window_state.lsl script.
6 *
7 * The door/window can also be lock or unlocked by using the door_window_state.lsl script. However,
8 * the lock does not prevent the door opener from opening and/or closing a door. This is used to ensure
9 * that if the control object is inside a building, a user cannot lock the doors and teleporting out, preventing
10 * anyone, including the owner, from entering the building by the door.
11 *
12 */
13
21integer COMMAND_CHANNEL_NUMBER = 0x80FFFF08; // The Inter-Object communications Channel
22
30string UNLOCK_NAME = "UNLOCK";
31
37string OPEN_NAME = "OPEN";
38
43string CLOSE_NAME = "CLOSE";
44
49string LOCK_NAME = "LOCK";
50
55integer UNLOCK_STATE = 0;
56
61integer OPEN_STATE = 1;
62
67integer CLOSE_STATE = 2;
68
73integer LOCK_STATE = 3;
74
80
85integer intSwing =-90;
86
91rotation rotSwing;
92
97vector vOffset;
98
104
112
121{
122 list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
123 vector v = llList2Vector(l,0);
124 rotation r = llList2Rot(l,1);
125 llSetPrimitiveParams([PRIM_POS_LOCAL,v-(vOffset-vOffset * rotSwing)*r, PRIM_ROT_LOCAL,rotSwing*r]);
126 rotSwing.s*=-1;
127}
128
132//default
133
138{
139
150 {
151 rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD); //90 degress on the z axis
153
154 vector size = llGetScale();
155 vOffset = <(size.x*0.45),(size.y*0.5),0.0>;
156
157 door_locked = FALSE;
158
159 listen_handle = llListen(COMMAND_CHANNEL_NUMBER, "", "", ""); // Open the Communications Channel
160 }
161
177 listen(integer ChannelNumber, string Name, key Id, string Message)
178 {
179 if (Message == UNLOCK_NAME)
180 {
181 door_locked = FALSE;
182 }
183 else if ((Message == OPEN_NAME) && !door_locked)
184 {
186 }
187 else if ((Message == CLOSE_NAME) && !door_locked)
188 {
189 if (rotSwing.s != closed_angle) rdSwingDoor();
190 }
191 else if (Message == LOCK_NAME)
192 {
193 door_locked = TRUE;
194 if (rotSwing.s != closed_angle) rdSwingDoor();
195 }
196 }
197
209 touch_start(integer total_number)
210 {
211 if ( !door_locked || (llDetectedKey(0) == llGetOwner()) )
212 {
213 rdSwingDoor();
214 }
215 else
216 {
217 llWhisper(PUBLIC_CHANNEL, "This door is currently locked.");
218 }
219 }
220
237 collision_start(integer total_number)
238 {
239 if (rotSwing.s != closed_angle)
240 {
241 llWhisper(PUBLIC_CHANNEL, "PLEASE BE CAREFUL! This door is already open.");
242 }
243 else if ((llDetectedKey(0) == llGetOwner()) || !door_locked)
244 {
245 rdSwingDoor();
246 }
247 else
248 {
249 llWhisper(PUBLIC_CHANNEL, "PLEASE BE CAREFUL! This door is currently locked.");
250 }
251 }
252}
state_entry()
Initialise the Door/Window swing parameters.
touch_start(integer total_number)
Process when a touch is detected.
collision_start(integer total_number)
Process collisions with the door/window.
listen(integer ChannelNumber, string Name, key Id, string Message)
Listen to the channel selected in state_entry() and process any commands received.
string LOCK_NAME
The string for the Lock Command.
float closed_angle
The Angle that the door/window will be in the Open State.
integer OPEN_STATE
Flag indicating the dooe/window is open.
integer UNLOCK_STATE
Flag indicating the dooe/window is unlocked.
vector vOffset
The movement offset of the door/window when opened.
rdSwingDoor()
Swing the Door/Window between Open and Closed.
string UNLOCK_NAME
The string for the Unlock Command.
string OPEN_NAME
The string for Open Windws Command.
integer door_locked
Value indicating if the door/window is currently locked or unlocked.
integer CLOSE_STATE
Flag indicating the dooe/window is closed.
string CLOSE_NAME
integer COMMAND_CHANNEL_NUMBER
This is the channel where the script accepts remote commands.
integer listen_handle
Listen handle.
integer intSwing
Angle the door/window will swing.
rotation rotSwing
Swing angle in a rotation vector.
integer LOCK_STATE
Flag indicating the dooe/window is locked.