Difference between revisions of "Describe Chatter"

From Second Life Wiki
Jump to navigation Jump to search
m (→‎Code: lsl code tagging)
(rewrote example script cause it would not give the assume result but fail when the dataserver event is not called)
Line 11: Line 11:
<pre>
<pre>
---
---
Avatar info:
    Name: John Doe
    Birthday: 2007-09-23
    Payinfo: Has payment info on file but did not use it.
    Online status: Offline
---
</pre>


J Doe
= Code =


Born 2007-09-01
<lsl>
//  Touch prim to get avatar info as shown in the profile
//
//  http://wiki.secondlife.com/wiki/Describe_Chatter


Has no money
key nameRequestId;
key birthdayRequestId;
key payinfoRequestId;
key onlineStatusRequestId;


Online
string avatarLegacyName;
string avatarBirthday;
string avatarPayinfo;
string avatarOnlineStatus;


---
float timeoutTimeInSeconds;
</pre>
list listOfWhichKeysHaveBeenReceived;


= Code =
clear_cache()
{
    timeoutTimeInSeconds = 10.0;


<lsl>
    nameRequestId = NULL_KEY;
// Chat to see yourself as others do
    birthdayRequestId = NULL_KEY;
// http://wiki.secondlife.com/wiki/Describe_Chatter
    payinfoRequestId = NULL_KEY;
    onlineStatusRequestId = NULL_KEY;


key theDataNameKey;
    avatarLegacyName = "";
key theDataBornKey;
    avatarBirthday = "";
key theDataPayInfoKey;
    avatarPayinfo = "";
key theDataOnlineKey;
    avatarOnlineStatus = "";


integer sendableKeyings = 4;
//  yellow and opaque
integer receivedKeyings;
    llSetText("<~!~ touch to get avatar info ~!~>", <1.0, 1.0, 0.1>, (float)TRUE);


string theDataNameString;
    listOfWhichKeysHaveBeenReceived = [FALSE, FALSE, FALSE, FALSE];
string theDataBornString;
}
string theDataPayInfoString;
string theDataOnlineString;


// Say why chat with this script
initiate_requests_for_avatar_info(key avatarToRequestInfoAbout)
{
    nameRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_NAME);
    birthdayRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_BORN);
    payinfoRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_PAYINFO);
    onlineStatusRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_ONLINE);
}


startup()
process_returned_data(key query_id, string data)
{
{
     scrubKeys();
     if (query_id == nameRequestId)
     llOwnerSay("You chat at the mirror, mirror, on the wall ...");
     {
    list lines = [llGetObjectName(), llGetObjectDesc()];
        nameRequestId = NULL_KEY;
    string label = llDumpList2String(lines, "\n---\n");
        listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
    llSetText(label, <1.0, 1.0, 1.0>, 1.0);
                                            [TRUE], 0, 0);
}


// Forget old chat
        avatarLegacyName = data;
    }
    else if (query_id == birthdayRequestId)
    {
        birthdayRequestId = NULL_KEY;
        listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
                                            [TRUE], 1, 1);


scrubKeys()
        avatarBirthday = data;
{
     }
    llSetText("", <0.0, 0.0, 0.0>, 1.0);
     else if (query_id == payinfoRequestId)
      
     {
     theDataNameKey = NULL_KEY;
        payinfoRequestId = NULL_KEY;
     theDataBornKey = NULL_KEY;
        listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
    theDataPayInfoKey = NULL_KEY;
                                            [TRUE], 2, 2);
    theDataOnlineKey = NULL_KEY;
   
    receivedKeyings = 0;  
}


// Float an image of the chatter above the object
        avatarPayinfo = process_payinfo(data);
    }
    else if (query_id == onlineStatusRequestId)
    {
        onlineStatusRequestId = NULL_KEY;
        listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
                                            [TRUE], 3, 3);


receiveKeys()
         integer isOnline = (integer)data;
{
    string text = ""
         + "---\n" + " \n"
        + theDataNameString + "\n" + " \n"
        + "Born " + theDataBornString + "\n" + " \n"
        + toPayInfoEcho(theDataPayInfoString) + "\n" + " \n"
        + toOnlineEcho(theDataOnlineString) + "\n" + " \n"
        + "---\n" + " \n "
        ;
    vector color = <0.0, 1.0, 1.0>;
    float opacity = 1.0;
    llSetText(text, color, opacity);
}     


// Convert to string from PAYMENT_INFO
        if (isOnline)
            avatarOnlineStatus = "Online";
        else
            avatarOnlineStatus = "Offline";
    }
}


