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  

Door

Door.lsl

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

the Zip file

Download all files for Door
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Door_1.lsl
1
2 // improved door script by Ezhar Fairlight
3 // features: automatic closing, workaround for rotating out of position,
4 // doesn't mess up when moved, adjustable direction (inwards/outwards)
5 // updated for SL 1.1 damped rotations, small bugfix
6
7 // ********** USER SETTINGS HERE **********
8 float TIMER_CLOSE = 5.0; // automatically close the door after this many seconds,
9 // set to 0 to disable
10
11 integer DIRECTION = -1; // direction door opens in. Either 1 (outwards) or -1 (inwards);
12 // ********** END OF USER SETTINGS **********
13
14
15
16 integer DOOR_OPEN = 1;
17 integer DOOR_CLOSE = 2;
18
19 vector mypos; // door position (objects move a tiny amount
20 // away from their position each time they are rotated,
21 // thus we need to workaround this by resetting
22 // the position after rotating)
23
24 door(integer what) {
25 rotation rot;
26 rotation delta;
27
28 llSetTimerEvent(0); // kill any running timers
29
30 if( what == DOOR_OPEN ) {
31 llTriggerSound("Door open", 0.8);
32
33 rot = llGetRot();
34 delta = llEuler2Rot(<0, 0, -DIRECTION * PI_BY_TWO>);
35 rot = delta * rot; // rotate by -45 degree
36 llSetRot(rot);
37
38 } else if( what == DOOR_CLOSE) {
39 rot = llGetRot();
40 delta = llEuler2Rot(<0, 0, DIRECTION * PI_BY_TWO>); // rotate by 45 degree
41 rot = delta * rot;
42 llSetRot(rot);
43
44 llTriggerSound("Door close", 0.8);
45 }
46 }
47
48
49 default { // is closed
50 on_rez(integer start_param) { // reset, so we store the new position
52 }
53
54 state_entry() {
55 mypos = llGetPos(); // remember where we're supposed to be
56 }
57
58 touch_start(integer total_number) {
59 door(DOOR_OPEN);
60
61 state is_open;
62 }
63
64 moving_end() { // done moving me around, store new position
65 mypos = llGetPos();
66 }
67 }
68
69 state is_open {
70 state_entry() {
71 llSetTimerEvent(TIMER_CLOSE);
72 }
73
74 touch_start(integer num) {
75 door(DOOR_CLOSE);
76
77 llSetPos(mypos); // workaround for tiny movements during rotation
78
79 state default;
80 }
81
82 timer() { // it's time to close the door
83 door(DOOR_CLOSE);
84
85 llSetPos(mypos); // workaround for tiny movements during rotation
86
87 state default;
88 }
89
90 moving_start() { // close door when door is being moved
91 door(DOOR_CLOSE);
92
93 state default;
94 }
95 }
96 // END //

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