With this 2.0 version you can:
*Set drink time (after that time cup will be detached)
*Set sip time (time between each sip)
*Set attach message
*Set detach messsage
All this configured by notecard!
You need "sip rest loop" and "sipping sl" animations, if you don't have them send an IM.
CODE
// Original sip script By Theda Twilight
// Animations by Robin Sojourner
// Attach/detach message + drinking time configuration by Kahiro Watanabe
key drinker; //agent wearing the object
// This data is taken from notecard //
string attachMessage; //whispered message on attach
string detachMessage; //whispered message on detach
float sipTime; //time between each sip
float drinkTime; //total drink time
///////////////////////////////////////
float currentDrinkTime; //keeps track of current drink time
// for dataserver queries //
key notecardQuery;
integer notecardLine;
default
{
attach(key attached)
{
if (attached) // someone is wearing it
{
drinker = attached;
notecardLine = 0;
notecardQuery = llGetNotecardLine("!config",notecardLine);
}
}
dataserver(key queryId, string data)
{
if (queryId == notecardQuery)
{
if (data != EOF)
{
if (llGetSubString(data,0,0) != "#") // keep passing lines until finds a "#"
{
notecardLine = notecardLine + 1;
notecardQuery = llGetNotecardLine("!config",notecardLine);
}
else if (data != EOF) // "#" was found, time to read configuration
{
list tempList = llParseString2List(data, [",","#"],[]);
string tempString = llToLower(llList2String(tempList,0));
string tempString2 = llList2String(tempList,1);
if (tempString == "attachmessage")
{
attachMessage = tempString2;
}
else if (tempString == "detachmessage")
{
detachMessage = tempString2;
}
else if (tempString == "siptime")
{
sipTime = (float)tempString2;
}
else if (tempString == "drinktime")
{
drinkTime = (float)tempString2;
}
notecardLine = notecardLine + 1;
notecardQuery = llGetNotecardLine("!config",notecardLine);
}
}
else // end of notecard reached go to 'ready' state
{
state ready;
}
}
}
}
state ready
{
state_entry() // when state is entered permissions are requested
{
llRequestPermissions(drinker, PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH);
}
attach(key id) // this is because a LSL bug next time cup is attached script will start in this state
{ // and we don't want that so this takes the script to default state
if (id)
{
drinker = id;
state default;
}
}
run_time_permissions(integer perms)
{
if(perms & (PERMISSION_TRIGGER_ANIMATION | PERMISSION_ATTACH))
{
llWhisper(0,attachMessage); // 'attachMessage' is whispered
llSetTimerEvent(0.1); // lets go to the timer
llStartAnimation("sip rest loop"); // and start the base animation
}
}
timer()
{
llStartAnimation("sipping sl");
if ((currentDrinkTime < drinkTime) | (drinkTime == 0)) // keep drinkning until time is over (or drinktime equals zero)
{
llSetTimerEvent(sipTime);
}
else if (drinkTime != 0) // stop drinking if time is over
{
llWhisper(0,detachMessage);
llStopAnimation("sip rest loop");
llStopAnimation("sipping sl");
llDetachFromAvatar();
llSetTimerEvent(0.0);
}
currentDrinkTime = currentDrinkTime + sipTime; // keeps track of current drink time
}
}
Notecard for configuration, name it "!config"
Sip script 2.0 with timer
Help:
attachmessage: whispered message when attach
detachmessage: whispered message when detach
siptime: time between each sip
drinktime: total drinking time (0 for infinite)
--------------------------------------------------------------------------------------------------------------------
Notecard configuration:
#attachmessage,Mmmhh....refreshing!
#detachmessage,Hit me one more time!
#siptime,5
#drinktime,30