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
Vehicle OpenSim Car  

OpenSim Car

This script allows a car to hover over water as well as run on land. It has ten power settings.

Category: Vehicle
By : Sarge Misfit
Created: 2014-02-08 Edited: 2014-02-08
Worlds: Second Life

the Zip file

Download all files for OpenSim Car
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl
1 // This script allows a car to hover over water as well as run on land. It has ten power settings. I have not yet been able to get it to allow a flight mode. It is ODE Physics based.
2
3 integer Private = 1; // Change to 1 to prevent others riding.
4 integer tt;
5 integer Gear = 1;
6 integer Run;
7 integer oldn;
8
9 vector Sitpos = <.8,0,.8>;
10 vector SitrotV = <0,0,0>;
11
12 rotation Sitrot;
13
14 key oldagent;
15 key agent;
16
17 float forward_power = 3; //Power used to go forward (1 to 30)
18 float forward_normal = 3;
19 float crash_power_forward = 3;
20 float reverse_power = -3; //Power ued to go reverse (-1 to -30)
21 float turning_ratio = 5; //How sharply the vehicle turns. Less is more sharply. (.1 to 10)
22 float Speed;
23
24 string sit_message = "Ride"; //Sit message
25 string not_owner_message = "You are not the owner of this vehicle."; //Not owner message
26 string DrivingAnim = "driving generic"; //Animation to use when owner sits
27
28 ///////////////////////////////
29
30 go_up()
31 {
33 llSetRot(<0,0,0,0>);
35 }
36
37 setCamera(float degrees)
38 {
39 rotation sitRot = llAxisAngle2Rot(<0, 0, 1>, degrees * PI);
40 llSetCameraEyeOffset(<-10, 0, 3> * sitRot);
41 llSetCameraAtOffset(<4, 0, 3> * sitRot);
43 }
44
45 setVehicle()
46 {
52 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.2);
55 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.5);
56
57 }
58
59 Init()
60 {
61 Run = 0;
64 Sound(0);
65 vector rotv = llRot2Euler(llGetRot());
66 rotation rot = llEuler2Rot(<0,0,rotv.z>);
67 llSetRot(rot);
68 Sitrot = llEuler2Rot(DEG_TO_RAD * SitrotV);
69 }
70
71 Reset()
72 {
73 Run = 0;
74 vector rotv = llRot2Euler(llGetRot());
75 rotation rot = llEuler2Rot(<0,0,rotv.z>);
76 llSetRot(rot);
77 llSetPos(llGetPos() + <0,0,0.5>);
78 }
79
80 integer LastSetMaterial = FALSE;
81 SetMaterial()
82 {
83 if(LastSetMaterial == FALSE)
84 {
85 LastSetMaterial = TRUE;
86 }
87 }
88
89 Sound(integer n)
90 {
91 if(n != oldn)
92 {
93 oldn = n;
94 if(n == 2)
95 {
97 }
98
99 else if(n == 1)
100 {
101 llLoopSound("plane",1);
102 }
103
104 else
105 {
107 }
108 }
109 }
110
111 default
112 {
114 {
115 Init();
116 llSetSitText(sit_message);
117 llSitTarget(Sitpos, Sitrot);
118 setCamera(0);
119 }
120
121 on_rez(integer rn)
122 {
124 llSetPos(llGetPos() + <0,0,.5>);
125 }
126
127 link_message(integer sender, integer num, string message, key id)
128 {
129 if(message=="reset")
130 {
131 Reset();
132 }
133 }
134
135 changed(integer change)
136 {
137 if((change & CHANGED_LINK) == CHANGED_LINK)
138 {
139 agent = llAvatarOnSitTarget();
140
141 if(agent != NULL_KEY)
142 {
143 if( (agent != llGetOwner()))
144 {
145 llSay(0, not_owner_message);
146 llUnSit(agent);
147 llPlaySound("car alarm",1.0);
148 llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
149 }
150
151 else
152 {
154 llSleep(.4);
155 oldagent = agent;
156 setVehicle();
157 SetMaterial();
158 llSetTimerEvent(0.3);
159 llMessageLinked(LINK_SET, 0, "shift", "2");
161 Sound(1);
162 Run = 1;
163 }
164 }
165
166 else
167 {
168 Run = 0;
170 llStopAnimation(DrivingAnim);
171 Init();
172 llSetPos(llGetPos() + <0,0,0>);
173 Sound(0);
174 }
175 }
176 }
177
179 {
180 if(perm)
181 {
182 forward_power = forward_normal;
183 reverse_power = -2;
184 turning_ratio = 5;
185 Gear = 2;
187 llPlaySound("start",1.0);
188 llMessageLinked(LINK_SET, 0, "shift", "2");
189 llSetPos(llGetPos() + <0,0,0.5>);
190 llStartAnimation(DrivingAnim);
191 llWhisper(0,"Hit M for mouselook, page up and down for thrust control. If you flip, Stand Up to flip the vehicle right-side up.");
192 }
193 }
194
195 control(key id, integer level, integer edge)
196 {
197 if(Run == 0)
198 {
199 return;
200 }
201 integer reverse=1;
202 vector angular_motor;
203 vector vel = llGetVel();
204 Speed = llVecMag(vel);
205
206 if((level & edge & CONTROL_UP) || ((Gear >= 7) && (level & CONTROL_UP)))
207 {
208 Gear=Gear+1;
209
210 if(Gear == 2)
211 {
212 llSay(0,"Thrust at 10%");
213 llLoopSound("gear1",1);
214 llMessageLinked(LINK_SET, 0, "shift", "2");
215 }
216
217 if(Gear == 3)
218 {
219 llSay(0,"Thrust at 20%");
220 llLoopSound("gear2",1);
221 llMessageLinked(LINK_SET, 0, "shift", "3");
222 }
223
224 if(Gear == 4)
225 {
226 llSay(0,"Thrust at 30%");
227 llLoopSound("gear3",1);
228 llMessageLinked(LINK_SET, 0, "shift", "4");
229 }
230
231 if(Gear == 5)
232 {
233 llSay(0,"Thrust at 40%");
234 llLoopSound("gear4",1);
235 llMessageLinked(LINK_SET, 0, "shift", "5");
236 }
237
238 if(Gear == 6)
239 {
240 llSay(0,"Thrust at 50%");
241 llLoopSound("gear5",1);
242 llMessageLinked(LINK_SET, 0, "shift", "6");
243 }
244
245 if(Gear == 7)
246 {
247 llSay(0,"Thrust at 60%");
248 llLoopSound("gear6",1);
249 llMessageLinked(LINK_SET, 0, "shift", "7");
250 }
251
252 if(Gear == 8)
253 {
254 llSay(0,"Thrust at 70%");
255 llLoopSound("gear6",1);
256 llMessageLinked(LINK_SET, 0, "shift", "8");
257 }
258
259 if(Gear == 9)
260 {
261 llSay(0,"Thrust at 80%");
262 llLoopSound("gear6",1);
263 llMessageLinked(LINK_SET, 0, "shift", "9");
264 }
265
266 if(Gear == 10)
267 {
268 llSay(0,"Thrust at 90%");
269 llLoopSound("gear6",1);
270 llMessageLinked(LINK_SET, 0, "shift", "10");
271 }
272
273 if(Gear == 11)
274 {
275 llSay(0,"Thrust at 100%");
276 llLoopSound("gear6",1);
277 llMessageLinked(LINK_SET, 0, "shift", "11");
278 }
279
280 if(Gear < 1) Gear = 1;
281 if(Gear > 11) Gear = 11;
282 }
283
284 if((level & edge & CONTROL_DOWN) || ((Gear >= 7) && (level & CONTROL_DOWN)))
285 {
286 Gear=Gear-1;
287
288 if(Gear == 2)
289 {
290 llSay(0,"Power at 10%");
291 llLoopSound("gear1",1);
292 llMessageLinked(LINK_SET, 0, "shift", "2");
293 }
294
295 if(Gear == 3)
296 {
297 llSay(0,"Power at 20%");
298 llLoopSound("gear2",1);
299 llMessageLinked(LINK_SET, 0, "shift", "3");
300 }
301
302 if(Gear == 4)
303 {
304 llSay(0,"Power at 30%");
305 llLoopSound("gear3",1);
306 llMessageLinked(LINK_SET, 0, "shift", "4");
307 }
308
309 if(Gear == 5)
310 {
311 llSay(0,"Power at 40%");
312 llLoopSound("gear4",1);
313 llMessageLinked(LINK_SET, 0, "shift", "5");
314 }
315
316 if(Gear == 6)
317 {
318 llSay(0,"Power at 50%");
319 llLoopSound("gear5",1);
320 llMessageLinked(LINK_SET, 0, "shift", "6");
321 }
322
323 if(Gear == 7)
324 {
325 llSay(0,"Power at 60%");
326 llLoopSound("gear6",1);
327 llMessageLinked(LINK_SET, 0, "shift", "7");
328 }
329
330 if(Gear == 8)
331 {
332 llSay(0,"Thrust at 70%");
333 llLoopSound("gear6",1);
334 llMessageLinked(LINK_SET, 0, "shift", "8");
335 }
336
337 if(Gear == 9)
338 {
339 llSay(0,"Thrust at 80%");
340 llLoopSound("gear6",1);
341 llMessageLinked(LINK_SET, 0, "shift", "9");
342 }
343
344 if(Gear == 10)
345 {
346 llSay(0,"Thrust at 90%");
347 llLoopSound("gear6",1);
348 llMessageLinked(LINK_SET, 0, "shift", "10");
349 }
350
351 if(Gear == 11)
352 {
353 llSay(0,"Thrust at 100%");
354 llLoopSound("gear6",1);
355 llMessageLinked(LINK_SET, 0, "shift", "11");
356 }
357
358 if(Gear < 1) Gear = 1;
359 if(Gear > 11) Gear = 11;
360 }
361
362 if(level & CONTROL_FWD)
363 {
364 turning_ratio = 5;
367 reverse=1;
368 }
369
370 if(level & CONTROL_BACK)
371 {
374 turning_ratio = -5;
375 reverse = -1;
376 }
377
379 {
380 angular_motor.z -= Speed / (turning_ratio*Gear);
381 }
382
384 {
385 angular_motor.z += Speed / (turning_ratio*Gear);
386 }
387
389
390 }
391
392 timer()
393 {
394
395 if(Run == 1)
396 {
397 vector pos = llGetPos();
398 float Z = pos.z;
399
400 if(Z < 20)
401 {
405 }
406
407 else
408 {
411 }
412 vector vel = llGetVel();
413 Speed = llVecMag(vel);
414
415 if(Speed > 2.0)
416 {
417 Sound(2);
418 }
419
420 else if(Speed > 0.0)
421 {
424 Sound(1);
425 }
426 llSetTimerEvent(0.3);
427 }
428
429 else
430 {
431 llSetTimerEvent(0.0);
432 }
433 }
434
435 } //end default

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