Opensim Bee.lsl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // :SHOW:1
  2. // :CATEGORY:Flying Bee
  3. // :NAME:Flying Bee and Hive
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:
  6. // :CREATED:2013-09-08 12:59:45
  7. <<<<<<< HEAD
  8. // :EDITED:2016-07-10 09:24:29
  9. =======
  10. >>>>>>> f0df6f03553fbf82e10f35590fcf71af838ab4be
  11. // :ID:995
  12. // :NUM:1725
  13. // :REV:5
  14. // :WORLD:Opensim, SecondLife
  15. // :DESCRIPTION:
  16. // A free flying bee that gathers pollen and takes it to his hive for either OpenSim or Second Life
  17. // :CODE:
  18. // Simple Bee script to locate and gather pollen from all prims named "Flower" then returns to the "Beehive"
  19. // Requires 2 sounds buzz1 and buzz2
  20. // !!!!!!!!!!!!!!
  21. // Mods by Donjr Spiegelblatt for Opensim to remove chance of thread locking on 3/7/2015
  22. // Thank YOU very much, DonJr !
  23. // 03-17-2015 fixed up a problem reported by DonJr where the bees visited to flowers in the wrong sequence.
  24. // Note: For Opensim, make sure to set the prim to PHYSICS type = NONE manually
  25. //======================================================================
  26. // Note: Inworldz Revisions - 7/9/2016
  27. // RadioRoy Wattz (Inworldz)
  28. //======================================================================
  29. // Tunable items
  30. integer debug = FALSE; // enablefor chattiness
  31. integer PHYSICAL = TRUE; // for smooth movemenents enable physical.
  32. // For less lag, set this to false, but the motion willl be very quick and jerky.
  33. string FLOWER_NAME = "Flower"; // the name of the thing we seek
  34. string HIVE_NAME = "Beehive Box-1";
  35. float DIST = 25.0; // gow far to fly, max
  36. float SPEED = 1; // move in this number of seconds from place to place
  37. // code bits
  38. vector vInitROT = <90,0,0> ; // due to the sculpted body, this bee gets rotated 90 degrees.
  39. vector vFlowerOffset = <0,.10,0.1>;// due to the rotation on the sculpted body, this is back and up a bit.
  40. vector vHiveOffset = <0,.5,0>;
  41. rotation r90; // a calculated 90 degree rotation ends up here
  42. integer iCount = 0; // hive counter
  43. string sLocatedName = "Beehive Box-1"; // located name of item
  44. list lGlist; // This is used as a first in first out stack with 2 entries per element
  45. DEBUG(string str)
  46. {
  47. if (debug) llOwnerSay(llGetScriptName() + ":" + str);
  48. }
  49. // pop the top entry off the stack
  50. poplGlist() {
  51. lGlist = llDeleteSubList(lGlist,0,1);
  52. }
  53. // Get the top Position
  54. vector Gpos() {
  55. return llList2Vector(lGlist,0);
  56. }
  57. // Get the top Rotation
  58. rotation Grot() {
  59. return llList2Rot(lGlist,1);
  60. }
  61. SetRotPos(rotation rot, vector dest)
  62. {
  63. DEBUG("moveto:" + (string) dest);
  64. if (PHYSICAL) {
  65. llMoveToTarget(dest,SPEED);
  66. llLookAt(dest+ <1,0,0>,SPEED,1); // 0.1 is a good compromise for SPEED > 1
  67. } else {
  68. llSetRegionPos(dest);
  69. llSetRot(rot);
  70. llSetStatus(STATUS_PHANTOM,TRUE);
  71. }
  72. }
  73. default
  74. {
  75. state_entry()
  76. {
  77. llStopMoveToTarget(); // new inworldz
  78. sLocatedName = "";
  79. llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]); //new inworldz
  80. llSleep(2); //new Inworldz
  81. // set rotation for this sculpted bee - remove this if yiou use a base prim| saved-> PRIM_PHYSICS_SHAPE_TYPE
  82. vector new = vInitROT * DEG_TO_RAD;
  83. r90 = llEuler2Rot(new);
  84. llSetTimerEvent(.2); // let's go!// move time up from .1 to .2
  85. if (PHYSICAL) {
  86. llSetStatus(STATUS_PHYSICS,FALSE); // disable, then enable to get it to engage
  87. llSetStatus(STATUS_PHYSICS,TRUE);
  88. } else{
  89. llSetStatus(STATUS_PHYSICS,FALSE);
  90. }
  91. }
  92. on_rez(integer p)
  93. {
  94. llSetStatus(STATUS_PHYSICS,FALSE); //new Inworldz
  95. llStopMoveToTarget( ); // new - inworldz - I Know Overkill!
  96. llResetScript();
  97. }
  98. timer()
  99. {
  100. llSetTimerEvent(0);
  101. if (sLocatedName == FLOWER_NAME)
  102. {
  103. if ( lGlist != [] )
  104. {
  105. llPlaySound("buzz1",1.0);
  106. SetRotPos(Grot() * r90 , Gpos() + vFlowerOffset); // orient to it
  107. llSetTimerEvent(4);
  108. poplGlist(); // pop the top entry off the stack
  109. }
  110. else
  111. {
  112. DEBUG("Look for Hive");
  113. llSensor(HIVE_NAME,NULL_KEY,ACTIVE|PASSIVE,DIST,PI); // Hive can be scripted, or not
  114. }
  115. }
  116. else if (sLocatedName == HIVE_NAME)
  117. {
  118. if ( iCount == 0 )
  119. {
  120. SetRotPos(llGetRot(), Gpos()); // move in
  121. llSetTimerEvent(10);
  122. }
  123. else if ( iCount == 1 )
  124. {
  125. llSetTimerEvent(2);
  126. SetRotPos(llGetRot(),Gpos() + vHiveOffset); // move out
  127. }
  128. else {
  129. sLocatedName = ""; // fall into llSensor FLOWER_NAME
  130. llSetTimerEvent(2); // adjust pause here
  131. }
  132. iCount++;
  133. } else { // fixed here
  134. // as you don't want to "fall" into here until after a 1 second pause
  135. DEBUG("Look for Flower");
  136. llSensor(FLOWER_NAME, NULL_KEY, ACTIVE|PASSIVE, DIST,PI); // flowers can be scripted, or not
  137. }
  138. }
  139. sensor(integer numDetected)
  140. {
  141. DEBUG("detected:" + (string) numDetected);
  142. sLocatedName = llDetectedName(0);
  143. // Clear the stack and place the first entry on it
  144. lGlist = [ llDetectedPos(0), llDetectedRot(0) ];
  145. if (sLocatedName == FLOWER_NAME)
  146. {
  147. // Append any additional Flowers entries onto the stack
  148. integer i;
  149. for (i = 1; i < numDetected; i++)
  150. {
  151. lGlist += [ llDetectedPos(i), llDetectedRot(i) ];
  152. }
  153. } else {
  154. iCount = 0;
  155. llPlaySound("buzz1",1.0);
  156. // start moving towards the Hive
  157. SetRotPos(Grot() * r90,Gpos() + vHiveOffset); // orient to it
  158. }
  159. // next step is always timer event
  160. llSetTimerEvent(1);
  161. }
  162. no_sensor()
  163. {
  164. sLocatedName = "";
  165. llSetTimerEvent(15); // try again
  166. }
  167. changed(integer change)
  168. {
  169. if (change & CHANGED_REGION_START)
  170. llResetScript();
  171. }
  172. }
  173. <<<<<<< HEAD
  174. // end of code
  175. =======
  176. // end of code
  177. >>>>>>> f0df6f03553fbf82e10f35590fcf71af838ab4be