walking.lsl 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. // :CATEGORY:XS Pet
  2. // :NAME:XS Pet Robot
  3. // :AUTHOR:Ferd Frederix
  4. // :KEYWORDS: Pet,XS,breed,breedable,companion,Ozimal,Meeroo,Amaretto,critter,Fennux,Pets
  5. // :CREATED:2013-09-06
  6. // :EDITED:2014-01-30 12:24:20
  7. // :ID:988
  8. // :NUM:1442
  9. // :REV:0.50
  10. // :WORLD:Second Life, OpenSim
  11. // :DESCRIPTION:
  12. // XS Pet walk on a moon pose ball
  13. // :CODE:
  14. // walk on a moon pose ball
  15. // Put this script into a pose ball and set it near your Sphere world.
  16. // This allows the person to actually welk on your world using the arrow ketys
  17. // Requires there to be one Walk animation in the inventory of the pose ball.
  18. // START OF COPIED file 'Global Constants.txt' from the Debug folder. It has to be the same in all files
  19. // If you change this in any script, change it in all of them, please. It works a lot better that way.
  20. // This is code based on Version 0.50 01-30-2014
  21. // For version history, see file revisions.txt
  22. //
  23. // LICENSE
  24. /////////////////////////////////////////////////////////////////////
  25. // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
  26. // See http://creativecommons.org/liceses/by-nc-sa/3.0/
  27. // Noncommercial -- You may not use this work for commercial purposes, i.e., you cannot sell this script in any form, including derivatives.
  28. // 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. // This means that you cannot sell this or derivative code by itself, but you may share and use this code in any object or virtual world.
  30. // You must attribute authorship in the original scripts to Ferd Frederix and Xundra Snowpaw, and leave this notice intact.
  31. // You do not have to give back to the community any changes you make, however, code changes would be greatly appreciated!
  32. //
  33. // Exception: I am allowing this script to be used in an original build and sold with the build.
  34. // You are not selling the script, you are selling the build. If you want to sell these scripts, write your own or use the original at http://code.google.com/p/xspets/
  35. // Note: Xundra Snowpaw's license was 'New BSD' license and adding additional licenses is allowed.
  36. // Based on code from Xundra Snowpaw
  37. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  38. // Copyright (c) 2010, Xundra Snowpaw
  39. // All rights reserved.
  40. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  41. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  42. //* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
  43. // in the documentationand/or other materials provided with the distribution.
  44. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  45. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
  46. // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  47. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  48. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  49. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. ////////////////////////////////////////////////////////////////////
  51. // DEBUG - lets you see and hear wtf is happening
  52. integer debug = FALSE; // set to TRUE TO hear a lot of chat
  53. // This section has a few tuneable items that MUST be changed for any new pet
  54. // SECURITY
  55. string SECRET_PASSWORD = "top secret string"; // must use a password unique to any species of animal, when ENCRYPT= TRUE. Otherwise you will find Pet type A fucking pet type B.
  56. integer SECRET_NUMBER = 99999; // any number thats a secret, not necessary to change usually, this is used when pets are born and eggs are rezzed to establish a comm channel.
  57. integer ENCRYPT = TRUE; // set to TRUE to encrypt all data, Some Opensim worlds prefer FALSE due to parsing bugs, TRUE is the most secure. If FALSE you MUST change the FOOD_CHANNEL and other channels for different pets. or they will literally fuck each other.
  58. // if you add the UUID for your avatar here, you can change it later
  59. // and other alts or friends can change it too, and all of you can work on these pets.
  60. // If you leave it blank, only the creator of the root prim can work on these pets.
  61. key YOUR_UUID = "";
  62. // PET NAMES - YOU MUST CHANGE THEM HERE AND IN THE ROOT PRIM OF THE OBJECT - THEY MUST MATCH EXACTLY
  63. /////////////////////////
  64. string MaleName = "Troubot"; // Must be the name of your animal
  65. string FemaleName = "Troubot"; // The name of the female pet, if a different shape or prim count. Can be the same as the Male for pets like the robot that are unisex.
  66. string Egg = "Nut and Bolt"; // was 'XS Egg', must be the name of your egg
  67. string Crate = "Transport Spaceship"; // was XS-Cryocrate, must be the name of the crate you package pets in
  68. string HomeObject = "Home Flag"; // was "XS Home Object", must be the name of your Home Post indicator
  69. string EggCup = "Toolbox"; // was "XS Egg Cup", must be the name of your egg holder
  70. // any other object names are 'do not cares'.
  71. // NOTHING NEEDS TO BE CHANGED BELOW, BUT CAN BE CHANGED IF YOU DO IT EVERYWHERE
  72. // misc tunables
  73. float GROWTH_AMOUNT = 0.10; // 10% size increase each day for MaxAge days = 200% (double size after 7 days)
  74. integer MaxAge = 7; // stop growing in seven days. 10% growth compounded daily means that your pet will be 194% larger ( 2x, basically) in 7 days.
  75. integer UNITS_OF_FOOD = 168; // food bowl food qty, used by food bowl only
  76. float secs_to_grow = 86400; // grow daily = 86400 seconds
  77. float FOOD_BOWL_SCAN_INTERVAL = 1800.0; // look for food every 3 hours
  78. float fPregnancy = 172800.0; // how many seconds to lay an egg = 2 days or 48 hours.
  79. float MALE_TIMEOUT = 900.0 ; // in seconds, female waits this long in one spot for a male to arrive
  80. float SEX_WAIT = 10800.0; // How often they desire sex = 3 hours
  81. float fDaysToAdult = 7; // 7 days to become old enough to breed.
  82. integer SECONDS_BETWEEN_FOOD_NORMAL = 14400; // number of seconds to get hungry = 4 hours
  83. integer SECONDS_BETWEEN_FOOD_HUNGRY = 3600; // number of seconds before hunger count increases = 1 hour
  84. integer MAXIMUM_HUNGER = 30; // They die after a month with no food.
  85. // I control versions by Subversion Source Code Control. But the updater needs a version numbert in world.
  86. // This is the Protocol version. If you change this, then all pets with a lower version will be updated by the updater
  87. float VERSION = 0.50;
  88. // the leg sizes are safe to leave alone or set to 0 if you use a thin base prim, these are from the original Quail
  89. float LegLength = 0.064; // length of pet leg??? - not sure
  90. float LegOffset = 0.052399; // This is added to the Post Z to position the pet
  91. // the following are global constants and do not need to be changed
  92. // Prim animation linkmessages are sent by scripts on Link Message number 1
  93. // The strings are the names of the animations that are recorded.
  94. // No need to change them unless you want to change names of the animations when you run the prim animator, or you add additional link messages
  95. // If your pet walks, you need to record these names and save them in the notecard
  96. //
  97. // Example:
  98. // llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  99. // The above line will play the pre-recorded 'stand up' animation "stand" using the animator script.
  100. // The following animations are used in the pet. You can add your own.
  101. string ANI_STAND = "stand"; // default standing animation
  102. string ANI_WALKL = "left"; // triggers Left foot and Right arm walk animation
  103. string ANI_WALKR = "right"; // triggers Right foot and Left arm walk animation
  104. string ANI_SLEEP = "sleep"; // Sleeping
  105. string ANI_WAVE = "wave"; // Calling for sex, needs help with food, etc.
  106. // Channel assignments
  107. // if you change any of these constants, change it everywhere and in the list in XS_Debug so it can print them
  108. // If you turn encryption FALSE, you MUST change these between species of pets are they will fuck with each other. Literally.
  109. integer FOOD_CHANNEL = -999191;
  110. integer ANIMAL_CHANNEL = -999192;
  111. integer EGG_CHANNEL = -999193;
  112. integer HOME_CHANNEL = -999194;
  113. integer BOX_CHANNEL = -999195;
  114. integer ACC_CHANNEL = -999196;
  115. integer UPDATE_CHANNEL = -999197;
  116. integer API_CHANNEL = -999198;
  117. // global link messages to control the animal, never any need to change these.
  118. // They are exposed here so they will be the same everywhere. This uses a bit of RAM, but who cares?
  119. integer LINK_ANIMATE = 1; // messages on num 1 are assumed to be directed at the prim animator.
  120. integer DECREASE_FOOD = 100; // used in the food bowl.
  121. integer LINK_AGE_START = 800; // when pety is rezzed and secret_number is sent by brain to breeder, eater and infomatic get booted up
  122. integer LINK_TEXTURE = 801; // ask for a new texture, or paint a color
  123. integer LINK_BREEDNAME = 802; // the name of the pet texture from the texture server notecard
  124. integer LINK_FOOD_CONSUME = 900; // from movement to brain when close to food, brain then consumes a random amount up to 10000
  125. integer LINK_FOODMINUS = 901; // xs_brain receives FOOD_CONSUME, decrement hunger (eat)
  126. integer LINK_HUNGRY = 903; // sent by eater (string)hunger_amount, checks each hour
  127. integer LINK_HAMOUNT = 904; // hunger_amount = (integer)str,m updates the hunger amount in scripts
  128. integer LINK_SET_HOME = 910; // loc ^ dist
  129. integer LINK_MOVER = 911; // tell mover to rest for str seconds
  130. integer LINK_FOODIE_CLR = 920; // clear all food_bowl_keys and contents
  131. integer LINK_FOODIE = 921; // send FOOD_LOCATION coordinates to movement
  132. integer LINK_COLOR1 = 930; // colour1
  133. integer LINK_COLOR2 = 931; // colour2
  134. integer LINK_SEX = 932; // sex
  135. integer LINK_SHINE = 933; // shine
  136. integer LINK_GLOW = 934; // glow
  137. integer LINK_GEN = 935; // generation
  138. integer LINK_RESET_SIZE = 936; // reset size to 1
  139. integer LINK_MAGE = 940; // xs_brain sends, xs_ager consumes, adds str to age, if older than 7 days, will grow the animal
  140. integer LINK_DAYTIME = 941; // xs_ager consumes, starts a timer of 86,400 seconds in xs_ager
  141. integer LINK_GET_AGE = 942; // get age from xs_ager and sent it on channel 943
  142. integer LINK_PUT_AGE = 943; // print age from xs_ager
  143. integer LINK_PACKAGE = 950; // look for a cryo_crate
  144. integer LINK_SEEK_FEMALE = 960; // MALE_BREED_CALL
  145. integer LINK_MALE_BREED_CALL = 961; // triggered by LINK_SEEK_FEMALE
  146. integer LINK_SIGNAL_ELIGIBLE = 962; // sent by female when hears LINK_MALE_BREED_CALL
  147. integer LINK_FEMALE_ELIGIBLE = 963; // sent when it hears in chat FEMALE_ELIGIBLE
  148. integer LINK_CALL_MALE = 964; // if LINK_FEMALE_ELIGIBLE && looking_for_female
  149. integer LINK_MALE_ON_THE_WAY = 965; // triggered by LINK_CALL_MALE
  150. integer LINK_FEMALE_LOCATION = 966; // female location, sends coordinates of a female
  151. integer LINK_RQST_BREED = 967; // sent when close enough to male/female
  152. integer LINK_CALL_MALE_INFO = 968; // sent by xs_breeding, this line of code was in error in v.24 of xs_breeding see line 557 and 636 of xs_brain which make calls and also xs_breeding which receives LINK_MALE_INFO.
  153. integer LINK_MALE_INFO = 969; // Breeding failed, sent info
  154. integer LINK_LAY_EGG = 970; // Rez Object(Egg...
  155. integer LINK_BREED_FAIL = 971; // key = father, failed, timed out
  156. integer LINK_PREGNANT = 972; // chick is preggers
  157. integer LINK_SOUND_OFF= 974; // sound is off
  158. integer LINK_SOUND_ON= 973; // sound is on
  159. integer LINK_SLEEPING = 990; // close eyes
  160. integer LINK_UNSLEEPING = 991; // open eyes
  161. integer LINK_SOUND = 1001; // plays a sound if enabled
  162. integer LINK_SPECIAL = 1010; // xs_special, if str = "Normal", removes script
  163. integer LINK_EFFECTS_ON = 2000; // particle effects in the packger
  164. integer LINK_PREGNANCY_TIME = 5000; // in seconds as str
  165. integer LINK_SLEEP = 7999; // disable sleep by parameter
  166. integer LINK_TIMER = 8000; // scan for food bowl about every 1800 seconds
  167. integer LINK_DIE = 9999; // death
  168. string Copyright = " (c)2014 by Ferd Frederix"; // You cannot change this line, but you can change the code that prints it!
  169. // See License agreements above.
  170. // Attribution is required, as these files are copyrighted.
  171. DEBUG ( string msg){
  172. if (debug) {
  173. llOwnerSay(llGetScriptName() + ":" + msg);
  174. }
  175. }
  176. ///////// end global Link constants ////////
  177. // END OF COPIED CODE
  178. vector home_location;
  179. vector destination;
  180. float increment = 0.1;
  181. // DON'T CHANGE THE FOLLOWING! (Unless you know what you are doing!)
  182. integer XTEA_DELTA = 0x9E3779B9; // (sqrt(5) - 1) * 2^31
  183. integer xtea_num_rounds = 6;
  184. list xtea_key = [0, 0, 0, 0];
  185. integer hex2int(string hex) {
  186. if(llGetSubString(hex,0,1) == "0x")
  187. return (integer)hex;
  188. if(llGetSubString(hex,0,0) == "x")
  189. return (integer)("0"+hex);
  190. return(integer)("0x"+hex);
  191. }
  192. // Convers any string to a 32 char MD5 string and then to a list of
  193. // 4 * 32 bit integers = 128 bit Key. MD5 ensures always a specific
  194. // 128 bit key is generated for any string passed.
  195. list xtea_key_from_string( string str )
  196. {
  197. str = llMD5String(str,0); // Use Nonce = 0
  198. return [ hex2int(llGetSubString( str, 0, 7)),
  199. hex2int(llGetSubString( str, 8, 15)),
  200. hex2int(llGetSubString( str, 16, 23)),
  201. hex2int(llGetSubString( str, 24, 31))];
  202. }
  203. // Encipher two integers and return the result as a 12-byte string
  204. // containing two base64-encoded integers.
  205. string xtea_encipher( integer v0, integer v1 )
  206. {
  207. integer num_rounds = xtea_num_rounds;
  208. integer sum = 0;
  209. do {
  210. // LSL does not have unsigned integers, so when shifting right we
  211. // have to mask out sign-extension bits.
  212. v0 += (((v1 << 4) ^ ((v1 >> 5) & 0x07FFFFFF)) + v1) ^ (sum + llList2Integer(xtea_key, sum & 3));
  213. sum += XTEA_DELTA;
  214. v1 += (((v0 << 4) ^ ((v0 >> 5) & 0x07FFFFFF)) + v0) ^ (sum + llList2Integer(xtea_key, (sum >> 11) & 3));
  215. } while( num_rounds = ~-num_rounds );
  216. //return only first 6 chars to remove "=="'s and compact encrypted text.
  217. return llGetSubString(llIntegerToBase64(v0),0,5) +
  218. llGetSubString(llIntegerToBase64(v1),0,5);
  219. }
  220. // Decipher two base64-encoded integers and return the FIRST 30 BITS of
  221. // each as one 10-byte base64-encoded string.
  222. string xtea_decipher( integer v0, integer v1 )
  223. {
  224. integer num_rounds = xtea_num_rounds;
  225. integer sum = XTEA_DELTA*xtea_num_rounds;
  226. do {
  227. // LSL does not have unsigned integers, so when shifting right we
  228. // have to mask out sign-extension bits.
  229. v1 -= (((v0 << 4) ^ ((v0 >> 5) & 0x07FFFFFF)) + v0) ^ (sum + llList2Integer(xtea_key, (sum>>11) & 3));
  230. sum -= XTEA_DELTA;
  231. v0 -= (((v1 << 4) ^ ((v1 >> 5) & 0x07FFFFFF)) + v1) ^ (sum + llList2Integer(xtea_key, sum & 3));
  232. } while ( num_rounds = ~-num_rounds );
  233. return llGetSubString(llIntegerToBase64(v0), 0, 4) +
  234. llGetSubString(llIntegerToBase64(v1), 0, 4);
  235. }
  236. // Encrypt a full string using XTEA.
  237. string xtea_encrypt_string( string str )
  238. {
  239. if (! ENCRYPT)
  240. return str;
  241. // encode string
  242. str = llStringToBase64(str);
  243. // remove trailing =s so we can do our own 0 padding
  244. integer i = llSubStringIndex( str, "=" );
  245. if ( i != -1 )
  246. str = llDeleteSubString( str, i, -1 );
  247. // we don't want to process padding, so get length before adding it
  248. integer len = llStringLength(str);
  249. // zero pad
  250. str += "AAAAAAAAAA=";
  251. string result;
  252. i = 0;
  253. do {
  254. // encipher 30 (5*6) bits at a time.
  255. result += xtea_encipher(llBase64ToInteger(llGetSubString(str, i, i + 4) + "A="), llBase64ToInteger(llGetSubString(str, i+5, i + 9) + "A="));
  256. i+=10;
  257. } while ( i < len );
  258. return result;
  259. }
  260. // Decrypt a full string using XTEA
  261. string xtea_decrypt_string( string str ) {
  262. if (! ENCRYPT)
  263. return str;
  264. integer len = llStringLength(str);
  265. integer i=0;
  266. string result;
  267. //llOwnerSay(str);
  268. do {
  269. integer v0;
  270. integer v1;
  271. v0 = llBase64ToInteger(llGetSubString(str, i, i + 5) + "==");
  272. i+= 6;
  273. v1 = llBase64ToInteger(llGetSubString(str, i, i + 5) + "==");
  274. i+= 6;
  275. result += xtea_decipher(v0, v1);
  276. } while ( i < len );
  277. // Replace multiple trailing zeroes with a single one
  278. i = llStringLength(result) - 1;
  279. while ( llGetSubString(result, i - 1, i) == "AA" ){
  280. result = llDeleteSubString(result, i, i);
  281. i--;
  282. }
  283. i = llStringLength(result) - 1;
  284. // while (llGetSubString(result, i, i + 1) == "A" ) {
  285. // i--;
  286. // }
  287. result = llGetSubString(result, 0, i+1);
  288. i = llStringLength(result);
  289. integer mod = i%4; //Depending on encoded length diffrent appends are needed
  290. if(mod == 1) result += "A==";
  291. else if(mod == 2 ) result += "==";
  292. else if(mod == 3) result += "=";
  293. return llBase64ToString(result);
  294. }
  295. // walk on a sphere
  296. string Text = "Walk on the moon"; // the hovertext when noone is stting
  297. string ANIMATION ; // change to a walk animation
  298. vector Home;
  299. rotation gOrient;
  300. key avatarKey;
  301. float x ;
  302. float y ;
  303. float z ;
  304. float gRADIUS;
  305. float aRADIUS;
  306. string controls ;
  307. face_target(vector lookat) {
  308. // rotation rot = llGetRot() * llRotBetween(<1.0 ,0.0 ,0.0 > * llGetRot(), lookat - llGetPos());
  309. // llSetRot(rot);
  310. // llSleep(.1);
  311. rotation rot = llGetRot() * llRotBetween(<0.0 ,0.0 ,1.0 > * llGetRot(), home_location - llGetPos());
  312. llSetRot(rot);
  313. }
  314. key avatar;
  315. warpPos( vector destpos )
  316. { //R&D by Keknehv Psaltery, 05/25/2006
  317. //with a little poking by Strife, and a bit more
  318. //some more munging by Talarus Luan
  319. //Final cleanup by Keknehv Psaltery
  320. //Changed jump value to 411 (4096 ceiling) by Jesse Barnett
  321. // Compute the number of jumps necessary
  322. integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
  323. // Try and avoid stack/heap collisions
  324. if (jumps > 411)
  325. jumps = 411;
  326. list rules = [ PRIM_POSITION, destpos ]; //The start for the rules list
  327. integer count = 1;
  328. while ( ( count = count << 1 ) < jumps)
  329. rules += rules; //should tighten memory use.
  330. llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
  331. if ( llVecDist( llGetPos(), destpos ) > .001 ) //Failsafe
  332. while ( --jumps )
  333. llSetPos( destpos );
  334. }
  335. default
  336. {
  337. on_rez(integer p)
  338. {
  339. llResetScript();
  340. }
  341. state_entry()
  342. {
  343. ANIMATION = llGetInventoryName(INVENTORY_ANIMATION,0); // get the first animation we can find
  344. Home = llGetPos();
  345. llSetAlpha(1,ALL_SIDES);
  346. llSetText(Text,<1,1,1>,1);
  347. vector rot = <0,180,180>;
  348. rotation sitrot = llEuler2Rot(rot * DEG_TO_RAD);
  349. llSitTarget(<0,0,0.01>,sitrot);
  350. xtea_key = xtea_key_from_string(SECRET_PASSWORD);
  351. llListen(ANIMAL_CHANNEL, "", "", "");
  352. llShout(HOME_CHANNEL, "XSPET_PING_HOME");
  353. llSetCameraEyeOffset(<-4, 0, 3> * sitrot);
  354. llSetCameraAtOffset(<2, 0, 1> * sitrot);
  355. }
  356. listen(integer channel, string name, key id, string message)
  357. {
  358. llOwnerSay(message);
  359. if (channel == ANIMAL_CHANNEL) {
  360. list data = llParseString2List(xtea_decrypt_string(message), ["^"], []);
  361. if (llList2String(data, 0) == "XSPET")
  362. {
  363. if (llList2String(data, 1) == "HOME_LOCATION") {
  364. vector n_home_loc = (vector)llList2String(data, 2);
  365. float home_dis = llList2Float(data, 3);
  366. vector my_loc = llGetPos();
  367. if (llGetOwnerKey(id) == llGetOwner()) {
  368. home_location = n_home_loc;
  369. llOwnerSay("Homeworld located");
  370. }
  371. }
  372. else if (llList2String(data, 1) == "HOME_RADIUS")
  373. {
  374. float dia = llList2Float(data, 2);
  375. if (llGetOwnerKey(id) == llGetOwner())
  376. {
  377. gRADIUS = dia/2;
  378. //home_location.y -= dia/2;
  379. //llOwnerSay("Home Radius:" + (string) gRADIUS);
  380. state running;
  381. }
  382. }
  383. }
  384. }
  385. }
  386. }
  387. state running
  388. {
  389. state_entry()
  390. {
  391. llOwnerSay("Ready");
  392. gOrient = ZERO_ROTATION;
  393. destination = <0,0,0>;
  394. vector current_loc = llGetPos();
  395. llListen(ANIMAL_CHANNEL, "", "", "");
  396. }
  397. changed(integer change)
  398. {
  399. if(change & CHANGED_LINK)
  400. {
  401. avatar = llAvatarOnSitTarget();
  402. if(avatar != NULL_KEY){
  403. //SOMEONE SAT DOWN
  404. avatarKey = avatar;
  405. llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION |PERMISSION_TAKE_CONTROLS);
  406. return;
  407. }else{
  408. //SOMEONE STOOD UP
  409. if (llGetPermissionsKey() != NULL_KEY)
  410. {
  411. llSetTimerEvent(0);
  412. llStopAnimation(ANIMATION);
  413. llSetText(Text,<1,1,1>,1);
  414. llSetAlpha(1,ALL_SIDES);
  415. warpPos(Home);
  416. }
  417. return;
  418. }
  419. }
  420. }
  421. run_time_permissions(integer perm)
  422. {
  423. if(perm & PERMISSION_TRIGGER_ANIMATION)
  424. {
  425. vector height = llGetAgentSize(avatarKey);
  426. aRADIUS = gRADIUS + height.z * .85 ; // adjust for the agent size
  427. llStopAnimation("sit");
  428. llStartAnimation(ANIMATION);
  429. llSetTimerEvent(.5);
  430. llSetText("",<1,0,0>,1);
  431. llSetAlpha(0,ALL_SIDES);
  432. }
  433. if(PERMISSION_TAKE_CONTROLS & perm)
  434. {
  435. //llOwnerSay("Controls Ready");
  436. llTakeControls( CONTROL_FWD |
  437. CONTROL_BACK |
  438. CONTROL_ROT_LEFT |
  439. CONTROL_ROT_RIGHT , TRUE, TRUE);
  440. controls = "U";
  441. }
  442. }
  443. timer()
  444. {
  445. if(llStringLength(controls) == 0)
  446. {
  447. llStopAnimation(ANIMATION);
  448. return;
  449. }
  450. //llOwnerSay(controls);
  451. controls = "";
  452. llStartAnimation(ANIMATION);
  453. rotation delta = llEuler2Rot(<x,y,z> * DEG_TO_RAD);
  454. vector unitpos = llRot2Fwd( gOrient );
  455. vector pos = home_location + unitpos * aRADIUS;
  456. //llOwnerSay((string) llVecDist(home_location,llGetPos()));
  457. face_target(pos);
  458. //llSetRot(gOrient);
  459. llRezObject("Primitive",pos,<0,0,0>,gOrient,1);
  460. //llOwnerSay("Pos:" + ( string) pos);
  461. llSetPos(pos);
  462. gOrient = gOrient * delta;
  463. }
  464. control(key driver, integer levels, integer edge)
  465. {
  466. // integer start = levels & edge;
  467. // integer end = ~levels & edge;
  468. // integer held = levels & ~edge;
  469. //integer untouched = ~(levels | edge);
  470. //llOwnerSay(llList2CSV([levels, edge, start, end, held, untouched]));
  471. //z = L/R
  472. //y = U/d
  473. x = 0;
  474. y = 0;
  475. z = 0;
  476. float bump = 10;
  477. if (levels & CONTROL_FWD)
  478. {
  479. y = bump;
  480. controls = "U";
  481. }
  482. if (levels & CONTROL_BACK)
  483. {
  484. y = -bump;
  485. controls = "D";
  486. }
  487. if (levels & CONTROL_ROT_LEFT)
  488. {
  489. z = bump ;
  490. controls = "L";
  491. }
  492. if (levels & CONTROL_ROT_RIGHT)
  493. {
  494. z = -bump;
  495. controls = "R";
  496. }
  497. }
  498. }