string toPayInfoEcho(string data)
string process_payinfo(string data)
{
{
     integer payInfo = (integer)data;
     integer payInfo = (integer)data;
    if(payInfo  & ~(PAYMENT_INFO_ON_FILE | PAYMENT_INFO_USED))
        return data;
    integer not_has = !(payInfo & PAYMENT_INFO_ON_FILE);
    integer not_used = !(payInfo & PAYMENT_INFO_USED);
    string out = "Has ";
    if(not_has)
        out += "not ";
    if(not_has == not_used)//use the proper conjunction
        out += "used but does";
    else
        out += "used and does";
    if(not_used)
        out += " not";
    return out + " have payment info on file";
}


// Convert to string from DATA_ONLINE
    if (payInfo  & ~(PAYMENT_INFO_ON_FILE | PAYMENT_INFO_USED))
        return "- payinfo request failed -";
 
    integer hasPayinfo = (payInfo & PAYMENT_INFO_ON_FILE);
    integer usedPayinfo = (payInfo & PAYMENT_INFO_USED);
 
    if (!hasPayinfo)
// {
        return "Has no payment info on file.";
//  }
//  else
//  {
        string payinfoOutput = "Has payment info on file ";
 
        if (usedPayinfo)
//      {
            payinfoOutput += "and used it.";
//      }
        else
//      {
            payinfoOutput += "but did not use it.";
//      }


string toOnlineEcho(string data)
         return payinfoOutput;
{
//  }
    integer online = (integer) data;
    if (!online)
    {
         return "Not online";
    }
    return "Online";
}
}


// Receive an image of the chatter
dump_result_to_local_chat()
 
catchKey(key queryid, string data)
{
{
        if (queryid == theDataNameKey)
    llSetTimerEvent((float)FALSE);
        {
            theDataNameString = data;
        }
        else if (queryid == theDataBornKey)
        {
            theDataBornString = data;
        }       
        else if (queryid == theDataPayInfoKey)
        {
            theDataPayInfoString = data;
        }
        else if (queryid == theDataOnlineKey)
        {
            theDataOnlineString = data;
        }
}


// Ask to receive an image of the chatter in pieces
    if (llListStatistics(LIST_STAT_MEAN, listOfWhichKeysHaveBeenReceived) != 1.0)
// {
        llSay(PUBLIC_CHANNEL, "Sorry, did not get a response for all requested info. Please try again!");
//  }
    else
//  {
        llSay(PUBLIC_CHANNEL, "Avatar info:"
            + "\n\tName: " + avatarLegacyName
            + "\n\tBirthday: " + avatarBirthday
            + "\n\tPayinfo: " + avatarPayinfo
            + "\n\tOnline status: " + avatarOnlineStatus);
//  }


sendKeys(key who)
     clear_cache();
{
    theDataNameKey = llRequestAgentData(who, DATA_NAME);
    theDataBornKey = llRequestAgentData(who, DATA_BORN);
    theDataPayInfoKey = llRequestAgentData(who, DATA_PAYINFO);
     theDataOnlineKey = llRequestAgentData(who, DATA_ONLINE);
}
}
// For each reset ...


default
default
{
{
    on_rez(integer start_param)
    {
        llResetScript();
    }


     // Listen to all ordinary chat
     changed(integer change)
   
    state_entry()
     {
     {
         startup();
         if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
        llListen(0, "", NULL_KEY, "");
            llResetScript();
     }
     }
   
 
    // Ask to receive an image of the chatter in pieces
     touch_start(integer num_detected)
   
     listen(integer channel, string name, key id, string message)
     {
     {
         if (llGetAgentSize(id) != ZERO_VECTOR)
         key touchingAvatarKey = llDetectedKey(0);
         {
 
            scrubKeys();
         clear_cache();
            sendKeys(id);
        initiate_requests_for_avatar_info(touchingAvatarKey);
         }
 
         llSetTimerEvent(timeoutTimeInSeconds);
     }
     }
   
 
    // Receive every piece of an image of the chatter
     dataserver(key query_id, string data)
   
     {
     dataserver(key queryid, string data)
         if (query_id == NULL_KEY)
     {      
            return;
         catchKey(queryid, data);  
 
        receivedKeyings += 1;
        process_returned_data(query_id, data);
         if (receivedKeyings == sendableKeyings)
 
        {
         if (llListStatistics(LIST_STAT_MEAN, listOfWhichKeysHaveBeenReceived) == 1.0)
             receiveKeys();
//      {
        }      
             dump_result_to_local_chat();
//      }
     }
     }


    timer()
    {
        dump_result_to_local_chat();
    }
}
}
</lsl>
</lsl>

Revision as of 11:43, 1 November 2012

Introduction

Your avatar in second life is differently anonymous than yourself in real life. Any other avatar and any thing can ask what your avatar's name is, what your avatar's date-of-birth is, whether payment info is on file for your avatar, etc. The Linden servers discuss your avatar in these ways without asking you for permission and without notifying you.

If you can see who is chatting, then Profile > 2nd Life will tell you things like Currently Online, Born mm/dd/yyyy, No Payment Info On File. If you don't know that, or if you can't be bothered to go there, or if you can't see who is chatting, then this script will tell you those kinds of things too.

Sample Results

---
Avatar info:
    Name: John Doe
    Birthday: 2007-09-23
    Payinfo: Has payment info on file but did not use it.
    Online status: Offline
