Multi-vehicle script.lsl 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // :SHOW:
  2. // :CATEGORY:Tour
  3. // :NAME:OpenSim Tour Car
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:
  6. // :CREATED:2015-02-25 22:55:43
  7. // :EDITED:2015-02-25 21:55:43
  8. // :ID:1040
  9. // :NUM:1722
  10. // :REV:1
  11. // :WORLD:Opensim or Secondlife// :DESCRIPTION:
  12. // :DESCRIPTION:
  13. // Opensim Tour Boat
  14. // :CODE:
  15. // Tour car prim for Opensim - can switch the vehicle while riding
  16. // Put a unique name in the cars prims for each type.
  17. integer _debug = 0;
  18. integer REZ = 3454; // shouts Rex on this channel so a rezzer can produce another car, as this one will die
  19. float INTERVAL = 0.5; // How often to check for progress
  20. float TOLERANCE = 2; // how close to the destination we have to get
  21. float SPEED = 8.0; // speed of vehicle
  22. vector TARGET = <0,0,0>; // sit position on the root prim. Ste this to <0,0,0> if you want to not to be able to sit on the base
  23. vector ROT = <0,0,0>; // and the rotation, if they sit
  24. list lCoordinate;
  25. list lRotation ;
  26. list lText;
  27. list lPrim;
  28. // notecard reading
  29. integer iIndexLines;
  30. integer i;
  31. string NOTECARD = "Route"; // the notecard for configuring
  32. key kNoteCardLines; // the key of the notecard
  33. key kGetIndexLines; // the key of the current line
  34. integer count = 0;
  35. vector TargetLocation;
  36. rotation TargetRotation;
  37. Switch(string whichPrim)
  38. {
  39. integer n = llGetNumberOfPrims();
  40. integer i;
  41. for ( i = 1; i < n; i++) {
  42. if (llGetLinkName(i) == whichPrim) {
  43. llSetLinkAlpha(i,1.0,ALL_SIDES);
  44. } else {
  45. llSetLinkAlpha(i,0,ALL_SIDES); // 0 = transparent
  46. }
  47. }
  48. }
  49. Goto()
  50. {
  51. if (_debug)
  52. llOwnerSay("Looking at Target Location = " + (string) TargetLocation);
  53. vector ownPosition = llGetPos();
  54. float dist = llVecDist(ownPosition, TargetLocation);
  55. float rate = dist / SPEED;
  56. rotation ownRotation = llGetRot();
  57. llSetKeyframedMotion(
  58. [(TargetLocation - ownPosition) + <0.0, 0.0, -.5> * TargetRotation,
  59. NormRot(TargetRotation/ownRotation), rate],
  60. []);
  61. }
  62. rotation NormRot(rotation Q)
  63. {
  64. float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
  65. return
  66. <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
  67. }
  68. integer locationLength;
  69. string strip( string str)
  70. {
  71. string out;
  72. integer i;
  73. //llOwnerSay("str = " + str);
  74. for ( ; i < llStringLength(str); i++)
  75. {
  76. out += llGetSubString(str,i,i);
  77. out = llStringTrim(out, STRING_TRIM);
  78. //llOwnerSay("out = " + out + " at " + (string) i);
  79. }
  80. return out;
  81. }
  82. string Getline(list Input, integer line)
  83. {
  84. return strip(llList2String(Input, line));
  85. }
  86. default
  87. {
  88. on_rez(integer param)
  89. {
  90. llResetScript();
  91. }
  92. changed( integer change )
  93. {
  94. if (change & CHANGED_INVENTORY)
  95. {
  96. llResetScript();
  97. }
  98. }
  99. state_entry()
  100. {
  101. llSetLinkPrimitiveParamsFast(LINK_ROOT,
  102. [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX,
  103. PRIM_LINK_TARGET, LINK_ALL_CHILDREN,
  104. PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]);
  105. llSetCameraEyeOffset(<0, 5, 0> );
  106. llSetCameraAtOffset(<0, 0, 1>);
  107. rotation rot = llEuler2Rot(ROT * DEG_TO_RAD); // convert the degrees to radians, then convert that vector into a rotation, rot30x
  108. llSitTarget(TARGET, rot); // where they sit
  109. kNoteCardLines = llGetNumberOfNotecardLines(NOTECARD);
  110. kGetIndexLines = llGetNotecardLine(NOTECARD,0);
  111. llSay (0, "Tour guide initialising. Please wait.");
  112. }
  113. // read notecard on bootup
  114. dataserver(key queryid, string data)
  115. {
  116. vector TempLocation;
  117. if (queryid == kNoteCardLines)
  118. {
  119. iIndexLines = (integer) data;
  120. }
  121. if (queryid == kGetIndexLines)
  122. {
  123. if (data != EOF)
  124. {
  125. queryid = llGetNotecardLine(NOTECARD, i);
  126. list lLine = (llParseString2List(data, ["|"], []));
  127. if (_debug ) llOwnerSay("Line = " + llDumpList2String(lLine,":"));
  128. TempLocation = (vector) Getline(lLine,1);
  129. if (TempLocation != ZERO_VECTOR)
  130. {
  131. rotation Rot = (rotation) llList2String(lLine,2);
  132. string text = llList2String(lLine,3);
  133. string primName = llList2String(lLine,4);
  134. if (_debug) llOwnerSay((string)TempLocation);
  135. lCoordinate += [TempLocation];
  136. lRotation += [Rot];
  137. lText += [text];
  138. lPrim += [primName];
  139. locationLength = (llGetListLength(lCoordinate));
  140. integer InitPerCent = (integer) llRound(((float) locationLength / (float) iIndexLines) * 100);
  141. llSetText("Initialising... \n" + (string) InitPerCent + "%" , <1,1,1>, 1.0);
  142. if (InitPerCent == 100)
  143. {
  144. state Paused;
  145. }
  146. }
  147. else
  148. {
  149. state Paused;
  150. }
  151. i++;
  152. }
  153. kGetIndexLines = llGetNotecardLine(NOTECARD,i);
  154. // (_debug ) llOwnerSay("Got " + (string) i);
  155. }
  156. }
  157. state_exit()
  158. {
  159. llSetText("", <1,1,1>, 1.0);
  160. TargetLocation = llList2Vector(lCoordinate, 0); // Look at 0th
  161. TargetRotation = llList2Rot(lRotation, 0); // Look at 0th
  162. Goto();
  163. }
  164. }
  165. state Paused
  166. {
  167. state_entry()
  168. {
  169. llSay(0,"Ready");
  170. }
  171. link_message(integer sender,integer num,string msg, key id)
  172. {
  173. if (msg =="sit")
  174. {
  175. llWhisper(0,"Please stay seated. Waiting 10 seconds for a passenger");
  176. llSleep(10.0);
  177. llShout(REZ,"rez");
  178. state moving;
  179. }
  180. }
  181. on_rez(integer param)
  182. {
  183. llResetScript();
  184. }
  185. changed( integer change )
  186. {
  187. if (change & CHANGED_INVENTORY)
  188. {
  189. llResetScript();
  190. }
  191. }
  192. }
  193. state moving
  194. {
  195. state_entry()
  196. {
  197. if (_debug) llOwnerSay("State Moving entered, is pointing to target " + (string) TargetLocation );
  198. string SpeakThis = llList2String(lText, count);
  199. if (llStringLength(SpeakThis))
  200. llSay(0,SpeakThis);
  201. llSetTimerEvent(INTERVAL);
  202. }
  203. changed(integer change)
  204. {
  205. if (change & CHANGED_LINK)
  206. {
  207. key av = llAvatarOnSitTarget();
  208. //llWhisper(0,"Sit by " + (string) av);
  209. if (av == NULL_KEY) {
  210. state end;
  211. }
  212. }
  213. if (change & CHANGED_INVENTORY)
  214. {
  215. llResetScript();
  216. }
  217. }
  218. on_rez(integer param)
  219. {
  220. llResetScript();
  221. }
  222. timer()
  223. {
  224. if (llVecMag(llGetPos() - TargetLocation) <= TOLERANCE) {
  225. if (_debug) llOwnerSay("At location: " + (string) llGetPos());
  226. count ++;
  227. if (count >= locationLength) {
  228. state end;
  229. if (_debug) llOwnerSay("Restart: " + (string) TargetLocation);
  230. TargetLocation = llList2Vector(lCoordinate, 0); // Look at 0th
  231. TargetRotation = llList2Rot(lRotation, 0); // Look at 0th
  232. Goto();
  233. count = 0;
  234. } else {
  235. TargetLocation = llList2Vector(lCoordinate, count); // Look at nth
  236. TargetRotation = llList2Rot(lRotation, count); // Look at nth
  237. string SpeakThis = llList2String(lText, count);
  238. if (llStringLength(SpeakThis))
  239. llSay(0,SpeakThis);
  240. // if the last param is a name, change any prim by that name to be visible, and any others to be invidible.
  241. string whichPrim = llList2String(lPrim, count);
  242. if (whichPrim)
  243. Switch(whichPrim);
  244. Goto();
  245. if (_debug) llOwnerSay("New Target: " + (string) TargetLocation);
  246. }
  247. }
  248. }
  249. state_exit()
  250. {
  251. llSetTimerEvent(0);
  252. }
  253. }
  254. state end
  255. {
  256. state_entry()
  257. {
  258. llMessageLinked(LINK_SET,0,"DOOR OPEN","");
  259. llSetTimerEvent(0);
  260. key av = llAvatarOnSitTarget();
  261. if (av != NULL_KEY) {
  262. //llWhisper(0, llKey2Name(av) +", please go into the hotel and check in.");
  263. llUnSit(av);
  264. }
  265. llSetTimerEvent(60);
  266. }
  267. on_rez(integer param)
  268. {
  269. llResetScript();
  270. }
  271. timer()
  272. {
  273. llDie();
  274. }
  275. }