Tour.lsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. // :CATEGORY:Tour
  2. // :NAME:TourCopter
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:39:08
  6. // :ID:909
  7. // :NUM:1304
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // Tour
  12. // :CODE:
  13. // ______ _ ______ _ _
  14. // | ___| | | | ___| | | (_)
  15. // | |_ ___ _ __ __| | | |_ _ __ ___ __| | ___ _ __ ___ __
  16. // | _/ _ \ '__/ _` | | _| '__/ _ \/ _` |/ _ \ '__| \ \/ /
  17. // | || __/ | | (_| | | | | | | __/ (_| | __/ | | |> <
  18. // \_| \___|_| \__,_| \_| |_| \___|\__,_|\___|_| |_/_/\_\
  19. //
  20. // fred@mitsi.com
  21. // tour copter script
  22. //
  23. //Revisions:
  24. // 1/28/2010 initial release
  25. integer _debug = 0;
  26. integer ShoutChannel = 5;
  27. integer falling = 0; // flag to let us know in final state we are falling in free-fall
  28. // notecard readers
  29. key RequestStops;
  30. key GetIndexLines;
  31. // The database read from the note card
  32. list Line = [];
  33. list lCoordinate = [];
  34. list lDescriptions = [];
  35. list lSounds = [];
  36. list lCommands = [];
  37. list lLinks = [];
  38. integer IndexLines;
  39. integer i = 0;
  40. integer gCurrentRecord = 0; // the current record in the notecard
  41. integer locationLength;
  42. integer InitPerCent; // how far we have read in the notecard
  43. integer timeout = 0; // global timeout.. if the pysicas gets hosed from running into a solid object, this takes over and moves us no-physically.
  44. vector TargetLocation;
  45. float INTERVAL = .20; // seconds to move
  46. float DAMPING = .1; // .3
  47. string SpeakThis; // what is to be said
  48. string PlayThis; // what is to be said
  49. string ChatThis; // what is to be said
  50. string LinkThis; // what is to be said
  51. // Particle Script 0.5
  52. // Created by Ama Omega
  53. // 3-26-2004
  54. integer keystate = 0 ;
  55. // Life in seconds for the system to make particles
  56. integer flags;
  57. list sys;
  58. Look( vector target)
  59. {
  60. float mass = llGetMass()/2;
  61. float damp = mass/5;
  62. llLookAt(target, mass, damp); // 2,1, the damp could be smaller
  63. }
  64. // see if the pointer is past tghe end of memory
  65. integer EndCard()
  66. {
  67. return gCurrentRecord > (llGetListLength(lCoordinate) - 1);
  68. }
  69. // remove white space at begiinign and end
  70. string trim(string input)
  71. {
  72. //return llDumpList2String(llParseString2List(input, [" "], []), " ");
  73. return llStringTrim( input, STRING_TRIM );
  74. }
  75. // fetch next notecard entry
  76. GetNextRecord()
  77. {
  78. gCurrentRecord++;
  79. TargetLocation = (vector) llList2String(lCoordinate, gCurrentRecord);
  80. if (_debug) llOwnerSay("Moving: " + (string) TargetLocation);
  81. }
  82. updateParticles()
  83. {
  84. // Mask Flags - set to TRUE to enable
  85. integer glow = FALSE; // Make the particles glow
  86. integer bounce = FALSE; // Make particles bounce on Z plane of object
  87. integer interpColor = TRUE; // Go from start to end color
  88. integer interpSize = TRUE; // Go from start to end size
  89. integer wind = TRUE; // Particles effected by wind
  90. integer followSource = FALSE; // Particles follow the source
  91. integer followVel = FALSE; // Particles turn to velocity direction
  92. // Choose a pattern from the following:
  93. // PSYS_SRC_PATTERN_EXPLODE
  94. // PSYS_SRC_PATTERN_DROP
  95. // PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
  96. // PSYS_SRC_PATTERN_ANGLE_CONE
  97. // PSYS_SRC_PATTERN_ANGLE
  98. integer pattern = PSYS_SRC_PATTERN_EXPLODE;
  99. key target = "";
  100. // Particle paramaters
  101. float age = 5; // Life of each particle
  102. float maxSpeed = 1; // Max speed each particle is spit out at
  103. float minSpeed = 0.8; // Min speed each particle is spit out at
  104. string texture = "4f714019-c1cf-6b16-994f-44b217022f1a"; // Texture used for particles, default used if blank
  105. float startAlpha = 0.8; // Start alpha (transparency) value
  106. float endAlpha = 0.0; // End alpha (transparency) value
  107. vector startColor = <0.5,0.5,0.5>; // Start color of particles <R,G,B>
  108. vector endColor = <0,0,0>; // End color of particles <R,G,B> (if interpColor == TRUE)
  109. vector startSize = <1.01,1.01,5.0>; // Start size of particles
  110. vector endSize = <5.0,5.0,10.0>; // End size of particles (if interpSize == TRUE)
  111. vector push = <.2,0,3>; // Force pushed on particles
  112. // System paramaters
  113. float rate = 1; // How fast (rate) to emit particles
  114. float radius = 0.0; // Radius to emit particles for BURST pattern
  115. integer count = 40; // How many particles to emit per BURST
  116. float outerAngle = 0; // Outer angle for all ANGLE patterns
  117. float innerAngle = 0.1; // Inner angle for all ANGLE patterns
  118. vector omega = <0,0,0>; // Rotation of ANGLE patterns around the source
  119. float life = 0;
  120. flags = 0;
  121. if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
  122. if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
  123. if (interpColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
  124. if (interpSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
  125. if (wind) flags = flags | PSYS_PART_WIND_MASK;
  126. if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
  127. if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
  128. if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;
  129. sys = [ PSYS_PART_MAX_AGE,age,
  130. PSYS_PART_FLAGS,flags,
  131. PSYS_PART_START_COLOR, startColor,
  132. PSYS_PART_END_COLOR, endColor,
  133. PSYS_PART_START_SCALE,startSize,
  134. PSYS_PART_END_SCALE,endSize,
  135. PSYS_SRC_PATTERN, pattern,
  136. PSYS_SRC_BURST_RATE,rate,
  137. PSYS_SRC_ACCEL, push,
  138. PSYS_SRC_BURST_PART_COUNT,count,
  139. PSYS_SRC_BURST_RADIUS,radius,
  140. PSYS_SRC_BURST_SPEED_MIN,minSpeed,
  141. PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
  142. PSYS_SRC_TARGET_KEY,target,
  143. PSYS_SRC_INNERANGLE,innerAngle,
  144. PSYS_SRC_OUTERANGLE,outerAngle,
  145. PSYS_SRC_OMEGA, omega,
  146. PSYS_SRC_MAX_AGE, life,
  147. PSYS_SRC_TEXTURE, texture,
  148. PSYS_PART_START_ALPHA, startAlpha,
  149. PSYS_PART_END_ALPHA, endAlpha
  150. ];
  151. llParticleSystem(sys);
  152. }
  153. DoEffects()
  154. {
  155. SpeakThis = llList2String(lDescriptions, gCurrentRecord);
  156. PlayThis = llList2String(lSounds, gCurrentRecord);
  157. ChatThis = llList2String(lCommands, gCurrentRecord);
  158. LinkThis = llList2String(lLinks, gCurrentRecord);
  159. if (llStringLength(SpeakThis) > 1)
  160. llSay(0,SpeakThis);
  161. if (llStringLength(PlayThis) > 1)
  162. llPlaySound(PlayThis,1.0);
  163. if (llStringLength(ChatThis) > 1)
  164. {
  165. if (_debug) llWhisper(0,"Shouting on channel " + (string) ShoutChannel + " the message:" + LinkThis);
  166. llShout(ShoutChannel,"Shout message:" + ChatThis);
  167. }
  168. if (llStringLength(LinkThis) > 1)
  169. {
  170. if (_debug) llWhisper(0,"Link message:" + LinkThis);
  171. llMessageLinked(LINK_SET,0,LinkThis,NULL_KEY);
  172. }
  173. }
  174. string Getline(list Input, integer line)
  175. {
  176. return trim(llList2String(Input, line));
  177. }
  178. default_cam()
  179. {
  180. if (_debug) llOwnerSay("default_cam"); // say function name for debugging
  181. llClearCameraParams(); // reset camera to default
  182. }
  183. driving_cam()
  184. {
  185. llOwnerSay("driving_cam"); // say function name for debugging
  186. default_cam();
  187. llSetCameraParams([
  188. CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
  189. CAMERA_BEHINDNESS_ANGLE, 45.0, // (0 to 180) degrees
  190. CAMERA_BEHINDNESS_LAG, 0.5, // (0 to 3) seconds
  191. CAMERA_DISTANCE, 10.0, // ( 0.5 to 10) meters
  192. //CAMERA_FOCUS, <0.0,0.0,5.0>, // region relative position
  193. CAMERA_FOCUS_LAG, 1.0 , // (0 to 3) seconds
  194. CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
  195. CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
  196. CAMERA_PITCH, 20.0, // (-45 to 80) degrees
  197. //CAMERA_POSITION, <0.0,0.0,0.0>, // region relative position
  198. CAMERA_POSITION_LAG, 0.1, // (0 to 3) seconds
  199. CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
  200. CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
  201. CAMERA_FOCUS_OFFSET, <00.0,0.0,10.0> // <-10,-10,-10> to <10,10,10> meters
  202. ]);
  203. }
  204. spin_cam()
  205. {
  206. if (_debug) llOwnerSay("spin_cam"); // say function name for debugging
  207. llSetCameraParams([
  208. CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
  209. CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
  210. CAMERA_BEHINDNESS_LAG, 0.5, // (0 to 3) seconds
  211. //CAMERA_DISTANCE, 10.0, // ( 0.5 to 10) meters
  212. //CAMERA_FOCUS, <0.0,0.0,5.0>, // region relative position
  213. CAMERA_FOCUS_LAG, 0.05 , // (0 to 3) seconds
  214. CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
  215. CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
  216. CAMERA_PITCH, 30.0, // (-45 to 80) degrees
  217. //CAMERA_POSITION, <0.0,0.0,0.0>, // region relative position
  218. CAMERA_POSITION_LAG, 0.0, // (0 to 3) seconds
  219. CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
  220. CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
  221. CAMERA_FOCUS_OFFSET, <0.0,0.0,0.0> // <-10,-10,-10> to <10,10,10> meters
  222. ]);
  223. float i;
  224. vector camera_position;
  225. for (i=0; i< TWO_PI; i+=.05)
  226. {
  227. camera_position = llGetPos() + <0.0, 10.0, 0.0> * llEuler2Rot(<0.0, 0.0, i>);
  228. llSetCameraParams([CAMERA_POSITION, camera_position]);
  229. }
  230. default_cam();
  231. }
  232. ////////////////////
  233. default
  234. {
  235. on_rez(integer param)
  236. {
  237. llResetScript();
  238. }
  239. changed( integer change )
  240. {
  241. if (change & CHANGED_INVENTORY)
  242. {
  243. llResetScript();
  244. }
  245. }
  246. state_entry()
  247. {
  248. llParticleSystem([]);
  249. llSitTarget(ZERO_VECTOR,ZERO_ROTATION); // remove the sit, the pilot seat takes care of that
  250. llSetStatus(STATUS_DIE_AT_EDGE | STATUS_PHYSICS, FALSE);
  251. llMessageLinked(LINK_SET,0,"stop",NULL_KEY);
  252. llMessageLinked(LINK_SET,0,"off",NULL_KEY);
  253. llSetSoundQueueing(TRUE);
  254. llSetBuoyancy(1);
  255. RequestStops = llGetNumberOfNotecardLines("Initialize");
  256. GetIndexLines = llGetNotecardLine("Initialize",0);
  257. llSay (0, "Tour controller is initializing. Please wait.");
  258. if(llAvatarOnSitTarget() != NULL_KEY) // if someone is sitting
  259. llUnSit(llAvatarOnSitTarget()); // unsit him
  260. }
  261. dataserver(key queryid, string data)
  262. {
  263. if (queryid == RequestStops)
  264. {
  265. IndexLines = (integer) data;
  266. }
  267. if (queryid == GetIndexLines)
  268. {
  269. if (data != EOF)
  270. {
  271. queryid = llGetNotecardLine("Initialize", i);
  272. Line = (llParseString2List(data, ["|"], []));
  273. // if (_debug ) llOwnerSay("Line = " + llDumpList2String(Line,":"));
  274. //string sComment = Getline(Line,0);
  275. float X = (float)Getline(Line,1);
  276. float Y = (float)Getline(Line,2);
  277. float Z = (float)Getline(Line,3);
  278. string Msg = Getline(Line,4);
  279. string sUUID = Getline(Line,5);
  280. string sCommand = Getline(Line,6);
  281. string sLink = Getline(Line,7);
  282. vector TempLocation;
  283. TempLocation.x = X;
  284. TempLocation.y = Y;
  285. TempLocation.z = Z;
  286. lCoordinate = lCoordinate + [TempLocation];
  287. lDescriptions = lDescriptions + [Msg];
  288. lSounds += [sUUID];
  289. lCommands += [sCommand];
  290. lLinks += [sLink];
  291. locationLength = (llGetListLength(lCoordinate));
  292. InitPerCent = (integer) llRound(((float) locationLength / (float) IndexLines) * 100);
  293. llSetText("Initializing... \n" + (string) InitPerCent + "%" , <1,1,1>, 1.0);
  294. if (InitPerCent == 100)
  295. {
  296. state Paused;
  297. }
  298. i++;
  299. }
  300. GetIndexLines = llGetNotecardLine("Initialize",i);
  301. //if (_debug ) llOwnerSay("Got " + (string) i);
  302. }
  303. }
  304. touch_start(integer total_number)
  305. {
  306. integer check = llGetListLength(lCoordinate);
  307. if (_debug) llOwnerSay("List is " + (string) check + " destinations long");
  308. if (check >= IndexLines)
  309. state Paused;
  310. if (check < IndexLines)
  311. llSay(0, "Waiting for the tour pilot, please wait a moment...");
  312. }
  313. state_exit()
  314. {
  315. llSetText("", <1,1,1>, 1.0);
  316. if (_debug)
  317. llOwnerSay("First Target Location = " + (string) TargetLocation);
  318. }
  319. }
  320. state Paused
  321. {
  322. state_entry()
  323. {
  324. llSay(0,"Ready for the next passenger.");
  325. }
  326. link_message(integer sender, integer num, string str, key id)
  327. {
  328. if (str =="pilot" and key != NULL_KEY)
  329. {
  330. llTriggerSound("7Clearedfortakeoff",1.0);
  331. llSleep(3.0); // time for it to start playing cause next line gets loud!
  332. llMessageLinked(LINK_SET,0,"start",NULL_KEY);
  333. llMessageLinked(LINK_SET,0,"on",NULL_KEY);
  334. llMessageLinked(LINK_SET, (integer) 100, "throttle", NULL_KEY);
  335. llSleep(10.0);
  336. llMessageLinked(LINK_SET,0,"displayon",NULL_KEY);
  337. llSleep(5.0);
  338. TargetLocation = (vector) llList2String(lCoordinate, 0); // Look at 0th vector
  339. state MoveToTarget;
  340. }
  341. }
  342. }
  343. state MoveToTarget
  344. {
  345. state_entry()
  346. {
  347. if (_debug) llOwnerSay("State MoveToTarget entered, is pointing to target " + (string) TargetLocation );
  348. llSetStatus(STATUS_PHYSICS, TRUE);
  349. llSetTimerEvent(INTERVAL);
  350. Look(TargetLocation);
  351. }
  352. timer()
  353. {
  354. timeout = timeout + 1;
  355. if (timeout > 60/INTERVAL ) // Time Out to contingency in one minute, if we cannot get ther by then, we go non-physical
  356. {
  357. llOwnerSay("Copter is stuck at " + (string) llGetPos());
  358. state end;
  359. }
  360. if (llVecDist(TargetLocation, <0,0,0>) < 1)
  361. {
  362. llOwnerSay("wtf? Copter is headed for <0,0,0>!");
  363. state end;
  364. }
  365. float x = llVecMag(llGetPos() - TargetLocation);
  366. if (_debug) llSetText("Timeout... \n" + (string) timeout + "\n" + (string) x, <1,1,1>, 1.0);
  367. vector vPos = llGetPos();
  368. vector vMoveBig = TargetLocation - vPos;
  369. float fDistance = llVecMag(vMoveBig);
  370. if (fDistance > 10)// distance is greater than llMoveToTarget can handle, so just 10m toward destination
  371. {
  372. vector vNewPos = vPos + llVecNorm(vMoveBig)*1;
  373. llMoveToTarget(vNewPos,DAMPING);
  374. }
  375. else
  376. {
  377. llMoveToTarget(TargetLocation,DAMPING);
  378. if (_debug) llOwnerSay("At destination: " + (string) llGetPos());
  379. DoEffects();
  380. GetNextRecord();
  381. if (EndCard())
  382. state end;
  383. Look(TargetLocation); // Look at target
  384. }
  385. }
  386. state_exit()
  387. {
  388. llSetTimerEvent(0);
  389. //llSetStatus(STATUS_PHYSICS, FALSE);
  390. timeout = 0;
  391. }
  392. }
  393. state setposition //contingency
  394. {
  395. state_entry()
  396. {
  397. llSetPrimitiveParams([PRIM_PHYSICS, FALSE]);
  398. llSetTimerEvent(INTERVAL);
  399. }
  400. changed( integer change )
  401. {
  402. if (change & CHANGED_INVENTORY)
  403. {
  404. llResetScript();
  405. }
  406. }
  407. timer()
  408. {
  409. if (llVecMag(llGetPos() - TargetLocation) > .49999)
  410. {
  411. if (_debug ) llOwnerSay("setposition llLookAt: " + (string) TargetLocation);
  412. llSetPos((llVecNorm(TargetLocation - llGetPos()) * 0.5) + llGetPos());
  413. Look(TargetLocation); // Look at targe
  414. }
  415. if (llVecMag(llGetPos() - TargetLocation) < .49999)
  416. {
  417. if (_debug)
  418. llOwnerSay("At location: " + (string) llGetPos());
  419. llSetPrimitiveParams([PRIM_PHYSICS, TRUE]);
  420. GetNextRecord();
  421. if (EndCard())
  422. state end;
  423. }
  424. }
  425. state_exit()
  426. {
  427. llSetTimerEvent(0);
  428. }
  429. }
  430. state end
  431. {
  432. state_entry()
  433. {
  434. updateParticles(); // smoke on
  435. spin_cam();
  436. if (_debug) llOwnerSay("State MoveToTarget entered, is pointing to target " + (string) TargetLocation );
  437. // jerk the copter around by pointing nose down at 45 degree angle
  438. vector mypos = llGetPos();
  439. mypos.z -=10;
  440. mypos.y -=10;
  441. mypos.x -=10;
  442. Look(mypos);
  443. timeout = 0;
  444. llSetTimerEvent(INTERVAL);
  445. }
  446. timer()
  447. {
  448. timeout = timeout + 1;
  449. if (llVecMag(llGetPos() - TargetLocation) > .49999)
  450. {
  451. if (timeout > 30/INTERVAL) // Time Out to contingency
  452. {
  453. llSetTimerEvent(0);
  454. spin_cam();
  455. if(llAvatarOnSitTarget() != NULL_KEY) // if someone is sitting
  456. llUnSit(llAvatarOnSitTarget()); // unsit him
  457. llSetPrimitiveParams([PRIM_TEMP_ON_REZ,TRUE]);
  458. }
  459. llMoveToTarget((llVecNorm(TargetLocation - llGetPos()) * 1) + llGetPos(), DAMPING);
  460. }
  461. if (llVecMag(llGetPos() - TargetLocation) < .49999)
  462. {
  463. falling ++;
  464. llMessageLinked(LINK_SET,0,"bomb",NULL_KEY); // bombs away
  465. }
  466. if (falling)
  467. {
  468. llStopLookAt();
  469. llStopMoveToTarget();
  470. llSetBuoyancy(0.8); // blades are spinning, so we float a bit
  471. if (timeout % 51 == 0) // 10 seconds
  472. {
  473. spin_cam();
  474. llMessageLinked(LINK_SET,0,"fire",NULL_KEY);
  475. llMessageLinked(LINK_SET,0,"stop",NULL_KEY);
  476. }
  477. if (timeout > 100) // 20 seconds
  478. {
  479. llSetTimerEvent(0);
  480. llMessageLinked(LINK_SET,0,"bomb",NULL_KEY);
  481. spin_cam();
  482. if(llAvatarOnSitTarget() != NULL_KEY) // if someone is sitting
  483. llUnSit(llAvatarOnSitTarget()); // unsit him
  484. llSetPrimitiveParams([PRIM_TEMP_ON_REZ,TRUE]);
  485. llSetBuoyancy(0.8); // blades are spinning
  486. }
  487. }
  488. }
  489. }