1 //originally written by Davide Byron
2 //this code is released under the GPLv3
4 // Produces R_MOD_ENERGY, to inform the energy manager script of changes
5 // Reacts to E_SHOUT_ENERGY keeping track of the current energy amount
8 // you MUST have an energy manager for this to work, otherwise you'll feed other creature forever
9 // and this is not a desirable behaviour.
11 // this script allow a creature to provide leaf food according to the EWG standard.
12 // TODO: it lacks a way to automagically rename the creature to make it compliant to
13 // the EWG naming standard in case this script is acquired during the creature life.
15 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
17 //wich version of the EcoComm standard is in use, see
18 // http://www.slecosystem.com/wiki/index.php?title=Main_Page
20 string ECO_COMM_VERSION
= "0x1";
21 //separator char in conformity with EcoCommV1
22 string ECO_COMM_V1_SEPARATOR
= "|";
23 //eat request by a predator, in conformity with EcoCommV1
24 integer ECO_COMM_V1_EAT_MSG_LEAF
= 0x10010108;
25 //response to a predator request, in conformity with EcoCommV1
26 //notice that it already includes the separator
27 string ECO_COMM_V1_FOOD_MSG_LEAF
= "0x10010208|";
31 integer R_MOD_ENERGY
= 11;
32 integer E_SHOUT_ENERGY
= 12;
40 //credits for this function goes to Sera Rawley and her cannon plant script, thanks.
41 //calculates the channel used to talk to this creature, pretty much unique.
42 integer getEcoCommChannel(string Version
, key SourceKey
)
44 return (integer)(Version
+ llGetSubString(SourceKey
, 0, 6));
63 //isten for eat messages
64 llListen( getEcoCommChannel( ECO_COMM_VERSION
, llGetKey() ), "", "", "" );
70 //credits for this function goes to Sera Rawley and her cannon plant script, thanks.
71 //triggered when someone is eating this creature
72 //If it's lifetime decrease too much it will die.
73 listen( integer channel
, string name
, key id
, string message
)
75 //if a predator has sent a eat request
76 if( ((integer)message
& ECO_COMM_V1_EAT_MSG_LEAF
) == ECO_COMM_V1_EAT_MSG_LEAF
)
78 //find out how much food the predator needs
79 integer requestedFood
= (integer)llDeleteSubString(message
, 0, llSubStringIndex(message
, ECO_COMM_V1_SEPARATOR
));
80 if( Energy
>= requestedFood
)
82 //"give" him the requested food
83 llSay(getEcoCommChannel(ECO_COMM_VERSION
, id
), ECO_COMM_V1_FOOD_MSG_LEAF
+ (string)requestedFood
);
87 //"give" him all we have...
88 llSay(getEcoCommChannel(ECO_COMM_VERSION
, id
), ECO_COMM_V1_FOOD_MSG_LEAF
+ (string)Energy
);
90 //signal the loss of energy to the creature
91 llMessageLinked(LINK_THIS
, R_MOD_ENERGY
, (string)(-requestedFood
), "");
99 link_message( integer sender_num
, integer num
, string str
, key id
)
101 //keep our energy value in line with the creature energy level, periodically updated
102 if( num
== E_SHOUT_ENERGY
)