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
Teleport PortRingRetriever_version_13  

PortRingRetriever_version_13

PortRingRetriever version 1.3.lsl

Category: Teleport
By : neo Rebus
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for PortRingRetriever_version_13
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. PortRingRetriever_version_13_1.lsl
1
2 // PortRingRetriever - Retrieve a set of PortRing objects from
3 // a dropped-in notecard.
4 // version 1.3.0, 1 August 2004, by Neo Rebus
5 //
6 // This script will retrieve the objects that make up a PortRing
7 // structure.
8 //
9 // See PortRingCreator for the details of the notecard.
10 //
11 // General algorithm:
12 //
13 // When a notecard is dropped in, parse the notecard into the
14 // gxPortRingInfo and gxPortRingStations global lists. When
15 // finished, the first three entries should be strings containing
16 // the names of the three Porter objects - back, forward, base,
17 // respectively, followed by the spacing between 'porters in a
18 // set, and then by vector, rotation pairs, the first for the base
19 // location, the rest
20 // for each station.
21 //
22 // Delete the notecard.
23 //
24 // Loop through the base and station locations, use a sensor to
25 // find the different objects, and attach them to this object.
26 //
27 ////////////////////////////////////////////////////////////////////////
28 //
29 // REVISION HISTORY
30 //
31 // version 1.3.0, 1 August 2004, by Neo Rebus
32 // Added RINGSTYLE option for compatibility with PortRingCreator.
33 // version 1.2.0, 25 July 2004, by Neo Rebus
34 // Added OPTIONS line to notecard format.
35 // Added BASEPORTERS option for compatibility with PortRingCreator.
36 // version 1.0.1, 25 July 2004, by Neo Rebus
37 // New version of f_TeleportTo, that only lifts up when necessary.
38 // version 1.0.0, 24 July 2004, by Neo Rebus
39 // First version. Only works inside a single sim.
40 //
41 ////////////////////////////////////////////////////////////////////////
42 //
43 // A NOTE ABOUT VARIABLE NAMES
44 //
45 // I use a form of "polish notation", where variable names are prefixed
46 // by their scope and type. The first letter of a variable name is its
47 // scope:
48 //
49 // p - parameter (a global that is set by the program maintainer and
50 // referenced but not changed by the program itself)
51 // g - global
52 // f - function
53 // s - state (a global that is only used in a particular state)
54 // l - local
55 // a - argument (in the formal argument list for a function)
56 //
57 // The second letter is the variable's type:
58 //
59 // b - boolean (an integer that holds TRUE or FALSE)
60 // f - float
61 // i - integer
62 // r - rotation
63 // s - string
64 // v - vector
65 // x - list ('x' is used instead of 'l' to avoid llXYZ names)
66 // _ - void (only for functions)
67 //
68 // The rest of the name is in MultipleCaps notation.
69 //
70 ////////////////////////////////////////////////////////////////////////
71 //
72 // CONSTANTS
73 //
74 // cxHeadingToRotation
75 // A list used to translate a heading to a rotation
76
77 list cxHeadingToRotation = [
78 "E", <0.00000, 0.00000, 0.00000, 1.00000>,
79 "ENE", <0.00000, 0.00000, 0.19509, 0.98079>,
80 "NE", <0.00000, 0.00000, 0.38268, 0.92388>,
81 "NNE", <0.00000, 0.00000, 0.55557, 0.83147>,
82 "N", <0.00000, 0.00000, 0.70711, 0.70711>,
83 "NNW", <0.00000, 0.00000, 0.83147, 0.55557>,
84 "NW", <0.00000, 0.00000, 0.92388, 0.38268>,
85 "WNW", <0.00000, 0.00000, 0.98079, 0.19509>,
86 "W", <0.00000, 0.00000, 1.00000, -0.00000>,
87 "WSW", <0.00000, 0.00000, 0.98078, -0.19509>,
88 "SW", <0.00000, 0.00000, 0.92388, -0.38268>,
89 "SSW", <0.00000, 0.00000, 0.83147, -0.55557>,
90 "S", <0.00000, 0.00000, 0.70711, -0.70711>,
91 "SSE", <0.00000, 0.00000, 0.55557, -0.83147>,
92 "SE", <0.00000, 0.00000, 0.38268, -0.92388>,
93 "ESE", <0.00000, 0.00000, 0.19509, -0.98078>
94 ] ;
95
96 ////////////////////////////////////////////////////////////////////////
97 //
98 // PARAMETERS
99 //
100 // (none)
101
102 ////////////////////////////////////////////////////////////////////////
103 //
104 // GLOBAL VARIABLES
105 //
106 // gsNotecardName
107 // The name of the notecard we're parsing.
108 //
109 // giNotecardLine
110 // The line number in the notecard we're parsing.
111 //
112 // gxPortRingInfo
113 // A list of:
114 // string porterBackName
115 // string porterForwardName
116 // string porterBaseName
117 // float porterSpacing
118 //
119 // gxPortRingStations
120 // A list of:
121 // vector baseLocation
122 // rotation baseRotation
123 // vector stationLocation
124 // rotation stationRotation
125 // ... add'l stations ...
126 //
127 // gxOptions
128 // A list of:
129 // string optionName
130 // string optionValue
131 // string possibleValues
132 // Initialized to the option names and default option values.
133 // option names must be in all caps and start with a ",".
134 // possibleValues is a CSV of the possible values. If empty,
135 // any value is allowed.
136 //
137 // gxLocations
138 // A refactored form of gxPortRingInfo and gxPortRingStations; this
139 // is a list of:
140 // string porterName
141 // vector stationLocation
142 // ...
143 //
144 // giLocationIndex
145 // Holds the current index into gxLocations as we're travelling around.
146 //
147 // gvStartLocation
148 // Where we want to return to when we're done.
149
150 string gsNotecardName ;
151
152 integer giNotecardLine ;
153
154 list gxPortRingInfo ;
155 list gxPortRingStations ;
156
157 list gxOptions = [
158 ",BASEPORTERS", "FIRSTONLY", "FIRSTONLY,FIRSTANDLAST,ALL" ,
159 ",RINGSTYLE", "LINEAR", "LINEAR,LOOP"
160 ] ;
161
162 list gxLocations ;
163 integer giLocationIndex ;
164 vector gvStartLocation ;
165
166 ////////////////////////////////////////////////////////////////////////
167 //
168 // FUNCTIONS
169 //
170
171 ////////////////////////////////////////////////////////////////////////
172 //
173 // f_TeleportTo(vector avDestination)
174 // teleport to avDestination, in the same sim as the object.
175 //
176 // record PHANTOM status, and set PHANTOM to true.
177 // Move UP to 250m, move to avDestination (at 250m), then move down
178 // to a height above gronud equal to avDestination's Z value.
179
180 f_TeleportTo(vector avDestination)
181 {
182 integer liOldPhantom = llGetStatus(STATUS_PHANTOM);
183 llSetStatus(STATUS_PHANTOM, TRUE);
184
185 vector lvTemp;
186 vector lvDest;
187 float lfHeight;
188
189 lvDest = avDestination;
190 lvDest.z = 0;
191 lvTemp = llGetPos();
192 lfHeight = lvTemp.z;
193 lvTemp.z = 0;
194
195 while(llVecDist(lvTemp, lvDest) > 0.1)
196 {
197 vector lvDelta = lvDest - lvTemp;
198 if(llVecMag(lvDelta) > 8)
199 {
200 lvDelta = llVecNorm(lvDelta) * 8;
201 }
202 if(llGround(lvDelta) > (lfHeight - 1.0))
203 {
204 lfHeight = llGround(lvDelta) + 1.0;
205 } else {
206 lvTemp += lvDelta ;
207 }
208 llSetPos( <lvTemp.x, lvTemp.y, lfHeight> );
209 }
210
211 lvDest = avDestination;
212 lvDest.z += llGround(ZERO_VECTOR);
213
214 while(llVecDist(llGetPos(), lvDest) > 0.1)
215 {
216 llSetPos(lvDest);
217 }
218
219 llSetStatus(STATUS_PHANTOM, liOldPhantom);
220 }
221
222 ////////////////////////////////////////////////////////////////////////
223 //
224 // Default state:
225 //
226 // Immediately switch to state WaitingForNotecard.
227
228 default
229 {
230
231 on_rez(integer liStartCode)
232 {
234 }
235
237 {
239 }
240
241 run_time_permissions(integer aiPermissions)
242 {
243 if(aiPermissions & PERMISSION_CHANGE_LINKS)
244 {
245 state WaitingForNotecard ;
246 } else {
247 llSay(0, "Cannot run without PERMISSION_CHANGE_LINKS");
249 }
250 }
251
252 }
253
254 ////////////////////////////////////////////////////////////////////////
255 //
256 // WaitingForNotecard state:
257 //
258 // on changed(), if CHANGED_INVENTORY, check if we have a notecard.
259 // if so, get the notecard name and switch to ParsingNotecard state.
260
261 state WaitingForNotecard
262 {
263 on_rez(integer liStartCode)
264 {
266 }
267
268 changed(integer aiWhat)
269 {
270 if(aiWhat == CHANGED_INVENTORY)
271 {
273 if(liNotecardCount > 0)
274 {
275 gsNotecardName = llGetInventoryName(INVENTORY_NOTECARD, liNotecardCount - 1);
276 state ParsingNotecard ;
277 }
278 }
279 }
280 }
281
282 ////////////////////////////////////////////////////////////////////////
283 //
284 // ParsingNotecard state:
285 //
286 // On entry, read the next notecard line.
287 // On exit, delete the notecard.
288 //
289 // On dataserver, fetch the line. If EOF, switch to state
290 // CreatingPortRing. If not blank or comment, parse the information
291 // out and add it to the gxPortRingInfo list.
292
293 state ParsingNotecard
294 {
295 on_rez(integer liStartCode)
296 {
298 }
299
301 {
302 llWhisper(0, "Parsing notecard " + gsNotecardName);
303 gxPortRingInfo = [ ] ;
304 gxPortRingStations = [ ] ;
305 llGetNotecardLine(gsNotecardName, 0);
306 giNotecardLine = 1;
307 llSetTimerEvent(10.0);
308 }
309
311 {
312 llSetTimerEvent(0.0);
313 llRemoveInventory(gsNotecardName);
314 }
315
316 timer()
317 {
318 llWhisper(0, "Still parsing...");
319 }
320
321 dataserver(key akRequestID, string asLine)
322 {
323 string lsError = "";
324
325 if(asLine == EOF)
326 {
327 state RetrievingPortRing;
328 }
329
330 if((asLine != "") && (llGetSubString(asLine, 0, 1) != "//"))
331 {
332 list lxLineInfo = llCSV2List(asLine);
333 string lsLineType = llList2String(lxLineInfo, 0);
334 if("PORTERS" == lsLineType)
335 {
336 if(llGetListLength(gxPortRingInfo) != 0)
337 {
338 lsError = "Invalid notecard format - only one PORTERS line allowed";
339 } else {
340 gxPortRingInfo += llList2List(lxLineInfo, 1, 3);
341 gxPortRingInfo += [ (float)llList2String(lxLineInfo, 4) ];
342 }
343 } else if("OPTIONS" == lsLineType)
344 {
345 integer liNumOptions = llGetListLength(lxLineInfo) - 1;
346 integer i;
347 for (i = 1; i <= liNumOptions; i++)
348 {
349 string lsOptionName = llList2String(lxLineInfo, i);
350 string lsOptionValue;
351 integer liIndex = llSubStringIndex(lsOptionName, "=");
352 if(liIndex > -1)
353 {
354 lsOptionValue = llGetSubString(lsOptionName, liIndex + 1, -1);
355 lsOptionName = llGetSubString(lsOptionName, 0, liIndex - 1);
356 } else {
357 lsOptionValue = "";
358 }
359 lsOptionName = llToUpper(lsOptionName);
360 lsOptionValue = llToUpper(lsOptionValue);
361 liIndex = llListFindList( gxOptions, [ "," + lsOptionName ] );
362 if(liIndex >= 0)
363 {
364 list lxAllowedValues = llCSV2List( llList2String(gxOptions, liIndex + 2) );
365 if("" == lsOptionValue)
366 {
367 lsOptionValue = llList2String(lxAllowedValues, 0);
368 }
369 if((llGetListLength(lxAllowedValues) == 0) || (llListFindList(lxAllowedValues, [lsOptionValue]) > -1))
370 {
371 gxOptions = llListInsertList( llDeleteSubList(gxOptions, liIndex + 1, liIndex + 1), [ lsOptionValue ], liIndex + 1);
372 } else {
373 lsError = "Invalid notecard format - invalid value " + lsOptionValue + " for option " + lsOptionName;
374 }
375 } else {
376 lsError = "Invalid notecard format - unknown option " + lsOptionName;
377 }
378 }
379 } else if("BASE" == lsLineType)
380 {
381 if(llGetListLength(gxPortRingInfo) == 0)
382 {
383 lsError = "Invalid notecard format - first entry must be PORTERS";
384 } else if(llGetListLength(gxPortRingStations) != 0)
385 {
386 lsError = "Invalid notecard format - only one BASE line allowed";
387 } else {
388 vector lvPosition = (vector)(llList2String(lxLineInfo, 1));
389 string lsHeading = llList2String(lxLineInfo, 2);
390 integer liIdx = llListFindList(cxHeadingToRotation, [ lsHeading ]);
391 if(liIdx < 0)
392 {
393 lsError = "Invalid notecard format - unknown heading " + lsHeading;
394 } else {
395 gxPortRingStations += [
396 lvPosition,
397 llList2Rot(cxHeadingToRotation, liIdx + 1)
398 ] ;
399 }
400 }
401 } else if("STATION" == lsLineType)
402 {
403 if(llGetListLength(gxPortRingInfo) == 0)
404 {
405 lsError = "Invalid notecard format - first entry must be PORTERS";
406 } else if(llGetListLength(gxPortRingStations) == 0)
407 {
408 lsError = "Invalid notecard format - BASE must occur before STATION lines";
409 } else {
410 vector lvPosition = (vector)(llList2String(lxLineInfo, 1));
411 string lsHeading = llList2String(lxLineInfo, 2);
412 integer liIdx = llListFindList(cxHeadingToRotation, [ lsHeading ]);
413 if(liIdx < 0)
414 {
415 lsError = "Invalid notecard format - unknown heading " + lsHeading;
416 } else {
417 gxPortRingStations += [
418 lvPosition,
419 llList2Rot(cxHeadingToRotation, liIdx + 1)
420 ] ;
421 }
422 }
423 } else {
424 lsError = "Invalid notecard format - found unknown line type " + lsLineType;
425 }
426 }
427
428 if(lsError != "")
429 {
430 llSay(0, "ERROR: " + lsError);
431 llSay(0, (string)giNotecardLine + ": " + asLine);
432 state WaitingForNotecard ;
433 } else {
434 llGetNotecardLine(gsNotecardName, giNotecardLine);
435 giNotecardLine += 1;
436 }
437 }
438
439 }
440
441 ////////////////////////////////////////////////////////////////////////
442 //
443 // RetrievingPortRing state:
444 //
445
446 state RetrievingPortRing
447 {
448 on_rez(integer liStartCode)
449 {
451 }
452
454 {
455 llWhisper(0, "Retrieving PortRing...");
456
457 llSetRot( <0,0.707,0,0.707> );
458
459 integer i;
460 integer liNumStations = (llGetListLength(gxPortRingStations) / 2) - 1;
461 vector lvLocation;
462 rotation lrRotation;
463 string lsBackPorter;
464 string lsForwardPorter;
465 string lsBasePorter;
466
467 lsBackPorter = llList2String(gxPortRingInfo, 0);
468 lsForwardPorter = llList2String(gxPortRingInfo, 1);
469 lsBasePorter = llList2String(gxPortRingInfo, 2);
470
471 // then create stations
472 for (i = 0; i <= liNumStations; i++)
473 {
474 lvLocation = llList2Vector(gxPortRingStations, i * 2);
475 lrRotation = llList2Rot(gxPortRingStations, i * 2 + 1);
476
477 gxLocations += [ lsBackPorter, lvLocation, lsForwardPorter, lvLocation, lsBasePorter, lvLocation ] ;
478 }
479
480 gvStartLocation = llGetPos() ;
481 gvStartLocation.z = liNumStations + 2;
482 giLocationIndex = 0;
483 llSetTimerEvent(1.0);
484 }
485
486 timer()
487 {
488 llSetTimerEvent(0.0);
489
490 if(giLocationIndex < llGetListLength(gxLocations))
491 {
492 float lfDist = (giLocationIndex/6) + 1;
493 float lfSpacing = llList2Float(gxPortRingInfo, 3);
494 f_TeleportTo(llList2Vector(gxLocations, giLocationIndex + 1) + <0,0,lfDist>);
495
497 llList2String(gxLocations, giLocationIndex),
499 SCRIPTED|PASSIVE|ACTIVE|AGENT,
500 llVecMag( <0, lfDist+lfSpacing, 2*lfSpacing> ),
501 PI
502 );
503 giLocationIndex += 2;
504 } else {
505 f_TeleportTo(gvStartLocation);
506 }
507 }
508
509 no_sensor()
510 {
511 llSetTimerEvent(1.0);
512 }
513
514 sensor(integer num)
515 {
516 integer i;
517 for (i=0; i<num; i++)
518 {
520 }
521 llSetTimerEvent(1.0);
522 }
523
524 }
525 // END //

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