tour guide 2.2.lsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. integer _debug = 0;
  2. integer REZ = 3454;
  3. vector TARGET = <-1.0,0,0.02>;
  4. vector ROT = <0, -90, 0>;
  5. list Line = [];
  6. list lCoordinate = [];
  7. list lDescriptions = [];
  8. list lSounds = [];
  9. list lCommands = [];
  10. list lLinks = [];
  11. // notecard reading
  12. integer iIndexLines;
  13. string NOTECARD = "Route"; // the notecard for configuring
  14. key kNoteCardLines; // the key of the notecard
  15. key kGetIndexLines; // the key of the current line
  16. integer i = 0;
  17. integer count = 0;
  18. integer timeout = 0;
  19. float DAMPING = .2; // .3
  20. vector TargetLocation;
  21. float INTERVAL = .050; // seconds to move
  22. string SpeakThis; // what is to be said
  23. string PlayThis; // what is to be Played
  24. string strip( string str)
  25. {
  26. string out;
  27. integer i;
  28. //llOwnerSay("str = " + str);
  29. for ( ; i < llStringLength(str); i++)
  30. {
  31. out += llGetSubString(str,i,i);
  32. out = llStringTrim(out, STRING_TRIM);
  33. //llOwnerSay("out = " + out + " at " + (string) i);
  34. }
  35. return out;
  36. }
  37. string Getline(list Input, integer line)
  38. {
  39. return strip(llList2String(Input, line));
  40. }
  41. default
  42. {
  43. on_rez(integer param)
  44. {
  45. llResetScript();
  46. }
  47. changed( integer change )
  48. {
  49. if (change & CHANGED_INVENTORY)
  50. {
  51. // llResetScript();
  52. }
  53. }
  54. state_entry()
  55. {
  56. llSetAlpha(1.0,ALL_SIDES);
  57. llSetCameraEyeOffset(<0, 0, -5> );
  58. llSetCameraAtOffset(<0, 0, 1>);
  59. rotation rot = llEuler2Rot(ROT * DEG_TO_RAD); // convert the degrees to radians, then convert that vector into a rotation, rot30x
  60. llSitTarget(TARGET, rot); // where they sit
  61. llSetPrimitiveParams([PRIM_PHYSICS, FALSE]);
  62. llSetBuoyancy(1);
  63. //llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
  64. //llSetColor(<1,0,0>, ALL_SIDES);
  65. kNoteCardLines = llGetNumberOfNotecardLines(NOTECARD);
  66. kGetIndexLines = llGetNotecardLine(NOTECARD,0);
  67. llSay (0, "Tour guide initialising. Please wait.");
  68. }
  69. // read notecard on bootup
  70. dataserver(key queryid, string data)
  71. {
  72. vector TempLocation;
  73. if (queryid == kNoteCardLines)
  74. {
  75. iIndexLines = (integer) data;
  76. }
  77. if (queryid == kGetIndexLines)
  78. {
  79. if (data != EOF)
  80. {
  81. queryid = llGetNotecardLine(NOTECARD, i);
  82. list lLine = (llParseString2List(data, ["|"], []));
  83. //if (_debug ) llOwnerSay("Line = " + llDumpList2String(lLine,":"));
  84. float X = (float) Getline(lLine,1);
  85. if (X > 0)
  86. {
  87. float Y = (float)Getline(lLine,2);
  88. float Z = (float)Getline(lLine,3);
  89. string Msg = llList2String(lLine,4);
  90. string sUUID = Getline(lLine,5);
  91. string sCommand = Getline(lLine,6);
  92. string sLink = Getline(lLine,7);
  93. TempLocation.x = X;
  94. TempLocation.y = Y;
  95. TempLocation.z = Z;
  96. if (_debug) llOwnerSay((string)TempLocation);
  97. lCoordinate = lCoordinate + [TempLocation];
  98. lDescriptions = lDescriptions + [Msg];
  99. lSounds += [sUUID];
  100. lCommands += [sCommand];
  101. lLinks += [sLink];
  102. //TempDescription = llStringTrim( TempDescription, STRING_TRIM );
  103. //if (_debug ) llOwnerSay("Description = " + Msg);
  104. integer locationLength = (llGetListLength(lCoordinate));
  105. integer InitPerCent = (integer) llRound(((float) locationLength / (float) iIndexLines) * 100);
  106. llSetText("Initialising... \n" + (string) InitPerCent + "%" , <1,1,1>, 1.0);
  107. if (InitPerCent == 100)
  108. {
  109. state Paused;
  110. }
  111. }
  112. else
  113. {
  114. state Paused;
  115. }
  116. i++;
  117. }
  118. kGetIndexLines = llGetNotecardLine(NOTECARD,i);
  119. // (_debug ) llOwnerSay("Got " + (string) i);
  120. }
  121. }
  122. touch_start(integer total_number)
  123. {
  124. integer check = llGetListLength(lCoordinate);
  125. if (_debug)
  126. llOwnerSay("List is " + (string) check + " destinations long");
  127. if (check >= iIndexLines)
  128. {
  129. state Paused;
  130. }
  131. if (check < iIndexLines)
  132. {
  133. llSay(0, "Hang on a sec, still initialising...");
  134. }
  135. }
  136. state_exit()
  137. {
  138. llSetText("", <1,1,1>, 1.0);
  139. TargetLocation = (vector) llList2String(lCoordinate, 0); // Look at 0th
  140. if (_debug)
  141. llOwnerSay("Looking at Target Location = " + (string) TargetLocation);
  142. }
  143. }
  144. state Paused
  145. {
  146. state_entry()
  147. {
  148. llSay(0,"Ready");
  149. }
  150. link_message(integer sender,integer num,string msg, key id)
  151. {
  152. if (msg =="sit")
  153. {
  154. llWhisper(0,"Please stay seated. Waiting 10 seconds for a passenger");
  155. llSleep(10.0);
  156. llShout(REZ,"rezswan");
  157. state moving;
  158. }
  159. }
  160. changed(integer change)
  161. {
  162. if (change & CHANGED_INVENTORY)
  163. {
  164. llResetScript();
  165. }
  166. }
  167. }
  168. state moving
  169. {
  170. state_entry()
  171. {
  172. llSetPrimitiveParams([PRIM_PHYSICS, TRUE]);
  173. if (_debug) llOwnerSay("State Moving entered, is pointing to target " + (string) TargetLocation );
  174. llLookAt(TargetLocation, 2, 1);
  175. SpeakThis = llList2String(lDescriptions, count);
  176. if (_debug) llOwnerSay("Speaking:" + SpeakThis);
  177. if (llStringLength(SpeakThis) > 1)
  178. llSay(0,SpeakThis);
  179. PlayThis = llList2String(lSounds, count);
  180. if (_debug) llOwnerSay("Playing:" + PlayThis);
  181. if (llStringLength(PlayThis) > 1)
  182. llPlaySound(PlayThis,1.0);
  183. llSetTimerEvent(INTERVAL);
  184. }
  185. changed(integer change)
  186. {
  187. if (change & CHANGED_LINK)
  188. {
  189. key av = llAvatarOnSitTarget();
  190. //llWhisper(0,"Sit by " + (string) av);
  191. if (av) //evaluated as true if not NULL_KEY or invalid
  192. {
  193. state moving;
  194. }
  195. else
  196. {
  197. state end;
  198. }
  199. }
  200. if (change & CHANGED_INVENTORY)
  201. {
  202. // llResetScript();
  203. }
  204. }
  205. on_rez(integer param)
  206. {
  207. llResetScript();
  208. }
  209. timer()
  210. {
  211. timeout ++;
  212. if (timeout%20 == 0)
  213. llMessageLinked(LINK_SET,0,"FLAP","");
  214. if (_debug) llSetText("Timeout... \n" + (string) timeout, <1,1,1>, 1.0);
  215. if (llVecMag(llGetPos() - TargetLocation) > .49999)
  216. {
  217. if (timeout > 30/INTERVAL) // Time Out to contingency
  218. {
  219. if (_debug) llOwnerSay("Timeout!");
  220. state setposition;
  221. }
  222. llMoveToTarget((llVecNorm(TargetLocation - llGetPos()) * 1) + llGetPos(), DAMPING);
  223. }
  224. if (llVecMag(llGetPos() - TargetLocation) < .49999)
  225. {
  226. if (_debug) llOwnerSay("At location: " + (string) llGetPos());
  227. state speaking;
  228. }
  229. }
  230. state_exit()
  231. {
  232. llSetTimerEvent(0);
  233. timeout = 0;
  234. i = 0;
  235. }
  236. }
  237. state setposition //contingency
  238. {
  239. state_entry()
  240. {
  241. llSetPrimitiveParams([PRIM_PHYSICS, FALSE]);
  242. llSetTimerEvent(INTERVAL);
  243. }
  244. changed(integer change)
  245. {
  246. if (change & CHANGED_LINK)
  247. {
  248. key av = llAvatarOnSitTarget();
  249. //llWhisper(0,"Sit by " + (string) av);
  250. if (av) //evaluated as true if not NULL_KEY or invalid
  251. {
  252. llWhisper(0,"Please stay seated");
  253. }
  254. else
  255. {
  256. state end;
  257. }
  258. }
  259. if (change & CHANGED_INVENTORY)
  260. {
  261. // llResetScript();
  262. }
  263. }
  264. timer()
  265. {
  266. if (llVecMag(llGetPos() - TargetLocation) > .49999)
  267. {
  268. if (_debug ) llOwnerSay("setposition llLookAt: " + (string) TargetLocation);
  269. llSetPos((llVecNorm(TargetLocation - llGetPos()) * 0.5) + llGetPos());
  270. llLookAt(TargetLocation, 10, 10);
  271. }
  272. if (llVecMag(llGetPos() - TargetLocation) < .49999)
  273. {
  274. if (_debug)
  275. llOwnerSay("At location: " + (string) llGetPos());
  276. state speaking;
  277. }
  278. }
  279. state_exit()
  280. {
  281. llSetTimerEvent(0);
  282. }
  283. }
  284. state speaking
  285. {
  286. state_entry()
  287. {
  288. count ++;
  289. if (count > (iIndexLines - 1))
  290. state end;
  291. if (count <= (iIndexLines - 1))
  292. {
  293. TargetLocation = (vector) llList2String(lCoordinate, count);
  294. if (_debug) llOwnerSay("New Target: " + (string) TargetLocation);
  295. state moving;
  296. }
  297. }
  298. state_exit()
  299. {
  300. llSetTimerEvent(0);
  301. }
  302. }
  303. state end
  304. {
  305. state_entry()
  306. {
  307. llMessageLinked(LINK_SET,0,"SIT","");
  308. llSetAlpha(1.0,ALL_SIDES);
  309. llSetTimerEvent(0);
  310. llSetPrimitiveParams([PRIM_PHYSICS, FALSE]);
  311. key av = llAvatarOnSitTarget();
  312. if (av) {//evaluated as true if not NULL_KEY or invalid
  313. llWhisper(0, llKey2Name(av) +" thank you for taking the tour");
  314. llStopAnimation("sit knees up2");
  315. llUnSit(av);
  316. }
  317. llSay(0, "Tour stopped. It will disappear in one minute");
  318. llSetTimerEvent(60);
  319. }
  320. changed(integer change)
  321. {
  322. if (change & CHANGED_LINK)
  323. {
  324. key av = llAvatarOnSitTarget();
  325. //llWhisper(0,"Sit by " + (string) av);
  326. if (av) //evaluated as true if not NULL_KEY or invalid
  327. {
  328. llWhisper(0,"Please stay seated");
  329. state moving;
  330. }
  331. }
  332. if (change & CHANGED_INVENTORY)
  333. {
  334. // llResetScript();
  335. }
  336. }
  337. on_rez(integer param)
  338. {
  339. llResetScript();
  340. }
  341. timer()
  342. {
  343. llDie();
  344. }
  345. }