Whale prim Movement script.lsl 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // :CATEGORY:Blue Whale
  2. // :NAME:BlueWhale
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:49
  6. // :ID:107
  7. // :NUM:148
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // prim mover
  12. // :CODE:
  13. // User settable parameters:
  14. float FLIPTIME = 1.5; // how often the tail moves, floating point.
  15. string NOTECARD = "Movement"; // the notecard name, you can add any nuimber of Notecards and eitherchange this to play them, or rename one of them to this string
  16. // global variables below - no need to modify
  17. // These are for notecard reading
  18. integer iIndexLines;
  19. integer i = 0;
  20. integer iMove; // N movements rea from the notecard
  21. key kNoteCardLines; // the key of the notecard
  22. key kGetIndexLines; // the key of the current line
  23. // misc
  24. list masterlist; // the list of coords, filled in by a notecard reader
  25. integer tailcounter = 0; // this counter flips the tail up and down
  26. integer STRIDE = 6; // the list we record contains 6 pieces of info
  27. // subroutine to remove any white space before or after a string
  28. string strip(string str)
  29. {
  30. return llStringTrim(str, STRING_TRIM);
  31. }
  32. // subroutine to get a line at index 'line' from list Input, and strip white space b4 or after
  33. string Getline(list Input, integer line)
  34. {
  35. return strip(llList2String(Input, line));
  36. }
  37. // subroutine to Play Back a named animation
  38. PlayBack (string name)
  39. {
  40. integer i;
  41. integer iMax = llGetListLength(masterlist); // how many are in the list? we need this to know when to stop
  42. // scan the entire array for the named animation
  43. for (i = 0; i < iMax; i+= STRIDE)
  44. {
  45. string aniname2 = llList2String(masterlist,i);
  46. if (aniname2 == name)
  47. {
  48. // convert each list element into a loal variable
  49. float fPrimnum = llList2Float(masterlist,i+1);
  50. vector vPrimpos = llList2Vector(masterlist,i+2);
  51. rotation rPrimrot = llList2Rot(masterlist,i+3) ;
  52. string sMsg = llList2String(masterlist,i+4);
  53. string sUUID = llList2String(masterlist,i+5);
  54. if (llStringLength(sMsg) > 0)
  55. llSay(0,sMsg); // chat any text we find
  56. if (llStringLength(sUUID) > 0)
  57. llPlaySound(sUUID,1.0); // play any sound we find
  58. if (fPrimnum < 0)
  59. {
  60. llSleep(-fPrimnum); // sleep the interval in the notecard
  61. }
  62. else
  63. {
  64. rPrimrot /= llGetRot(); // Add in the local rot
  65. if (fPrimnum != 0)
  66. // The new way llSetLinkPrimitiveParamsFast((integer) fPrimnum,[PRIM_POSITION,vPrimpos,PRIM_ROTATION,rPrimrot]);
  67. llSetLinkPrimitiveParamsFast((integer) fPrimnum,[PRIM_POSITION,vPrimpos,PRIM_ROTATION,rPrimrot]);
  68. }
  69. }
  70. }
  71. }
  72. default
  73. {
  74. state_entry()
  75. {
  76. kNoteCardLines = llGetNumberOfNotecardLines(NOTECARD);
  77. kGetIndexLines = llGetNotecardLine(NOTECARD,0);
  78. }
  79. // read notecard on reset, once. We store this in RAM and never reset again
  80. dataserver(key kQueryid, string sData)
  81. {
  82. if (kQueryid == kNoteCardLines)
  83. iIndexLines = (integer) sData;
  84. if (kQueryid == kGetIndexLines)
  85. {
  86. if (sData != EOF)
  87. {
  88. // read and parse the notecard line into a list of items
  89. kQueryid = llGetNotecardLine(NOTECARD, i);
  90. list lLine = (llParseString2List(sData, ["|"], []));
  91. // pull each element from the notecard list so we can store it in the proper format
  92. string junk = llList2String(lLine,0); // this is the time/date field and object name that was chatted into the notecard
  93. string sAniname = llList2String(lLine,1); // the name of the animation
  94. integer iNum = (integer)Getline(lLine,2); // the prim link number
  95. vector vPos = (vector) Getline(lLine,3); // the position
  96. rotation rRot = (rotation) Getline(lLine,4); // the rotation
  97. string sMsg = llList2String(lLine,5); // optional chat string
  98. string sUUID = llList2String(lLine,6); // option sound name or UUID
  99. if(iNum > 1) // skip the root prim! we don't want to move it
  100. {
  101. if (llStringLength(sMsg) > 0)
  102. llSay(0,sMsg); // chat any text in this notecard
  103. if (llStringLength(sUUID) > 0)
  104. llPlaySound(sUUID,1.0); // play any sound we find in the notecard
  105. masterlist += [sAniname];
  106. masterlist += [iNum];
  107. masterlist += [vPos];
  108. masterlist += [rRot];
  109. masterlist += [sMsg];
  110. masterlist += [sUUID];
  111. rRot /= llGetRot(); // remove our current rotation, by subtracting.. yes, a divide is a subtract in vector math
  112. //llSetLinkPrimitiveParamsFast(Num,[PRIM_POSITION,Pos,PRIM_ROTATION,Rot]);
  113. llSetLinkPrimitiveParamsFast(iNum,[PRIM_POSITION,vPos,PRIM_ROTATION,rRot]);
  114. iMove++; // count the real movement
  115. }
  116. i++;
  117. integer iInitPerCent = (integer) llRound(( (i+1) / (float) iIndexLines) * 100);
  118. llSetText("Initialising... \n" + (string) iInitPerCent + "%" , <1,1,1>, 1.0);
  119. if (iInitPerCent == 100)
  120. llSetText("" , <1,1,1>, 1.0);
  121. kGetIndexLines = llGetNotecardLine(NOTECARD,i);
  122. }
  123. else
  124. {
  125. llOwnerSay("initialized with " + (string) iMove + " movements");
  126. llSetText("" , <1,1,1>, 1.0);
  127. // start the whale flipping the tail every so often
  128. llSetTimerEvent(FLIPTIME);
  129. }
  130. }
  131. }
  132. // The timer code moves the prim up and down
  133. timer()
  134. {
  135. if (tailcounter ++ %2 == 0)
  136. PlayBack("up");
  137. else
  138. PlayBack("down");
  139. }
  140. }