Added the tree scripts, w/ comments
[ProgettoPaperellaDiGomma.git] / sendScriptsOnDetection.lsl
blobd22b26dfa037dae5fca0c8ac7d2e4b37e7214fe9
1 //originally written by Davide Byron
2 //this code is released under the GPLv3
3 //
4 // Reacts to E_SCRIPTED_POSITION and E_ACTIVE_POSITION events
5 // When the creature is very near an object it has a random
6 // chance to send a script to it. If the other object is a creature
7 // with the remote loading script enabler he will receive the script
8 // and start using it
9 //
10 // this will allow for complex evolution to take place, as every script codes
11 // a specific behaviour. Other creatures will be able to acquire new behaviours
12 // and try to get more fit to the world.
13 // this is a powerful and armful tool tough, be careful as it could drive things
14 // out of control pretty quick.
16 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
18 //standard
19 integer PIN = 123456;
20 integer E_SCRIPTED_POSITION = 2;
21 integer E_ACTIVE_POSITION = 4;
25 //global vars, may be subjected to evolution one day...
26 float SendingTreshold = 0.95;
27 float PositionTreshold = 1.0;
32 default
34 //listens for messages
35 link_message( integer sender_num, integer num, string str, key id )
37 //if a detection has occurred
38 if( num == E_ACTIVE_POSITION || num == E_SCRIPTED_POSITION )
40 vector objPos = (vector)str;
41 vector ourPos = llGetPos();
43 //if the object is enough near
44 if( llFabs(ourPos.x - objPos.x) <= PositionTreshold &&
45 llFabs(ourPos.y - objPos.y) <= PositionTreshold &&
46 llFabs(ourPos.z - objPos.z) <= PositionTreshold )
48 vector target = (vector)str;
49 //the creature has a given probability of sending one of its scripts
50 if( llFrand(1.0) > SendingTreshold )
52 integer isRunning = TRUE;
53 llRemoteLoadScriptPin(id, llGetInventoryName(INVENTORY_SCRIPT, (integer)llFrand(
54 llGetInventoryNumber(INVENTORY_SCRIPT))), PIN, isRunning, 0 );