Owl script.lsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. // :CATEGORY:Bird
  2. // :NAME:Roaming Owl
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:39:01
  6. // :ID:707
  7. // :NUM:966
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // main script
  12. // :CODE:
  13. // ______ _ ______ _ _
  14. // | ___| | | | ___| | | (_)
  15. // | |_ ___ _ __ __| | | |_ _ __ ___ __| | ___ _ __ ___ __
  16. // | _/ _ \ '__/ _` | | _| '__/ _ \/ _` |/ _ \ '__| \ \/ /
  17. // | || __/ | | (_| | | | | | | __/ (_| | __/ | | |> <
  18. // \_| \___|_| \__,_| \_| |_| \___|\__,_|\___|_| |_/_/\_\
  19. //
  20. // fred@mitsi.com
  21. // owl bird script
  22. //
  23. //Revisions:
  24. // 1/28/2010 initial release
  25. string CRY = "Bubo-virginianus";
  26. string SHORT = "Bubo-virginianus short";
  27. string SURPRISE = "Scotopelia-peli";
  28. string prey = "Squirrel and feeder";
  29. // fly sit, catch land
  30. integer debug = 0;
  31. vector rezpoint; // home point
  32. rotation rezrot;
  33. integer Flying;
  34. integer listen_chan;
  35. integer listener;
  36. float i ; //counter for timer moving
  37. vector up_vel = <10,0,9>; // speed and direction away
  38. vector down_vel = <6,0,-8>; // and to go home, small numbers for less speed and mass objects
  39. float STRENGTH = 2.0; // how hard to turn
  40. float DAMPING = 0.2; // and how soon
  41. float MAX = 3.0; // MAX strength ( slow turns)
  42. float MIN = 1.0; // fast turns
  43. float timerate = 0.215;
  44. float roam_range = 10; // default range
  45. string flag ; // what menu item thay need integers for
  46. vector direction;
  47. vector Destination;
  48. float atimer;
  49. float INTERVAL = .050; // seconds to move
  50. integer SeekingFish = FALSE;
  51. Dialog()
  52. {
  53. listener = llListen(listen_chan,"","","");
  54. llDialog(llGetOwner(),"Flight Controls: Home: current place is the roost\nTime: How often to fly when no one is near\nRange: Distance to roam\nFlap: Flap wings\nHelp: get notecard",["Range","Flap","Help","Home","Time","Ferd"],listen_chan);
  55. }
  56. CheckDir()
  57. {
  58. vector currPos = llGetPos();
  59. if (currPos.z > Destination.z)
  60. {
  61. direction = down_vel;
  62. // if (debug) llOwnerSay("D");
  63. }
  64. else
  65. {
  66. direction = up_vel;
  67. //if (debug) llOwnerSay("U");
  68. }
  69. if (! SeekingFish)
  70. {
  71. // go no lower than the rez point plus some slop
  72. if (currPos.z < rezpoint.z )
  73. {
  74. //if (debug) llOwnerSay("U");
  75. Destination.z = rezpoint.z + 1.0;
  76. direction = up_vel;
  77. }
  78. }
  79. }
  80. DoMove()
  81. {
  82. llMessageLinked(LINK_SET,1,"flap",""); // hop up
  83. CheckDir();
  84. //llSetStatus(STATUS_PHYSICS, TRUE);
  85. //llStopLookAt();
  86. llRotLookAt(llRotBetween(<1,0,0>, Destination - llGetPos()), STRENGTH, DAMPING);
  87. llSleep(DAMPING*3);
  88. llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, 1 * direction);
  89. llSleep(.1);
  90. llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, ZERO_VECTOR);
  91. //llSetStatus(STATUS_PHYSICS, FALSE);
  92. }
  93. NewDest()
  94. {
  95. // random direction
  96. Destination = llGetPos();
  97. Destination.x += llFrand(roam_range) - 0.5 * roam_range;
  98. Destination.y += llFrand(roam_range) - 0.5 * roam_range;
  99. Destination.z += (llFrand(1.0) -.5 ) + .5;
  100. if (Destination.z < rezpoint.z )
  101. {
  102. Destination.z = rezpoint.z + 4.0;
  103. direction = up_vel;
  104. }
  105. }
  106. Fly()
  107. {
  108. if (debug ) llOwnerSay("Fly");
  109. Flying = 1;
  110. i = 50;
  111. STRENGTH = MAX; // how hard to turn
  112. NewDest();
  113. llPlaySound(CRY,1.0);
  114. SeekingFish = FALSE;
  115. llSensorRepeat(prey,"", ACTIVE|PASSIVE|SCRIPTED, 96, PI, 10.0);
  116. llSetStatus(STATUS_PHYSICS, TRUE);
  117. llMessageLinked(LINK_SET,1,"fly",""); // hop up
  118. llSetTimerEvent(.1); // fast
  119. }
  120. default
  121. {
  122. on_rez(integer a)
  123. {
  124. llResetScript();
  125. }
  126. state_entry()
  127. {
  128. llMessageLinked(LINK_SET,1,"sit",""); // hop up
  129. llSetStatus(STATUS_DIE_AT_EDGE,TRUE);
  130. llSetBuoyancy(0.8);
  131. rezpoint = llGetPos();
  132. rezrot = llGetRot();
  133. llSetStatus(STATUS_PHYSICS, FALSE);
  134. llSetVehicleFlags(-1);
  135. llSetVehicleType(VEHICLE_TYPE_CAR);
  136. llRemoveVehicleFlags(VEHICLE_FLAG_LIMIT_MOTOR_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
  137. llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.8);
  138. llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.8);
  139. llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, .1);
  140. llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, .1);
  141. llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.8); // hover
  142. llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, .1);
  143. llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, .1);
  144. llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, .1);
  145. llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, .1);
  146. llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1.0, .1, 1000.0>);
  147. llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <.1, .1, .1>);
  148. llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, .8);
  149. llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, .1);
  150. llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.25);
  151. llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1);
  152. llGroundRepel(2.0, TRUE, 0.2);
  153. atimer = 60;
  154. llOwnerSay("Flight range is 10 meters. Timer is 1 minute. Click bird to change settings");
  155. state moving;
  156. }
  157. }
  158. state moving
  159. {
  160. on_rez(integer a)
  161. {
  162. llResetScript();
  163. }
  164. timer()
  165. {
  166. if (! Flying)
  167. {
  168. if (debug ) llOwnerSay("Was not flying");
  169. Fly();
  170. }
  171. if (--i == 0)
  172. {
  173. if (debug ) llOwnerSay("Too long");
  174. SeekingFish = FALSE;
  175. i = 50;
  176. Flying ++; // force HOME
  177. Destination = rezpoint;
  178. llPlaySound(CRY,1.0);
  179. STRENGTH = MIN; // turn sharply
  180. }
  181. DoMove();
  182. if (llVecDist(Destination,llGetPos()) < 2)
  183. {
  184. if (debug) llOwnerSay("At Dest");
  185. i = 50;
  186. Flying++;
  187. }
  188. if (! SeekingFish && Flying < 8)
  189. {
  190. if ((integer) i % 10 == 0)
  191. {
  192. NewDest();
  193. if (debug ) llOwnerSay("New dest");
  194. }
  195. if ((llVecDist(rezpoint,llGetPos()) > roam_range) )
  196. {
  197. if (debug ) llOwnerSay("Too far");
  198. Destination = rezpoint;
  199. Flying++;
  200. STRENGTH = MIN; // turn sharply
  201. llPlaySound(CRY,1.0);
  202. }
  203. }
  204. if (SeekingFish && llVecDist(Destination,llGetPos()) < 2)
  205. {
  206. if (debug ) llOwnerSay("Caught Fish");
  207. llPlaySound(SURPRISE,1.0);
  208. llWhisper(2222,"fish");
  209. //llMessageLinked(LINK_SET,1,"sit",""); // grab the fish
  210. llMessageLinked(LINK_SET,1,"catch",""); // grab the fish
  211. SeekingFish = FALSE;
  212. Flying = 8;
  213. i=50; // need some time to get home
  214. }
  215. if (Flying == 9)
  216. {
  217. // back on the ground
  218. Destination = rezpoint;
  219. i=50;
  220. if (debug ) llOwnerSay("Heading Home");
  221. }
  222. if (Flying >= 10)
  223. {
  224. float dist = llVecDist(rezpoint,llGetPos());
  225. // if (dist < 2)
  226. // {
  227. llMessageLinked(LINK_SET,1,"land",""); // hop up
  228. // }
  229. llPlaySound(SHORT,1.0);
  230. llSleep(0.5);
  231. llSetStatus(STATUS_PHYSICS, FALSE);
  232. llMessageLinked(LINK_SET,1,"sit",""); // hop up
  233. llSetRot(rezrot);
  234. llSetPos(rezpoint);
  235. // we may not have made it home, could have run into something
  236. if (dist > 1)
  237. {
  238. if (debug) llOwnerSay("Forced Home");
  239. state setposition; //contingency
  240. }
  241. //if(debug) llOwnerSay("At Home");
  242. SeekingFish = FALSE;
  243. Flying = 0;
  244. llSetTimerEvent(atimer);
  245. llSensorRepeat("","",AGENT,roam_range,PI,5);
  246. }
  247. }
  248. state_entry()
  249. {
  250. llSensorRepeat("","",AGENT,roam_range,PI,5);
  251. SeekingFish = FALSE;
  252. Fly(); // Fly at startup
  253. }
  254. sensor(integer total_number)
  255. {
  256. if (Flying)
  257. {
  258. if (debug ) llOwnerSay("Found Fish");
  259. llPlaySound(SURPRISE,1.0);
  260. Destination = llDetectedPos(0);
  261. Destination.z += 2.0;
  262. SeekingFish = TRUE;
  263. llSensorRemove();
  264. STRENGTH = 1.0; // how hard to turn
  265. i = 50; // need time to catch a fish
  266. }
  267. else
  268. {
  269. if (atimer)
  270. Fly();
  271. }
  272. }
  273. touch_start(integer a)
  274. {
  275. if (llDetectedKey(0) == llGetOwner())
  276. {
  277. listen_chan=llCeil(llFrand(10000) + 10000);
  278. Dialog();
  279. }
  280. else
  281. {
  282. if (atimer)
  283. Fly();
  284. }
  285. }
  286. listen(integer channel,string name, key id, string msg)
  287. {
  288. if (msg == "Range")
  289. {
  290. llDialog(llGetOwner(),"Range from Home place in meters",["10","15","20","25","30","35","40","45","50"],listen_chan);
  291. flag = "R";
  292. }
  293. else if ((integer) msg >= 10 && flag == "R")
  294. {
  295. roam_range = (integer) msg;
  296. flag = "";
  297. Dialog();
  298. }
  299. else if (msg == "Help")
  300. llGiveInventory(llGetOwner(),"Help");
  301. else if (msg == "Flap")
  302. {
  303. llMessageLinked(LINK_SET,1,"land",""); // hop up
  304. llPlaySound(CRY,1.0);
  305. llSleep(1); // time to see it
  306. llMessageLinked(LINK_SET,1,"sit",""); // hop up
  307. Dialog();
  308. }
  309. else if (msg == "Home")
  310. {
  311. rezpoint = llGetPos();
  312. llOwnerSay("Position is set to " + (string) rezpoint);
  313. Dialog();
  314. }
  315. else if (msg =="Time")
  316. {
  317. llDialog(llGetOwner(),"How often they auto fly in seconds",["Off","15s","30s","1min","2min","3min","5min","15min","hour"],listen_chan);
  318. }
  319. else if (msg =="Off")
  320. {
  321. atimer = 0;
  322. }
  323. else if (msg =="15s")
  324. atimer = 15;
  325. else if (msg =="30s")
  326. atimer = 30;
  327. else if (msg =="1min")
  328. atimer = 60;
  329. else if (msg =="2min")
  330. atimer = 120;
  331. else if (msg =="5min")
  332. atimer = 300;
  333. else if (msg =="15min")
  334. atimer = 900;
  335. else if (msg =="hour")
  336. atimer = 3600;
  337. else if (msg =="Ferd")
  338. llLoadURL(llGetOwner(),"More Info at our web site","http://secondlife.mitsi.com");
  339. llOwnerSay("Flight range is " + (string) roam_range + " meters. ");
  340. if (atimer)
  341. llOwnerSay("The bird will fly every " + (string) atimer + " seconds");
  342. else
  343. llOwnerSay("The bird will fly only when someone is near");
  344. if (! Flying)
  345. {
  346. llSetTimerEvent(atimer);
  347. }
  348. }
  349. }
  350. state setposition //contingency
  351. {
  352. state_entry()
  353. {
  354. if (debug)llOwnerSay("Oops, forcing home");
  355. llSetTimerEvent(INTERVAL);
  356. }
  357. on_rez(integer a)
  358. {
  359. llResetScript();
  360. }
  361. timer()
  362. {
  363. if (llVecMag(llGetPos() - rezpoint) > 5)
  364. {
  365. llSetPos((llVecNorm(Destination - llGetPos()) * 0.5) + llGetPos());
  366. }
  367. else
  368. {
  369. llSetRot(rezrot);
  370. llSetPos(rezpoint);
  371. if (debug)llOwnerSay("Homed");
  372. llMessageLinked(LINK_SET,1,"sit",""); // hop up
  373. state moving;
  374. }
  375. }
  376. state_exit()
  377. {
  378. llSetTimerEvent(0);
  379. }
  380. }