Added the tree scripts, w/ comments
[ProgettoPaperellaDiGomma.git] / sensorNearbyScripted.lsl
blobd0bdf0347b3ad4928153b84e8a09bab34d15ddfc
1 //originally written by Davide Byron
2 //this code is released under the GPLv3
3 //
4 // Produces E_SCRIPTED_POSITION and E_NO_SENSOR events
5 // Sensor have detected a scripted object, the position is passed as a string
6 // Sensor have not detected anything, no params
7 //
8 // this sensor is a kind of eye for the creature. Almost everything about the external world
9 // is known via this script. Succesfully detecting food is a key feature for surviving.
11 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
13 //standard constants
14 integer E_SCRIPTED_POSITION = 2;
15 integer E_NO_SENSOR = 5;
19 //vars used by the script, can be subjected to evolution one day...
20 float SensorRange = 96.0;
21 float SensorFrequency = 20.0;
26 default
29 on_rez(integer param)
31 llResetScript();
37 state_entry()
39 //activate the sensor
40 llSensorRepeat("", "", SCRIPTED, SensorRange, PI, SensorFrequency);
46 //nothing in sight
47 no_sensor()
49 llMessageLinked(LINK_SET, E_NO_SENSOR, "", "");
54 //something in sight, investigate further
55 sensor(integer numberDetected)
57 //pick a random object detected and broadcast it's coords within the animal body
58 integer target = (integer)llFrand( numberDetected );
59 llMessageLinked(LINK_SET, E_SCRIPTED_POSITION, (string)llDetectedPos(target), llDetectedKey(target));