Added the tree scripts, w/ comments
[ProgettoPaperellaDiGomma.git] / sendSoundsOnDetection.lsl
blob7c939cb3b20871b7f03eb0cdf6e3696e36e4704e
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 sound to it.
7 //
8 // you can see this as a way of learning to talk for creatures
9 // a real comunication standard will be defined at some point in
10 // the future and we can bound that to sounds maybe...
12 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
14 //standard
15 integer E_SCRIPTED_POSITION = 2;
16 integer E_ACTIVE_POSITION = 4;
20 //global var, cna be subject of evolution some day..
21 float SendingTreshold = 0.95;
22 float PositionTreshold = 1.0;
26 default
28 link_message( integer sender_num, integer num, string str, key id )
30 //if a detection has occurred
31 if( num == E_ACTIVE_POSITION || num == E_SCRIPTED_POSITION )
33 vector objPos = (vector)str;
34 vector ourPos = llGetPos();
36 //if the object is enough near
37 if( llFabs(ourPos.x - objPos.x) <= PositionTreshold &&
38 llFabs(ourPos.y - objPos.y) <= PositionTreshold &&
39 llFabs(ourPos.z - objPos.z) <= PositionTreshold )
41 vector target = (vector)str;
42 //we have a chance to send a sound
43 if( llFrand(1.0) > SendingTreshold )
45 if( llGetInventoryNumber(INVENTORY_SOUND) > 0 )
47 //a random one among all we have
48 llGiveInventory(id, llGetInventoryName(INVENTORY_SOUND, (integer)llFrand(
49 llGetInventoryNumber(INVENTORY_SOUND))) );