xs_sleep script.lsl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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:1435
  9. // :REV:0.50
  10. // :WORLD:Second Life, OpenSim
  11. // :DESCRIPTION:
  12. // XS Pet xs_sleep
  13. // :CODE:
  14. // xs_sleep
  15. // Particle plug in for XS_Pets.
  16. // place this in the head of any animal. When it falls asleep, it will spit out Zzzzs
  17. // only use this with xs_animated_eye script, as the xs_two_texture eye script has this built-in
  18. // 9-17-3012 - made it so the eyes black out when sleeping
  19. // tunables:
  20. string texture = "Z"; // Texture used for particles. Texture must be in prim's inventory.
  21. // thanks to Semi Sixpence for spotting this was 'key'
  22. // could be key texture "SOME key copied from inventory but not a name";
  23. // START OF COPIED file 'Global Constants.txt' from the Debug folder. It has to be the same in all files
  24. // If you change this in any script, change it in all of them, please. It works a lot better that way.
  25. // This is code based on Version 0.50 01-30-2014
  26. // For version history, see file revisions.txt
  27. //
  28. // LICENSE
  29. /////////////////////////////////////////////////////////////////////
  30. // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
  31. // See http://creativecommons.org/liceses/by-nc-sa/3.0/
  32. // Noncommercial -- You may not use this work for commercial purposes, i.e., you cannot sell this script in any form, including derivatives.
  33. // 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.
  34. // 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.
  35. // You must attribute authorship in the original scripts to Ferd Frederix and Xundra Snowpaw, and leave this notice intact.
  36. // You do not have to give back to the community any changes you make, however, code changes would be greatly appreciated!
  37. //
  38. // Exception: I am allowing this script to be used in an original build and sold with the build.
  39. // 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/
  40. // Note: Xundra Snowpaw's license was 'New BSD' license and adding additional licenses is allowed.
  41. // Based on code from Xundra Snowpaw
  42. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  43. // Copyright (c) 2010, Xundra Snowpaw
  44. // All rights reserved.
  45. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  46. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  47. //* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
  48. // in the documentationand/or other materials provided with the distribution.
  49. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  50. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
  51. // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  52. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  53. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  54. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55. ////////////////////////////////////////////////////////////////////
  56. // DEBUG - lets you see and hear wtf is happening
  57. integer debug = FALSE; // set to TRUE TO hear a lot of chat
  58. // This section has a few tuneable items that MUST be changed for any new pet
  59. // SECURITY
  60. 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.
  61. 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.
  62. 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.
  63. // if you add the UUID for your avatar here, you can change it later
  64. // and other alts or friends can change it too, and all of you can work on these pets.
  65. // If you leave it blank, only the creator of the root prim can work on these pets.
  66. key YOUR_UUID = "";
  67. // PET NAMES - YOU MUST CHANGE THEM HERE AND IN THE ROOT PRIM OF THE OBJECT - THEY MUST MATCH EXACTLY
  68. /////////////////////////
  69. string MaleName = "Troubot"; // Must be the name of your animal
  70. 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.
  71. string Egg = "Nut and Bolt"; // was 'XS Egg', must be the name of your egg
  72. string Crate = "Transport Spaceship"; // was XS-Cryocrate, must be the name of the crate you package pets in
  73. string HomeObject = "Home Flag"; // was "XS Home Object", must be the name of your Home Post indicator
  74. string EggCup = "Toolbox"; // was "XS Egg Cup", must be the name of your egg holder
  75. // any other object names are 'do not cares'.
  76. // NOTHING NEEDS TO BE CHANGED BELOW, BUT CAN BE CHANGED IF YOU DO IT EVERYWHERE
  77. // misc tunables
  78. float GROWTH_AMOUNT = 0.10; // 10% size increase each day for MaxAge days = 200% (double size after 7 days)
  79. 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.
  80. integer UNITS_OF_FOOD = 168; // food bowl food qty, used by food bowl only
  81. float secs_to_grow = 86400; // grow daily = 86400 seconds
  82. float FOOD_BOWL_SCAN_INTERVAL = 1800.0; // look for food every 3 hours
  83. float fPregnancy = 172800.0; // how many seconds to lay an egg = 2 days or 48 hours.
  84. float MALE_TIMEOUT = 900.0 ; // in seconds, female waits this long in one spot for a male to arrive
  85. float SEX_WAIT = 10800.0; // How often they desire sex = 3 hours
  86. float fDaysToAdult = 7; // 7 days to become old enough to breed.
  87. integer SECONDS_BETWEEN_FOOD_NORMAL = 14400; // number of seconds to get hungry = 4 hours
  88. integer SECONDS_BETWEEN_FOOD_HUNGRY = 3600; // number of seconds before hunger count increases = 1 hour
  89. integer MAXIMUM_HUNGER = 30; // They die after a month with no food.
  90. // I control versions by Subversion Source Code Control. But the updater needs a version numbert in world.
  91. // This is the Protocol version. If you change this, then all pets with a lower version will be updated by the updater
  92. float VERSION = 0.50;
  93. // 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
  94. float LegLength = 0.064; // length of pet leg??? - not sure
  95. float LegOffset = 0.052399; // This is added to the Post Z to position the pet
  96. // the following are global constants and do not need to be changed
  97. // Prim animation linkmessages are sent by scripts on Link Message number 1
  98. // The strings are the names of the animations that are recorded.
  99. // 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
  100. // If your pet walks, you need to record these names and save them in the notecard
  101. //
  102. // Example:
  103. // llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  104. // The above line will play the pre-recorded 'stand up' animation "stand" using the animator script.
  105. // The following animations are used in the pet. You can add your own.
  106. string ANI_STAND = "stand"; // default standing animation
  107. string ANI_WALKL = "left"; // triggers Left foot and Right arm walk animation
  108. string ANI_WALKR = "right"; // triggers Right foot and Left arm walk animation
  109. string ANI_SLEEP = "sleep"; // Sleeping
  110. string ANI_WAVE = "wave"; // Calling for sex, needs help with food, etc.
  111. // Channel assignments
  112. // if you change any of these constants, change it everywhere and in the list in XS_Debug so it can print them
  113. // If you turn encryption FALSE, you MUST change these between species of pets are they will fuck with each other. Literally.
  114. integer FOOD_CHANNEL = -999191;
  115. integer ANIMAL_CHANNEL = -999192;
  116. integer EGG_CHANNEL = -999193;
  117. integer HOME_CHANNEL = -999194;
  118. integer BOX_CHANNEL = -999195;
  119. integer ACC_CHANNEL = -999196;
  120. integer UPDATE_CHANNEL = -999197;
  121. integer API_CHANNEL = -999198;
  122. // global link messages to control the animal, never any need to change these.
  123. // They are exposed here so they will be the same everywhere. This uses a bit of RAM, but who cares?
  124. integer LINK_ANIMATE = 1; // messages on num 1 are assumed to be directed at the prim animator.
  125. integer DECREASE_FOOD = 100; // used in the food bowl.
  126. integer LINK_AGE_START = 800; // when pety is rezzed and secret_number is sent by brain to breeder, eater and infomatic get booted up
  127. integer LINK_TEXTURE = 801; // ask for a new texture, or paint a color
  128. integer LINK_BREEDNAME = 802; // the name of the pet texture from the texture server notecard
  129. integer LINK_FOOD_CONSUME = 900; // from movement to brain when close to food, brain then consumes a random amount up to 10000
  130. integer LINK_FOODMINUS = 901; // xs_brain receives FOOD_CONSUME, decrement hunger (eat)
  131. integer LINK_HUNGRY = 903; // sent by eater (string)hunger_amount, checks each hour
  132. integer LINK_HAMOUNT = 904; // hunger_amount = (integer)str,m updates the hunger amount in scripts
  133. integer LINK_SET_HOME = 910; // loc ^ dist
  134. integer LINK_MOVER = 911; // tell mover to rest for str seconds
  135. integer LINK_FOODIE_CLR = 920; // clear all food_bowl_keys and contents
  136. integer LINK_FOODIE = 921; // send FOOD_LOCATION coordinates to movement
  137. integer LINK_COLOR1 = 930; // colour1
  138. integer LINK_COLOR2 = 931; // colour2
  139. integer LINK_SEX = 932; // sex
  140. integer LINK_SHINE = 933; // shine
  141. integer LINK_GLOW = 934; // glow
  142. integer LINK_GEN = 935; // generation
  143. integer LINK_RESET_SIZE = 936; // reset size to 1
  144. integer LINK_MAGE = 940; // xs_brain sends, xs_ager consumes, adds str to age, if older than 7 days, will grow the animal
  145. integer LINK_DAYTIME = 941; // xs_ager consumes, starts a timer of 86,400 seconds in xs_ager
  146. integer LINK_GET_AGE = 942; // get age from xs_ager and sent it on channel 943
  147. integer LINK_PUT_AGE = 943; // print age from xs_ager
  148. integer LINK_PACKAGE = 950; // look for a cryo_crate
  149. integer LINK_SEEK_FEMALE = 960; // MALE_BREED_CALL
  150. integer LINK_MALE_BREED_CALL = 961; // triggered by LINK_SEEK_FEMALE
  151. integer LINK_SIGNAL_ELIGIBLE = 962; // sent by female when hears LINK_MALE_BREED_CALL
  152. integer LINK_FEMALE_ELIGIBLE = 963; // sent when it hears in chat FEMALE_ELIGIBLE
  153. integer LINK_CALL_MALE = 964; // if LINK_FEMALE_ELIGIBLE && looking_for_female
  154. integer LINK_MALE_ON_THE_WAY = 965; // triggered by LINK_CALL_MALE
  155. integer LINK_FEMALE_LOCATION = 966; // female location, sends coordinates of a female
  156. integer LINK_RQST_BREED = 967; // sent when close enough to male/female
  157. 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.
  158. integer LINK_MALE_INFO = 969; // Breeding failed, sent info
  159. integer LINK_LAY_EGG = 970; // Rez Object(Egg...
  160. integer LINK_BREED_FAIL = 971; // key = father, failed, timed out
  161. integer LINK_PREGNANT = 972; // chick is preggers
  162. integer LINK_SOUND_OFF= 974; // sound is off
  163. integer LINK_SOUND_ON= 973; // sound is on
  164. integer LINK_SLEEPING = 990; // close eyes
  165. integer LINK_UNSLEEPING = 991; // open eyes
  166. integer LINK_SOUND = 1001; // plays a sound if enabled
  167. integer LINK_SPECIAL = 1010; // xs_special, if str = "Normal", removes script
  168. integer LINK_EFFECTS_ON = 2000; // particle effects in the packger
  169. integer LINK_PREGNANCY_TIME = 5000; // in seconds as str
  170. integer LINK_SLEEP = 7999; // disable sleep by parameter
  171. integer LINK_TIMER = 8000; // scan for food bowl about every 1800 seconds
  172. integer LINK_DIE = 9999; // death
  173. string Copyright = " (c)2014 by Ferd Frederix"; // You cannot change this line, but you can change the code that prints it!
  174. // See License agreements above.
  175. // Attribution is required, as these files are copyrighted.
  176. DEBUG ( string msg){
  177. if (debug) {
  178. llOwnerSay(llGetScriptName() + ":" + msg);
  179. }
  180. }
  181. ///////// end global Link constants ////////
  182. // END OF COPIED CODE
  183. // Original Particle Script 0.4j
  184. // Created by Ama Omega 3-7-2004
  185. // Updated by Jopsy Pendragon 5-11-2004
  186. // For classes/tutorials/tricks, visit the Particle Labratory in Teal
  187. // Values marked with (*) are defaults.
  188. // SECTION ONE: APPEARANCE -- These settings affect how each particle LOOKS.
  189. integer glow = TRUE; // TRUE or FALSE(*)
  190. vector startColor = <1,1,1>; // RGB color, black<0,0,0> to white<1,1,1>(*)
  191. vector endColor = <1,1,1>; //
  192. float startAlpha = 1.0; // 0.0 to 1.0(*), lower = more transparent
  193. float endAlpha = 1.0; //
  194. vector startSize = <0.1,0.1,0>; // <0.04,0.04,0>(min) to <10,10,0>(max>, <1,1,0>(*)
  195. vector endSize = <.3,.3,0>; // (Z part of vector is discarded)
  196. // SECTION TWO: FLOW -- These settings affect how Many, how Quickly, and for how Long particles are created.
  197. // Note,
  198. integer count = 1; // Number of particles created per burst, 1(*) to 4096
  199. float rate = 1.0; // Delay between bursts of new particles, 0.0 to 60, 0.1(*)
  200. float age = 5.0; // How long each particle lives, 0.1 to 60, 10.0(*)
  201. float life = 0.0; // When to stop creating new particles. never stops if 0.0(*)
  202. // SECTION THREE: PLACEMENT -- Where are new particles created, and what direction are they facing?
  203. float radius = .30; // 0.0(default) to 64? Distance from Emitter where new particles are created.
  204. float innerAngle = 0.75; // "spread", for all ANGLE patterns, 0(default) to PI
  205. float outerAngle = 0.0; // "tilt", for ANGLE patterns, 0(default) to TWO_PI, can use PI_BY_TWO or PI as well.
  206. integer pattern = PSYS_SRC_PATTERN_ANGLE_CONE; // Choose one of the following:
  207. // PSYS_SRC_PATTERN_EXPLODE (sends particles in all directions)
  208. // PSYS_SRC_PATTERN_DROP (ignores minSpeed and maxSpeed. Don't bother with count>1 )
  209. // PSYS_SRC_PATTERN_ANGLE_CONE (set innerangle/outerange to make rings/cones of particles)
  210. // PSYS_SRC_PATTERN_ANGLE (set innerangle/outerangle to make flat fanshapes of particles)
  211. vector omega = <0,0,0>; // How much to rotate the emitter around the <X,Y,Z> axises. <0,0,0>(*)
  212. // Warning, there's no way to RESET the emitter direction once you use Omega!!
  213. // You must attach the script to a new prim to clear the effect of omega.
  214. // SECTION FOUR: MOVEMENT -- How do the particles move once they're created?
  215. integer followSource = FALSE; // TRUE or FALSE(*), Particles move as the emitter moves, (TRUE disables radius!)
  216. integer followVel = FALSE; // TRUE or FALSE(*), Particles rotate towards their direction
  217. integer wind = FALSE; // TRUE or FALSE(*), Particles get blown away by wind in the sim
  218. integer bounce = TRUE; // TRUE or FALSE(*), Make particles bounce on Z altitude of emitter
  219. float minSpeed = 0.1; // 0.01 to ? Min speed each particle is spit out at, 1.0(*)
  220. float maxSpeed = 0.2; // 0.01 to ? Max speed each particle is spit out at, 1.0(*)
  221. vector push = <0,0,-0.3>; // Continuous force pushed on particles, use small settings for long lived particles
  222. key target = ""; // Select a target for particles to arrive at when they die
  223. // can be "self" (emitter), "owner" (you), "" or any prim/persons KEY.
  224. // SECTION FIVE: Ama's "Create Short Particle Settings List"
  225. integer enableoutput = FALSE; // If this is TRUE, clicking on your emitter prim will cause it to speak
  226. // very terse "shorthand" version of your particle settings. You can cut'n'paste
  227. // this abbreviated version into a call to llParticleSystem([ ]); in another script.
  228. // Pros: Takes up far less scripting space, letting you focus on the rest of your code.
  229. // Cons: makes tune your settings afterwards rather awkward
  230. // === Don't muck about below this line unless you're comfortable with the LSL scripting language ====
  231. // Script variables
  232. integer flags;
  233. updateParticles()
  234. {
  235. flags = 0;
  236. if (target == "owner") target = llGetOwner();
  237. if (target == "self") target = llGetKey();
  238. if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
  239. if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
  240. if (startColor != endColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
  241. if (startSize != endSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
  242. if (wind) flags = flags | PSYS_PART_WIND_MASK;
  243. if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
  244. if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
  245. if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;
  246. list sys = [ PSYS_PART_MAX_AGE,age,
  247. PSYS_PART_FLAGS,flags,
  248. PSYS_PART_START_COLOR, startColor,
  249. PSYS_PART_END_COLOR, endColor,
  250. PSYS_PART_START_SCALE,startSize,
  251. PSYS_PART_END_SCALE,endSize,
  252. PSYS_SRC_PATTERN, pattern,
  253. PSYS_SRC_BURST_RATE,rate,
  254. PSYS_SRC_ACCEL, push,
  255. PSYS_SRC_BURST_PART_COUNT,count,
  256. PSYS_SRC_BURST_RADIUS,radius,
  257. PSYS_SRC_BURST_SPEED_MIN,minSpeed,
  258. PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
  259. PSYS_SRC_TARGET_KEY,target,
  260. PSYS_SRC_INNERANGLE,innerAngle,
  261. PSYS_SRC_OUTERANGLE,outerAngle,
  262. PSYS_SRC_OMEGA, omega,
  263. PSYS_SRC_MAX_AGE, life,
  264. PSYS_SRC_TEXTURE, texture,
  265. PSYS_PART_START_ALPHA, startAlpha,
  266. PSYS_PART_END_ALPHA, endAlpha
  267. ];
  268. float newrate = rate;
  269. if (newrate == 0.0) newrate=.01;
  270. if ( (age/rate)*count < 4096) llParticleSystem(sys);
  271. else {
  272. llInstantMessage(llGetOwner(),"Your particle system creates too many concurrent particles.");
  273. llInstantMessage(llGetOwner(),"Reduce count or age, or increate rate.");
  274. llParticleSystem( [ ] );
  275. }
  276. }
  277. default
  278. {
  279. state_entry()
  280. {
  281. llParticleSystem( [ ] ); // no particles
  282. }
  283. on_rez(integer num)
  284. {
  285. llResetScript();
  286. }
  287. link_message(integer sender, integer num, string str, key id)
  288. {
  289. if (num == 1 && str==ANI_SLEEP) {
  290. llSetColor(<0,0,0>,ALL_SIDES); // black out the eyes
  291. updateParticles();
  292. }
  293. else if (num == 1 && str == ANI_STAND) {
  294. llParticleSystem( [ ] );
  295. llSetColor(<1,1,1>,ALL_SIDES);
  296. }
  297. }
  298. }