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_follower  

Train_car_follower

Train_car_follower

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_follower
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Train_car_follower_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 is the simple follower that is used to make a car follow the
13 // train or follow another car. It uses a simple inchannel and outchannel
14 // mechanism - each position on inchannel is handed over to one of several
15 // movement scripts and then announced on the outchannel. A car has to handle
16 // it's queue length itself - the length of the queue is based on the engine
17 // speed and the car and engine sizes.
18
19 // channels to communicate on - inchannel receives, outchannel sends
20 integer inchannel = -65432;
21 integer outchannel = -65433;
22
23 // queue for incoming requests. The length is based on speed and size of the car.
24 list queue = [];
25 integer qlen = 7;
26
27 // timeout for position updates - if we go over this time for updates, die
28 float timeout = 300.0;
29
30 // number of motors in the car and current motor to use
31 integer nummotors = 4;
32 integer currentmotor = 0;
33
34 // for keeping track of the train on sim crossing
35 key train = NULL_KEY;
36
37 // just the listener to make sure we can close it on multiple rezzes
38 integer listener = 0;
39
40 default
41 {
43 {
44 queue = [];
45 llSetTimerEvent(timeout);
46 }
47
48 on_rez(integer start_param)
49 {
50 inchannel = start_param;
51 outchannel = start_param - 1;
52 train = NULL_KEY;
53 queue = [];
54 if(listener) llListenRemove(listener);
55 listener = llListen(inchannel, "", NULL_KEY, "");
56 }
57
58 listen(integer channel, string name, key id, string message)
59 {
60 if((id == train) || (llGetOwnerKey(id) == llGetOwner()))
61 {
62 // check for the trains die command
63 if(message == "!DIE!")
64 {
65 llShout(outchannel, "!DIE!");
66 llDie();
67 }
68 llSetTimerEvent(timeout);
69 if(message != "!NOP!")
70 {
71 if(llGetListLength(queue) > qlen)
72 {
73 train = id;
74 string m = llList2String(queue, 0);
75 queue = llList2List(queue, 1, -1);
76 llMessageLinked(LINK_THIS, currentmotor, m, NULL_KEY);
77 llShout(outchannel, m);
78 currentmotor += 1;
79 if(currentmotor >= nummotors)
80 {
81 currentmotor = 0;
82 }
83 }
84 queue += [message];
85 }
86 }
87 }
88
89 timer()
90 {
91 // if there is no update for a given time, we assume the train is dead
92 llDie();
93 }
94 }

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