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
Birds Gracie and George Flamingos  

Gracie and George Flamingos

Free-flight bird system without physics main script

Category: Birds
By : Ferd Frederix
Created: 2014-12-04 Edited: 2014-12-04
Worlds: Second Life

the Zip file

Download all files for Gracie and George Flamingos
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. flight script.lsl
Get file # 2. wing flap script.lsl
Get file # 3. flexi wing script.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // Bird flock flight script
2 // Author: Ferd Frederix
3 // This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
4 // This means that this script itself is not for sale and that modifications to it must be provided to anyone upon request. Pets made with this script may be sold. ~ Ferd Frederix
5
6 // requires the following animations:
7 // land, fly, peck, walk1, walk2, walk3
8
9 integer _debug = FALSE;
10 float SPACE = 1; // twice the amount of slop in flight
11 float SPEED = 2.0; // how fast to fly, large = faster, in meters per second.
12 float RANGE = 8; // how far to sense avatars
13 float TIMEOUT = 2; // how long to stay on ground after flight, and to scan for avatars
14 float MIN = 2; // walk timers
15 float MAX = 7; // MAX + MIN is the random time for actions
16
17 string WINGSOUND = "silence"; // UUID of a sound of wings flapping
18 string PECK = "pecking"; // peck sound
19 string FLY = "silence"; // flying sound
20
21 float totalTime; // the total time it takes to fly around once.
22 list lCoordinate; // a list of coordinates, rotations, and times from the notecard
23
24 integer moving = FALSE; // true if we are flying.
25 integer starting = FALSE; // true once the timer is set up
26
27 // notecard reading
28 integer iIndexLines; // the current line
29 string NOTECARD = "Route"; // the notecard for configuring
30 integer initted; // set TRUE when notecard is read.
31 key kNoteCardLines; // the key of the notecard
32 key kGetIndexLines; // the key of the current line
33 integer linecounter;
34
35
36 // movement
37 integer started = FALSE; // true once someone has clicked Start
38 integer sensorON ; // true if we are the controlling bird
39 vector startPos; // Home pos
40 vector lastPos; // last position we read
41 rotation lastRot; // last rotation
42 rotation startRot; // initial rotation
43
44 integer first; // first time flag
45 integer channel = -32523874; // the only listener
46 integer listener; // listener int
47
48 rotation NormRot(rotation Q)
49 {
50 float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
51 return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
52 }
53
54
55 restart()
56 {
57 SetupListens();
59 startPos = llGetPos();
60 startRot = llGetRot();
61
62 moving = FALSE;
63
64 if(started)
65 {
66 llSensorRepeat("", "", AGENT, RANGE, PI, TIMEOUT);
67 llSetTimerEvent(llFrand(MAX)+MIN); // movement channel
68 }
69 }
70
71 menu()
72 {
73 llDialog(llGetOwner(),"Bird Controls:",["Start","Reset","Stop","Set Pos"],channel);
74 }
75
76 string strip( string str)
77 {
78 string out;
79 integer i;
80
81 for (; i < llStringLength(str); i++)
82 {
83 out += llGetSubString(str,i,i);
84 out = llStringTrim(out, STRING_TRIM);
85 }
86 return out;
87
88 }
89
90 string Getline(list Input, integer line)
91 {
92 return strip(llList2String(Input, line));
93 }
94
95 startFlight()
96 {
97
98 if(_debug) llOwnerSay("flying");
99 // tell the others
100 if(sensorON)
101 llSay(channel,"Start");
102 llMessageLinked(LINK_SET,1,"land","");
103 llMessageLinked(LINK_SET,1,"fly","");
104
105 // llLoopSound(FLY,1.0);
106 starting = TRUE;
107 llSetTimerEvent(0.1);
108 }
109
110 init()
111 {
112 kNoteCardLines = llGetNumberOfNotecardLines(NOTECARD);
113 kGetIndexLines = llGetNotecardLine(NOTECARD,0);
114 }
115
116 SetupListens()
117 {
118 if(listener)
119 llListenRemove(listener);
120
121 listener = llListen(channel,"","","");
122 }
123
124 default
125 {
126
128 {
130 }
131
132
134 {
136
137 llSetKeyframedMotion([],[KFM_COMMAND,KFM_CMD_STOP]);
139 llMessageLinked(LINK_SET,1,"land","");
140
141 //if(_debug) llSetRegionPos(<114.332, 187.276, 20.8566>);
142
143 if(initted == FALSE)
144 {
145 llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]); // needed for older clients
146 init();
147 }
148 }
149
150
151 changed(integer what)
152 {
153 if(what & CHANGED_INVENTORY)
154 {
156 }
157 }
158
159 // read notecard on reset
160 dataserver(key queryid, string data)
161 {
162 if(queryid == kNoteCardLines)
163 {
164 iIndexLines = (integer) data;
165 }
166
167 if(queryid == kGetIndexLines)
168 {
169 if(data != EOF)
170 {
171 queryid = llGetNotecardLine(NOTECARD, linecounter);
172 list lLine = (llParseString2List(data, ["|"], []));
173
174 float ctr = (float) Getline(lLine,1);
175 if(ctr >= 0)
176 {
177 vector pos = (vector)Getline(lLine,2);
178
179 if(pos != ZERO_VECTOR)
180 {
181 rotation rot = (rotation) Getline(lLine,3);
182 float distance = llVecDist(pos,lastPos);
183
184 float time = distance / SPEED;
185 time += llFrand(.2);
186
187 if(time < .2)
188 time = 0.2;
189
190 //rotation newRot = NormRot(rot );
191
192 integer newtime = (integer) (time * 45);
193
194 time = (float) newtime /45;
195
196 lCoordinate += pos ; //* newRot;
197 //lCoordinate += newRot;
198
199 lCoordinate += NormRot(rot);
200 lCoordinate += time;
201 totalTime += time;
202
203 lastPos = pos;
204 lastRot = rot;
205 }
206 integer locationLength = (llGetListLength(lCoordinate))/3; // 3 strided list
207
208 integer InitPerCent = (integer) llRound(((float) locationLength / (float) iIndexLines) * 100);
209 llSetText("Initialising... \n" + (string) InitPerCent + "%" , <1,1,1>, 1.0);
210
211 }
212 else
213 {
214 llOwnerSay("Something is wrong in the notecard");
215 }
216 linecounter++;
217 }
218 else
219 {
220 llOwnerSay("Flight time is " + (string) totalTime + " seconds.");
221 llSetText("", <1,1,1>, 1.0);
222 initted = TRUE;
223 state movement;
224 }
225 kGetIndexLines = llGetNotecardLine(NOTECARD,linecounter);
226 }
227 }
228 }
229
230
231
232 state movement
233 {
235 {
236 restart();
237 }
238
239 changed(integer what)
240 {
241 if(what & CHANGED_INVENTORY)
242 {
244 }
245 }
246
247
248 sensor(integer number)
249 {
250 llSensorRemove(); // an avatar is here, we will turn it on after we fly.
251 if(sensorON && ! moving)
252 {
253 startFlight();
254 }
255 }
256
258 {
260 {
261 menu();
262 }
263 }
264
265 timer()
266 {
267
268 if(starting)
269 {
270 llSleep(1);
271 llSetKeyframedMotion(lCoordinate, [KFM_DATA, KFM_TRANSLATION|KFM_ROTATION, KFM_MODE, KFM_FORWARD]);
272 moving = TRUE;
273 starting = FALSE;
274 sensorON = TRUE; // start the sensing
275 llSetTimerEvent(totalTime); // wake us up at end of the trip.
276 if(_debug) llOwnerSay("start flying");
277 }
278 else if(moving )
279 {
280 if(_debug) llOwnerSay("stopping");
281
282 llSetKeyframedMotion([],[KFM_COMMAND,KFM_CMD_STOP]);
283 llSleep(1); // time to land, flapping motion
284 llSetPos(startPos);
285 llMessageLinked(LINK_SET,1,"land","");
286 llSetRot(startRot);
288 moving = FALSE;
289
290 if( sensorON)
291 llSensorRepeat("", "", AGENT, RANGE, PI, TIMEOUT);
292
293 llSetTimerEvent(llFrand(MAX)+MIN);
294 }
295 else
296 {
297 if(_debug) llOwnerSay("peck");
298
299
301 float rand = llFrand(4);
302 if(rand < 1.0) // 25 % chance of a peck
303 {
304 llMessageLinked(LINK_ROOT,1,"peck","");
305 llPlaySound(PECK,1);
306 }
307 else if(rand < 2) // 25% chance of a flap
308 {
309 llPlaySound(FLY,1.0);
310 llMessageLinked(LINK_SET,1,"peck","");
311 llSleep(2);
312 llMessageLinked(LINK_SET,1,"land","");
313 llSleep(0.5);
314 }
315 else // 50% chance of a motion
316 {
317 integer walknum = llCeil(llFrand(2)) +1; // from 1 to 3
318 llMessageLinked(LINK_ROOT,1,"walk" + (string) walknum,"");
319 }
320 llSetTimerEvent(llFrand(MAX)+MIN);
321 }
322
323 }
324
325
326 listen(integer channel, string name, key id, string message)
327 {
328 if(message == "sensor")
329 {
330 sensorON = FALSE;
332 }
333 else if( message == "Reset")
334 {
336 }
337 else if(message == "Stop")
338 {
339 moving = FALSE;
342 }
343 else if(message == "Start")
344 {
345 started = TRUE;
346 if(moving)
347 return;
348
349 llSleep(llFrand(1.0));
350 startFlight();
351 }
352 else if(message == "Set Pos")
353 {
354 startPos = llGetPos();
355 startRot = llGetRot();
356 llOwnerSay("Position set");
357 }
358 }
359
360
362 {
363 llSay(channel,"sensor");
364 sensorON = TRUE;
365
366 restart();
367 }
368
369
370 }
371
372
373
374
375

