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
Flight Assist Cyberflight_1_1  

Cyberflight_1_1

Cyberflight 1.0 1.lsl

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

the Zip file

Download all files for Cyberflight_1_1
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Cyberflight_1_1_1.lsl
1
2 // This Script is distributed under the terms of the modified BSD license, reproduced at the end of
3 // the script. The license and acknowledgments listed must be included in some fashion if this script
4 // is redistributed in a non-readable or non-modifiable form.
5
6 // Cyberflight (gentle flight boost)
7
8 float last_alt;
9 float last_time;
10 float last_move;
11 float boost;
12 integer controls;
13
14 float MIN_SPEED = 2.0;
15 float WANT_SPEED = 20.0;
16 float MAX_SPEED = 25.0;
17 float MIN_TIME = 1.0;
18 float DEFAULT_BOOST = 0.5;
19
20 float FAST_TICK = 0.1;
21 float SLOW_TICK = 1.0;
22 float LONG_TIME = 5.0; // reset boost if no work in a long time
23
24 float MIN_BOOST_HEIGHT = 72.0;
25 float MIN_BOOST_CLEARANCE = 36.0;
26
27 integer flying = -1;
28 integer falling = -1;
29 integer hovering = -1;
30 integer dimmed = -1;
31
32 integer HUD_OFF = 0;
33 integer HUD_ALWAYS = -1;
34 integer HUD_ON = 1;
35 integer hud_state = 1; // default HUD_ON
36
37 string last_hud_text;
38 integer hud_active = 0;
39 float last_hud_time = 0;
40 show_hud()
41 {
42 if(hud_state == HUD_ALWAYS)
43 hud_active = 1;
44 else if(hud_state == HUD_ON)
45 {
46 if(hud_active >= 0 && flying == 0 && hovering == 0 && falling == 0) hud_active = 0;
47 else if(hud_active <= 0 && (flying > 0 || hovering > 0 || falling > 0)) hud_active = 1;
48 }
49 else if(hud_active == 1)
50 hud_active = 0;
51
52 if(hud_active == 1) {
53 float time = llGetTime();
54 if(last_hud_time > time - 1) return;
55 vector v = llGetVel();
56 vector p = llGetPos();
57 string hover_text = "";
58 if(hovering && controls == 0)
59 hover_text = " (hover)";
60 string boost_text = "Standby";
61 if(!hovering)
62 boost_text = "Passive";
63 if(falling)
64 boost_text = "Inactive";
65 if(boost > 0 && controls > 0)
66 boost_text = "Boost "+((string)llFloor(boost * 100.0 / 6.0 + 0.5))+"%";
67 string hud_text = "";
68 if(hud_state == HUD_ALWAYS)
69 hud_text = "\nHUD locked";
70
71 string t =
72 "<"+((string)llFloor(p.x+0.5))+","+((string)llFloor(p.y+0.5))+","+((string)llFloor(p.z+0.5))+">"+
73 " ("+((string)(llFloor(p.z-llGround(<0,0,0>)+0.5)))+"m AGL)\n"+
74 "<"+((string)llFloor(v.x+0.5))+","+((string)llFloor(v.y+0.5))+","+((string)llFloor(v.z+0.5))+">"+
75 " ("+((string)llFloor(llVecMag(v)))+"m/s)\n"+
76 boost_text+hover_text+hud_text;
77 if(last_hud_text != t) {
78 vector color = <1,1,1>;
79 if(hud_state == HUD_ALWAYS)
80 color = <.3,1,.3>;
81 llSetText(t, color, 1);
82 last_hud_text = t;
83 last_hud_time = time;
84 }
85 } else if(hud_active == 0) {
86 last_hud_text = "";
87 last_hud_time = 0;
88 llSetText("", ZERO_VECTOR, 0);
89 hud_active = -1;
90 }
91 }
92
93 set_hover(integer active)
94 {
95 if(active == hovering) return;
96 hovering = active;
97 if(hovering)
98 llSetForce(<0,0,9.8> * llGetMass(), FALSE);
99 else
100 llSetForce(<0,0,0>, FALSE);
101 }
102
103 float last_tick = -1;
104 set_tick(float tick)
105 {
106 if(tick == last_tick) return;
107 last_tick = tick;
108 llSetTimerEvent(tick);
109 }
110
111 float last_boost_height;
112 float average_boost;
113 check_boost()
114 {
115 flying = 1;
116 falling = 0;
117
119
120 if((info & AGENT_FLYING) == 0)
121 {
122 set_hover(FALSE);
123 falling = (info & AGENT_IN_AIR) != 0;
124 flying = 0;
125 boost = 0;
126 set_tick(SLOW_TICK);
127 return;
128 }
129
130 vector pos = llGetPos();
131 if(pos.z < last_boost_height / 2) // trim running average of boost if big altitude drop
132 average_boost = average_boost * (pos.z / last_boost_height)
133 + DEFAULT_BOOST * (1.0 - pos.z / last_boost_height);
134
135 if(pos.z < MIN_BOOST_HEIGHT || pos.z - llGround(<0,0,0>) < MIN_BOOST_CLEARANCE)
136 {
137 set_hover(FALSE);
138 set_tick(SLOW_TICK);
139 boost = 0;
140 return;
141 }
142
143 set_hover(TRUE);
144
145 if(controls <= 0) return;
146
147 vector vel = llGetVel();
148 float time = llGetTime();
149 float speed = vel.z;
150 float target = WANT_SPEED;
151 float window = WANT_SPEED / 20;
152
153 if(speed > 0)
154 last_move = time;
155
156 if(time - last_time >= LONG_TIME)
157 boost = 0;
158 else
159 {
160 if(speed < target - window)
161 {
162 if(boost == 0)
163 boost = average_boost;
164 if(time - last_move > MIN_TIME) boost += 0.4;
165 else if(speed < target * 0.25) boost += 0.2;
166 else if(speed < target * 0.5 ) boost += 0.1;
167 else if(speed < target * 0.75) boost += 0.05;
168 else if(speed < target - window * 4) boost += 0.02;
169 else boost += 0.01;
170 }
171 else if(speed > MAX_SPEED) boost -= 0.5;
172 else if(speed > target + window * 4) boost -= 0.1;
173 else if(speed > target + window * 2) boost -= 0.03;
174 else if(speed > target + window) boost -= 0.01;
175
176 if(boost <= 0)
177 boost = 0;
178 if(boost > 0) {
179 llApplyImpulse(<0,0,boost> * llGetMass(), FALSE);
180 average_boost = average_boost * 0.9 + boost * 0.1; // 10 sample running average
181 last_boost_height = pos.z;
182 }
183 }
184
185 if(boost) set_tick(FAST_TICK);
186 else set_tick(SLOW_TICK);
187 last_alt = pos.z;
188 last_time = time;
189 }
190
191 take_controls()
192 {
194 }
195
196 request_perms()
197 {
199 take_controls();
200 else
202 }
203
204 init()
205 {
206 boost = 0;
207
208 flying = -1;
209 falling = -1;
210 hovering = -1;
211 dimmed = -1;
212 hud_state = HUD_ON;
213
214 set_tick(SLOW_TICK);
215 if(llGetAttached()) request_perms();
216 }
217
218 default
219 {
221 {
222 init();
223 }
224
225 on_rez(integer param)
226 {
227 init();
228 }
229
231 {
232 if(mask & PERMISSION_TAKE_CONTROLS) take_controls();
233 }
234
235 control(key id, integer level, integer edge)
236 {
237 controls = 0;
238 if(level & CONTROL_UP) controls++;
239 if(level & CONTROL_DOWN) controls--;
240 check_boost();
241 }
242
243 timer()
244 {
245 check_boost();
246 show_hud();
247 if(flying && boost > 0)
248 {
249 if(dimmed != 0)
251 dimmed = 0;
252 }
253 else
254 {
255 integer dimness = 4;
256 if(hud_state == HUD_ON) dimness = 5;
257 else if(hud_state == HUD_ALWAYS) dimness = 6;
258 if(dimmed != dimness) {
259 float alpha = ((float)dimness) / 10;
260 llSetAlpha(alpha,ALL_SIDES);
261 }
262 dimmed = dimness;
263 }
264 }
265
267 {
269 {
270 hud_state++;
271 if(hud_state > 1)
272 hud_state = -1;
273 }
274 }
275 }
276
277
278 //Copyright (c) 2005, Argent Stonecutter & player
279 //All rights reserved.
280 //
281 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
282 //
283 // * Redistributions in modifiable form must retain the above copyright notice, this list of conditions and the following disclaimer.
284 // * Redistributions in non-modifiable form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
285 // * Neither the name of Argent Stonecutter nor his player may be used to endorse or promote products derived from this software without specific prior written permission.
286 //
287 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288 // END //

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