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
Train Train_car_motor  

Train_car_motor

Train_car_motor

Category: Train
By : Barney Boomslang
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Train_car_motor
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Train_car_motor_1.lsl
1 // copyright 2007 Barney Boomslang
2 //
3 // this is under the CC GNU GPL
4 // http://creativecommons.org/licenses/GPL/2.0/
5 //
6 // prim-based builds that just use this code are not seen as derivative
7 // work and so are free to be under whatever license pleases the builder.
8 //
9 // Still this script will be under GPL, so if you build commercial works
10 // based on this script, keep this script open!
11
12 // This script moves the train car to the given position using warping to
13 // allow even updates over a longer distance. This script needs to be inside
14 // the train cars multiple times, at least 2 times. Each instance of this
15 // script needs to have it's own "mynum" value. It gets the number in the
16 // on_rez event from it's own name (multiple instances will be numbered
17 // by SL automatically and so get different numbers)
18
19 // my motor number (each motor script needs it's own)
20 integer mynum = 0;
21
22 // offset for car height with regard to engine
23 vector offset = <0,0,0.434>;
24
25 // jump to a target in one big swipe
26 llWarp2Pos( vector d, rotation rot )
27 {
28 if( d.z > 768 )
29 d.z = 768;
30 integer s = (integer)(llVecMag(d-llGetPos())/10)+1;
31 if( s > 100 )
32 s = 100;
33 integer e = (integer)( llLog( s ) / llLog( 2 ) );
34 list rules = [ PRIM_POSITION, d ];
35 integer i;
36 for ( i = 0 ; i < e ; ++i )
37 rules += rules;
38 integer r = s - (integer)llPow( 2, e );
39 if( r > 0 )
40 rules += llList2List( rules, 0, r * 2 + 1 );
41 llSetPrimitiveParams( [PRIM_ROTATION, rot] + rules );
42 }
43
44 default
45 {
46 on_rez(integer start_param)
47 {
48 list parts = llParseString2List(llGetScriptName(), [" "], []);
49 if(llGetListLength(parts) == 2)
50 {
51 integer i = (integer)llList2String(parts, 1);
52 if(i) mynum = i;
53 }
54 }
55
56 link_message(integer sender, integer num, string str, key id)
57 {
58 if(num == mynum)
59 {
60 list parts = llParseString2List(str, ["|"], []);
61 if(llGetListLength(parts) == 2)
62 {
63 vector pos = (vector)llList2String(parts, 0) - llGetRegionCorner();
64 rotation rot = (rotation)llList2String(parts, 1);
65 pos += offset;
66 llWarp2Pos(pos, rot);
67 }
68 }
69 }
70 }

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