Gracie and George Flamingos

Route notecard

Category: Birds
By : Ferd Frederix
Created: 2014-12-04 Edited: 2014-12-04
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 [23:46] Bird Flight recorder: |0|<3.03935, -3.18692, -0.86295>|<0.00000, 0.00000, 0.00000, 1.00000>
2 [23:46] Bird Flight recorder: |1|<0.00000, -5.42105, 3.07461>|<-0.13918, 0.00000, 0.00000, 0.99027>
3 [23:46] Bird Flight recorder: |2|<0.33053, -4.86701, 1.77682>|<-0.00007, -0.00002, 0.11315, 0.99358>
4 [23:46] Bird Flight recorder: |3|<1.79730, -5.49274, 0.95054>|<0.07124, 0.08540, 0.11847, 0.98671>
5 [23:46] Bird Flight recorder: |4|<3.37264, -6.57998, -0.03491>|<0.01015, -0.23322, -0.04242, 0.97145>
6 [23:46] Bird Flight recorder: |5|<1.34866, -5.11773, 0.67158>|<-0.00196, 0.03476, -0.12182, 0.99194>
7 [23:46] Bird Flight recorder: |6|<0.21964, -16.67410, 1.94359>|<-0.01837, -0.09413, -0.18995, 0.97710>
8 [23:46] Bird Flight recorder: |7|<-1.89562, -6.70639, 0.18081>|<-0.00002, -0.03493, -0.00003, 0.99939>
9 [23:46] Bird Flight recorder: |8|<-1.45229, -3.88854, -0.15882>|<-0.10528, -0.13539, -0.03813, 0.98445>
10 [23:46] Bird Flight recorder: |9|<-1.63088, -2.69160, 0.08126>|<0.00801, -0.00332, -0.36657, 0.93035>
11 [23:46] Bird Flight recorder: |10|<-3.83277, -1.24381, -1.61511>|<-0.19385, 0.04657, -0.21220, 0.95667>
12 [23:46] Bird Flight recorder: |11|<0.00000, 0.00000, 0.00000>|<0.00000, -0.06107, -0.00001, 0.99813>
13 [23:46] Bird Flight recorder: |12|<-3.22336, 2.37290, -1.90459>|<0.00000, -0.00006, -0.35027, 0.93665>
14 [23:46] Bird Flight recorder: |13|<-6.68420, 5.94370, -3.59071>|<-0.14768, 0.00642, 0.04308, 0.98808>
15 [23:46] Bird Flight recorder: |14|<-4.37235, 4.48998, 0.32541>|<0.00003, -0.00010, -0.14785, 0.98901>
16 [23:46] Bird Flight recorder: |15|<-5.84365, 7.76727, -0.25457>|<0.00000, 0.00000, 0.00000, 1.00000>
17 [23:46] Bird Flight recorder: |16|<-4.36068, 7.22676, -0.46142>|<-0.16502, -0.00001, -0.00002, 0.98629>
18 [23:46] Bird Flight recorder: |17|<-3.88627, 5.98682, 1.15929>|<0.00000, 0.00000, 0.00000, 1.00000>
19 [23:46] Bird Flight recorder: |18|<-2.51026, 6.88961, 0.63770>|<0.04568, 0.14057, 0.30563, -0.94061>
20 [23:46] Bird Flight recorder: |19|<1.70412, 7.03259, 1.50477>|<-0.17338, -0.06009, 0.01063, 0.98296>
21 [23:46] Bird Flight recorder: |20|<4.62103, 7.27395, 1.71155>|<-0.08307, 0.14289, -0.16779, 0.97187>
22 [23:46] Bird Flight recorder: |21|<4.56394, 4.56393, 1.44013>|<0.02767, 0.03304, -0.15553, 0.98689>
23 [23:46] Bird Flight recorder: |22|<3.96779, 3.05808, -1.51505>|<0.20295, -0.04500, -0.21171, 0.95497>
24 [23:46] Bird Flight recorder: |23|<8.14900, 1.38265, -3.45853>|<-0.00002, 0.00000, -0.19937, 0.97992>
25 [23:46] Bird Flight recorder: |24|<4.60667, -0.61626, -1.70496>|<-0.30380, 0.08623, -0.06836, 0.94636>
26 [23:46] Bird Flight recorder: |25|<3.82848, -1.75406, -0.45274>|<-0.00005, 0.00002, -0.25039, 0.96815>

Gracie and George Flamingos

DESCRIPTION: []::Free-flight bird system wing flap script - makes flex wings flap

Category: Birds
By : Ferd Frederix
Created: 2014-12-04 Edited: 2014-12-04
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 default
2 {
4 {
6 }
7
8 timer()
9 {
10
11 llMessageLinked(LINK_SET,10,"flap","");
12 llSleep(.5);
13 llMessageLinked(LINK_SET,-10,"flap","");
14
15
16 }
17 }

Gracie and George Flamingos

DESCRIPTION: []::Free-flight bird system without physics

Category: Birds
By : Ferd Frederix
Created: 2014-12-04 Edited: 2014-12-04
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 default
2 {
3
5 {
7 }
8
9 link_message(integer s, integer num, string str, key id)
10 {
11 if(str=="flap")
12 llSetPrimitiveParams([ PRIM_FLEXIBLE, 1, 2, num, 0.0, 0.0, 10.0, <0,0,0>] );
13
14 else if(str == "fly")
15 {
17 }
18 else if(str == "land")
19 {
21 }
22
23 }
24
26 {
28 }
29 }

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