1 //originally written by Davide Byron
2 //this code is released under the GPLv3
4 // Reacts to E_NEW_INVENTORY_OBJECT event
5 // spawns a new child with the given object as the body
6 // and sends to him all his scripts (but not objects, etc...)
8 // we know nothing about the object and we don't need to know anything.
9 // but there is something needed anyway. the remoteloadingenabler script MUST
10 // be in the new body. otherwise reproduction will fail.
12 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
15 integer E_NEW_INVENTORY_OBJECT
= 14;
17 //cage boundaries expressed in region absolute coords
18 integer CAGE_MIN_X
= 1;
19 integer CAGE_MAX_X
= 249;
20 integer CAGE_MIN_Y
= 1;
21 integer CAGE_MAX_Y
= 249;
22 integer CAGE_MIN_Z
= 1;
23 integer CAGE_MAX_Z
= 100;
28 //deny moving out of a definite cage
29 //mostly used for debug
30 vector checkCageLimit( vector pos
)
32 if( pos
.x
< CAGE_MIN_X
)
34 if( pos
.x
> CAGE_MAX_X
)
36 if( pos
.y
< CAGE_MIN_Y
)
38 if( pos
.y
> CAGE_MAX_Y
)
40 if( pos
.z
< CAGE_MIN_Z
)
42 if( llGround( pos
- llGetPos() ) > pos
.z
)
43 pos
.z
= llGround( pos
- llGetPos() ) + 0.1;
44 if( pos
.z
> CAGE_MAX_Z
)
53 //generates a random float number ranging from -range to range
54 float myRand( float range
)
56 float sign
= llFrand(2.1);
57 float random
= llFrand( range
+ 0.1 );
80 //this should help humans knows what this creature can do
81 llSetObjectDesc( llGetObjectDesc() + "drop item to inventory for me to reproduce-" );
88 //if this state needs to know something from the other states
89 //this is the right place.
90 link_message(integer sender_num
, integer num
, string msg
, key id
)
92 //a new object has been dropped to the creature inventory
93 if( num
== E_NEW_INVENTORY_OBJECT
)
95 //so spawn a creature using that object as the body
96 vector pos
= llGetPos() + <myRand(2.0), myRand(2.0), myRand(2.0)>;
97 pos
= checkCageLimit( pos
);
98 llRezAtRoot(msg
, pos
, llGetVel(), llGetRot(), 0);
105 //after the new creature has been spawned we send all our scripts to it
108 integer scriptCount
= llGetInventoryNumber(INVENTORY_SCRIPT
);
111 //be sure scripts sent are running (if possible)
112 integer isRunning
= TRUE
;
114 for( ; i
< scriptCount
; i
++ )
116 script
= llGetInventoryName(INVENTORY_SCRIPT
, i
);
117 //that 0 could be used in the future to cause "mutations" from one script to another...
118 llRemoteLoadScriptPin(id
, script
, PIN
, isRunning
, 0 );