Recorder.lsl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // :CATEGORY:Bird
  2. // :NAME:flamingo
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:53
  6. // :ID:314
  7. // :NUM:421
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // Recorder for movement paths
  12. // :CODE:
  13. // Bird flock recorder script
  14. // Author: Ferd Frederix
  15. // This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  16. // This means that this script itself is not for sale, that the script must be full Mod at all time, and that modifications to it MUST be provided to anyone upon request. Pets made with this script may be sold. ~ Ferd Frederix
  17. // 5-26-2013
  18. //
  19. //Commands are typed in Chat:
  20. //
  21. //Init - resets the script and gets it ready
  22. //set - records a position and rotation
  23. //Run - Plays back the animation
  24. //Export - Prints the list to chat so you can save it or put it into another script.
  25. //
  26. // This work uses content from the Second Life® Wiki article at http://wiki.secondlife.com/wiki/User:Jasper_Flossberg. Copyright © 2007-2012 Linden Research, Inc. Licensed under the Creative Commons Attribution-Share Alike 3.0 License.
  27. // Attribution — You must attribute the work
  28. // Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
  29. integer debug = FALSE;
  30. // Link message numbers to/from the main bird menu
  31. integer fromRoot = -3500;
  32. integer toRoot = -3501;
  33. integer toFlight = -3502;
  34. list keys=[];
  35. vector last_pos;
  36. rotation last_rot;
  37. vector start_pos;
  38. rotation start_rot;
  39. integer comChannel; // holds the owners channel
  40. integer comHandle;
  41. update_loc()
  42. {
  43. last_pos=llGetPos();
  44. last_rot=llGetRot();
  45. }
  46. DEBUG(string msg)
  47. {
  48. if (debug)
  49. llOwnerSay(msg);
  50. }
  51. Reset()
  52. {
  53. DEBUG("Intializing flight recorder");
  54. llSetKeyframedMotion([],[]);
  55. keys=[];
  56. start_pos=llGetPos();
  57. start_rot=llGetRot();
  58. update_loc();
  59. }
  60. list menu = ["Set Start","Record", "Finish"];
  61. dialog()
  62. {
  63. if (comHandle)
  64. llListenRemove(comHandle);
  65. comChannel = llCeil((llFrand(1000000) + 10000) * -1);
  66. comHandle = llListen(comChannel,"","","");
  67. integer memory = llGetFreeMemory();
  68. llDialog(llGetOwner(),"Select a recording option\nMemory Free:\n" + (string) memory,menu,comChannel);
  69. }
  70. default
  71. {
  72. state_entry()
  73. {
  74. Reset();
  75. }
  76. touch_start(integer n)
  77. {
  78. if (llDetectedKey(0) == llGetOwner())
  79. {
  80. dialog();
  81. }
  82. }
  83. link_message(integer sender_number, integer number, string message, key id)
  84. {
  85. if(message=="Setup")
  86. {
  87. Reset();
  88. dialog();
  89. }
  90. }
  91. listen(integer channel, string name, key id, string message)
  92. {
  93. if(message == "Set Start")
  94. {
  95. Reset();
  96. dialog();
  97. }
  98. else if(message == "Record")
  99. {
  100. keys+=[llGetPos()-last_pos,ZERO_ROTATION*(llGetRot()/last_rot)];
  101. update_loc();
  102. dialog();
  103. }
  104. else if(message=="Finish")
  105. {
  106. llOwnerSay("Saving Route");
  107. integer i;
  108. integer j = llGetListLength(keys);
  109. for ( ; i < j; i+=2)
  110. {
  111. string msg;
  112. vector myPos = llList2Vector(keys,i);
  113. rotation myRot = llList2Rot(keys,i+1);
  114. msg = (string) myPos + "|" + (string) myRot;
  115. DEBUG("Recorder:" + msg);
  116. llMessageLinked(LINK_SET,toFlight,msg,""); // tell the root prim to go silent on the menu
  117. llSleep(0.1); // time to dequeue it and encode it.
  118. }
  119. llMessageLinked(LINK_THIS,toRoot,"Playback",""); // tell the root prim to go silent on the menu
  120. state idle;
  121. }
  122. }
  123. }
  124. state idle
  125. {
  126. state_entry()
  127. {
  128. }
  129. link_message(integer sender_number, integer number, string message, key id)
  130. {
  131. if(message=="Setup")
  132. {
  133. llOwnerSay("Flight route is empty. Move the bird and click Record");
  134. Reset();
  135. dialog();
  136. state default;
  137. }
  138. }
  139. }