---

Code

<lsl> // Touch prim to get avatar info as shown in the profile // // http://wiki.secondlife.com/wiki/Describe_Chatter

key nameRequestId; key birthdayRequestId; key payinfoRequestId; key onlineStatusRequestId;

string avatarLegacyName; string avatarBirthday; string avatarPayinfo; string avatarOnlineStatus;

float timeoutTimeInSeconds; list listOfWhichKeysHaveBeenReceived;

clear_cache() {

   timeoutTimeInSeconds = 10.0;
   nameRequestId = NULL_KEY;
   birthdayRequestId = NULL_KEY;
   payinfoRequestId = NULL_KEY;
   onlineStatusRequestId = NULL_KEY;
   avatarLegacyName = "";
   avatarBirthday = "";
   avatarPayinfo = "";
   avatarOnlineStatus = "";

// yellow and opaque

   llSetText("<~!~ touch to get avatar info ~!~>", <1.0, 1.0, 0.1>, (float)TRUE);
   listOfWhichKeysHaveBeenReceived = [FALSE, FALSE, FALSE, FALSE];

}

initiate_requests_for_avatar_info(key avatarToRequestInfoAbout) {

   nameRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_NAME);
   birthdayRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_BORN);
   payinfoRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_PAYINFO);
   onlineStatusRequestId = llRequestAgentData(avatarToRequestInfoAbout, DATA_ONLINE);

}

process_returned_data(key query_id, string data) {

   if (query_id == nameRequestId)
   {
       nameRequestId = NULL_KEY;
       listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
                                           [TRUE], 0, 0);
       avatarLegacyName = data;
   }
   else if (query_id == birthdayRequestId)
   {
       birthdayRequestId = NULL_KEY;
       listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
                                           [TRUE], 1, 1);
       avatarBirthday = data;
   }
   else if (query_id == payinfoRequestId)
   {
       payinfoRequestId = NULL_KEY;
       listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
                                           [TRUE], 2, 2);
       avatarPayinfo = process_payinfo(data);
   }
   else if (query_id == onlineStatusRequestId)
   {
       onlineStatusRequestId = NULL_KEY;
       listOfWhichKeysHaveBeenReceived = llListReplaceList(listOfWhichKeysHaveBeenReceived,
                                           [TRUE], 3, 3);
       integer isOnline = (integer)data;
       if (isOnline)
           avatarOnlineStatus = "Online";
       else
           avatarOnlineStatus = "Offline";
   }

}

string process_payinfo(string data) {

   integer payInfo = (integer)data;
   if (payInfo  & ~(PAYMENT_INFO_ON_FILE | PAYMENT_INFO_USED))
       return "- payinfo request failed -";
   integer hasPayinfo = (payInfo & PAYMENT_INFO_ON_FILE);
   integer usedPayinfo = (payInfo & PAYMENT_INFO_USED);
   if (!hasPayinfo)

// {

       return "Has no payment info on file.";

// } // else // {

       string payinfoOutput = "Has payment info on file ";
       if (usedPayinfo)

// {

           payinfoOutput += "and used it.";

// }

       else

// {

           payinfoOutput += "but did not use it.";

// }

       return payinfoOutput;

// } }

dump_result_to_local_chat() {

   llSetTimerEvent((float)FALSE);
   if (llListStatistics(LIST_STAT_MEAN, listOfWhichKeysHaveBeenReceived) != 1.0)

// {

       llSay(PUBLIC_CHANNEL, "Sorry, did not get a response for all requested info. Please try again!");

// }

   else

// {

       llSay(PUBLIC_CHANNEL, "Avatar info:"
           + "\n\tName: " + avatarLegacyName
           + "\n\tBirthday: " + avatarBirthday
           + "\n\tPayinfo: " + avatarPayinfo
           + "\n\tOnline status: " + avatarOnlineStatus);

// }

   clear_cache();

}

default {

   on_rez(integer start_param)
   {
       llResetScript();
   }
   changed(integer change)
   {
       if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
           llResetScript();
   }
   touch_start(integer num_detected)
   {
       key touchingAvatarKey = llDetectedKey(0);
       clear_cache();
       initiate_requests_for_avatar_info(touchingAvatarKey);
       llSetTimerEvent(timeoutTimeInSeconds);
   }
   dataserver(key query_id, string data)
   {
       if (query_id == NULL_KEY)
           return;
       process_returned_data(query_id, data);
       if (llListStatistics(LIST_STAT_MEAN, listOfWhichKeysHaveBeenReceived) == 1.0)

// {

           dump_result_to_local_chat();

// }

   }
   timer()
   {
       dump_result_to_local_chat();
   }

} </lsl>

Instructions

Add the script to an object and start chatting with a friend. See the object remember who chatted last.

See Also

Functions

llDumpList2String - insert new lines (or whatever you wish) between strings

llRequestAgentData - ask to receive an image of an agent, such as a chatter, in pieces

llSetText - float text over a prim