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
Elevator Elevator_Script  

Elevator_Script

Elevator Script.lsl

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

the Zip file

Download all files for Elevator_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Elevator_Script_1.lsl
1
2 vector alignment;
3 vector targetVector;
4 integer travelDistance;
5 integer numListen;
6 integer targetFloor;
7 list floorHeights = [26.1,36,46,56,66,76,86,96,106,116,126,136];
8 float fixedFloorHeight = 10; //Set to floor heights, or set to -1 to use floorHeights list
9 float speed = 0.25; //Valid values are 0.01 to 1.0, a Percentage of maxSpeed;
10 float maxSpeed = 32;
11 float precision = 0.5;
12 integer autoSpeed = TRUE;
13 integer initialDistance;
14
15 elevate (vector end)
16 {
17 vector current = llGetPos();
18 travelDistance = llRound(current.z-end.z);
19 travelDistance = llAbs(travelDistance);
20
21 if(autoSpeed)
22 {
23 if(travelDistance < (initialDistance / 2))
24 {
25 speed -= (precision / 50);
26 if(speed < 0.25)
27 speed = 0.25;
28 }
29 else
30 {
31 speed += (precision / 25);
32 if(speed > 1)
33 speed = 1;
34 }
35 }
36 if(travelDistance > 30)
37 {
38 travelDistance = 30;
39 if(end.z > current.z)
40 {
41 end.z = current.z + 30;
42 }
43 else
44 {
45 end.z = current.z - 30;
46 }
47 }
48 float i = travelDistance/(maxSpeed*speed);
49 llMoveToTarget(end,i);
50 }
51
52 GotoFloor (integer floor, key id)
53 {
54 llWhisper(0, "Moving to floor#" + (string)floor);
56 llLoopSound("ElevatorNoises", 1);
57
58 targetFloor = floor;
59
60 if(fixedFloorHeight > 0)
61 {
62 targetVector = alignment;
63 targetVector.z = alignment.z + (fixedFloorHeight * floor);
64 }
65 else
66 {
67 targetVector = alignment;
68 targetVector.z = llList2Float(floorHeights, floor);
69 }
70 llWhisper(0, "At " + (string)targetVector.z + " meters...");
71
72 vector current = llGetPos();
73 initialDistance = llRound(current.z-targetVector.z);
74 initialDistance = llAbs(initialDistance);
75
76 if(autoSpeed)
77 {
78 speed = 0.01;
79 }
80
81 elevate(targetVector);
82 llSetTimerEvent(precision);
83 }
84
85 reset()
86 {
87 llSay(0, "Resetting Elevator...");
88 llSetStatus(STATUS_ROTATE_X| STATUS_ROTATE_Y| STATUS_ROTATE_Z, FALSE);
89
90 alignment = llGetPos();
93 llListenRemove(numListen);
94 numListen = llListen( 0, "", "", "" );
95 }
96 default
97 {
99 {
100 reset();
101 }
102 object_rez(key id)
103 {
105 }
106 listen(integer a, string n, key id, string m)
107 {
108 vector pos;
109 integer Floor;
110 float tempFloat;
111
112 if(llSubStringIndex(m, "goto floor") == 0)
113 {
114 Floor = (integer)llGetSubString(m, 10, llStringLength(m));
115 GotoFloor(Floor, NULL_KEY);
116 }
117 if(llSubStringIndex(m, "speed") == 0)
118 {
119 tempFloat = (float)llGetSubString(m, 5, llStringLength(m));
120 if((tempFloat > 0.001) && (tempFloat <= 1.0))
121 {
122 speed = tempFloat;
123 }
124 }
125 if((m=="elevator reset") && (id==llGetOwner()))
126 {
127 reset();
128 }
129 }
130
131 timer()
132 {
133 vector CurrentPos;
134 float tempfloat;
135
136 CurrentPos = llGetPos();
137 tempfloat = (CurrentPos.z - targetVector.z);
138
139 if(llFabs(tempfloat) < 2)
140 {
141 if(llFabs(tempfloat) < 0.05)
142 {
143 //Arrived at Floor
144 llWhisper(0, "Arrived at floor #" + (string)targetFloor);
148 }
149 else
150 {
151 llMoveToTarget(targetVector,1.0);
152 }
153 }
154 else
155 {
156 if(fixedFloorHeight > 0)
157 {
158 targetVector = alignment;
159 targetVector.z = alignment.z + (fixedFloorHeight * targetFloor);
160 }
161 else
162 {
163 targetVector = alignment;
164 targetVector.z = llList2Float(floorHeights, targetFloor);
165 }
166 elevate(targetVector);
167 }
168 }
169 }
170
171
172
173
174 // END //

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