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 Passive_Doorscript_autoclose_reset  

Passive_Doorscript_autoclose_reset

Passive Doorscript (autoclose) -reset on rez.lsl

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

the Zip file

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

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