Added the tree scripts, w/ comments
[ProgettoPaperellaDiGomma.git] / huntEWGLeafFood.lsl
blobe67add76972e6179a3b82b0e0a3689b309f3f75e
1 //originally written by Davide Byron
2 //this code is released under the GPLv3
3 //
4 // Produces R_MOD_ENERGY, when a leaf is eaten, the energy level
5 // is increased by notifying the energy manager script
6 //
7 // Reacts to E_SCRIPTED_POSITION and E_ACTIVE_POSITION when a target is found,
8 // the script checks if it's edible and in case eats it.
9 //
10 // this will only have a real effect if also the energy manager is in the creature,
11 // otherwise all the eating efforts will be useless.
12 // for eating the creature used the EWG standard, wich for now has proven good and
13 // well developed but might be improved in the future to assure more freedom
14 // from the life constrains as we know it.
16 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
18 //wich version of the EcoComm standard is in use, see
19 // http://www.slecosystem.com/wiki/index.php?title=Main_Page
20 //for details
21 string ECO_COMM_VERSION = "0x1";
22 //foods i like: leaves
23 //this is a plant with leaf food
24 integer PREY_MASK = 0x00100008;
25 //creature request for food, it eats leaves
26 integer ECO_COMM_V1_EAT_MSG_LEAF = 0x10010108;
27 //separator char in conformity with EcoCommV1
28 string ECO_COMM_V1_SEPARATOR = "|";
29 //reposnse from a prey, leaf, it's a mask
30 integer ECO_COMM_V1_FOOD_MSG_LEAF = 0x10010208;
32 //standard stuffs
33 integer R_MOD_ENERGY = 11;
34 integer E_SCRIPTED_POSITION = 2;
35 integer E_ACTIVE_POSITION = 4;
40 //how much vitality the creature gains for eating
41 integer EatVitalityRequested = 10;
46 //credits for this function goes to Sera Rawley and her cannon plant script, thanks.
47 //calculates the channel used to talk to this creature, pretty much unique.
48 integer getEcoCommChannel(string Version, key SourceKey)
50 return (integer)(Version + llGetSubString(SourceKey, 0, 6));
56 default
59 on_rez(integer param)
61 llResetScript();
67 state_entry()
69 //listen for eating messages
70 llListen( getEcoCommChannel( ECO_COMM_VERSION, llGetKey() ), "", "", "" );
76 link_message( integer sender_num, integer num, string str, key id )
78 //a scripted object has been sensed
79 if(num == E_SCRIPTED_POSITION || num == E_ACTIVE_POSITION )
81 //get some info
82 string targetName = llGetSubString( llKey2Name(id), 0, 9 );
84 //and check if it's edible food for us
85 if( ((integer)targetName & PREY_MASK) == PREY_MASK )
87 //the creature reached the prey, so ask for food
88 integer preyChannel = getEcoCommChannel( ECO_COMM_VERSION, id );
89 llSay(preyChannel, (string)ECO_COMM_V1_EAT_MSG_LEAF + ECO_COMM_V1_SEPARATOR + (string)EatVitalityRequested );
97 listen( integer channel, string name, key id, string message )
99 //if a prey has answered our message
100 integer request = (integer)llGetSubString( message, 0, 10 );
101 if( (integer)(request & ECO_COMM_V1_FOOD_MSG_LEAF) != 0 )
103 //take vital energy from received food and signal it to the energy script
104 llMessageLinked(LINK_THIS, R_MOD_ENERGY, llGetSubString(message, 11, -1 + llStringLength(message)), "");