Added the tree scripts, w/ comments
[ProgettoPaperellaDiGomma.git] / reproducePartialCopyOnInventoryObjectEvent.lsl
blobade073cfe18e77fb8c4df072977e6e4265f63930
1 //originally written by Davide Byron
2 //this code is released under the GPLv3
3 //
4 // Reacts to E_NEW_INVENTORY_OBJECT event
5 // spawns a new child with the just-dropped object in inventory as the body
6 // and sends to him a random amount of his scripts (but not objects, etc...)
7 // -- notice that scripts cannot be sent twice --
8 //
9 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
11 //standard stuffs
12 integer E_NEW_INVENTORY_OBJECT = 14;
13 integer PIN = 123456;
14 //this is the chance to send every single script
15 float SENDING_TRESHOLD = 0.5;
16 //cage boundaries expressed in region absolute coords
17 integer CAGE_MIN_X = 1;
18 integer CAGE_MAX_X = 249;
19 integer CAGE_MIN_Y = 1;
20 integer CAGE_MAX_Y = 249;
21 integer CAGE_MIN_Z = 1;
22 integer CAGE_MAX_Z = 100;
26 //deny moving out of a definite cage
27 //mostly used for debug
28 vector checkCageLimit( vector pos )
30 if( pos.x < CAGE_MIN_X )
31 pos.x = CAGE_MIN_X;
32 if( pos.x > CAGE_MAX_X )
33 pos.x = CAGE_MAX_X;
34 if( pos.y < CAGE_MIN_Y )
35 pos.y = CAGE_MIN_Y;
36 if( pos.y > CAGE_MAX_Y )
37 pos.y = CAGE_MAX_Y;
38 if( pos.z < CAGE_MIN_Z )
39 pos.z = CAGE_MIN_Z;
40 if( llGround( pos - llGetPos() ) > pos.z )
41 pos.z = llGround( pos - llGetPos() ) + 0.1;
42 if( pos.z > CAGE_MAX_Z )
43 pos.z = CAGE_MAX_Z;
45 return pos;
51 //generates a random float number ranging from -range to range
52 float myRand( float range )
54 float sign = llFrand(2.1);
55 float random = llFrand( range + 0.1 );
56 if( sign >= 1.0 )
57 return random;
58 else
59 return -random;
65 default
68 on_rez(integer param)
70 llResetScript();
76 state_entry()
78 //this should help humans knows what this creature can do
79 llSetObjectDesc( llGetObjectDesc() + "drop item to inventory for me to reproduce-" );
86 //if this state needs to know something from the other states
87 //this is the right place.
88 link_message(integer sender_num, integer num, string msg, key id)
90 //if a new inventory object has been dropped...
91 if( num == E_NEW_INVENTORY_OBJECT )
93 //spawn a child
94 vector pos = llGetPos() + <myRand(2.0), myRand(2.0), myRand(2.0)>;
95 pos = checkCageLimit( pos );
96 llRezAtRoot(msg, pos, llGetVel(), llGetRot(), 0);
103 //after the new creature has been spawned we send some of our scripts to it
104 object_rez(key id)
106 integer scriptCount = llGetInventoryNumber(INVENTORY_SCRIPT);
107 integer i = 0;
108 string script;
109 integer isRunning = TRUE;
111 //for every script of the parent
112 for( ; i < scriptCount; i++ )
114 script = llGetInventoryName(INVENTORY_SCRIPT, i);
115 //we have a given chance to send it
116 if( llFrand(1.1) > SENDING_TRESHOLD )
118 llRemoteLoadScriptPin(id, script, PIN, isRunning, 0 );