Difference between revisions of "Describe Chatter"

From Second Life Wiki
Jump to navigation Jump to search
m (fixed a error in the script that was forcing it not to compile. Also removed the word "Legal" from "Your Avatar's Legal Name" as the phrase previously suggested that the "user's name" was available.)
(Clean up code. Avoid double click issues.)
 
(3 intermediate revisions by 3 users not shown)
Line 3: Line 3:
= Introduction =
= 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.
Another avatar or object 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 will return this information 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.
If you can see an avatar's profile, then Profile > 2nd Life will tell you things like Currently Online, Born mm/dd/yyyy, No Payment Info On File. If you can't, then this script can tell you those kinds of things.


= Sample Results =
= Sample Results =
Line 11: Line 11:
<pre>
<pre>
---
---
 
Avatar info:
J Doe
    Name: John Doe
 
    Birthday: 2007-09-23
Born 2007-09-01
    Payinfo: Has unused payment info on file.
 
    Online status: Offline
Has no money
 
Online
 
---
---
</pre>
</pre>
Line 25: Line 21:
= Code =
= Code =


<pre>
<source lang="lsl2">
// Chat to see yourself as others do
// Touch prim to get avatar info as shown in the profile
// http://wiki.secondlife.com/wiki/Describe_Chatter
//
//  http://wiki.secondlife.com/wiki/Describe_Chatter


key theDataNameKey;
key nameRequestId;
key theDataBornKey;
key birthdayRequestId;
key theDataPayInfoKey;
key payinfoRequestId;
key theDataOnlineKey;
key onlineStatusRequestId;


integer sendableKeyings = 4;
string avatarLegacyName;
integer receivedKeyings;
string avatarBirthday;
string avatarPayinfo;
string avatarOnlineStatus;


string theDataNameString;
integer    gEventsReceived;               // Bit pattern of received dataserver events
string theDataBornString;
integer    gMaskName = 1;
string theDataPayInfoString;
integer    gMaskBirthday = 2;
string theDataOnlineString;
integer    gMaskPayinfo = 4;
integer    gMaskOnline  = 8;


// Say why chat with this script
key        gToucher;


startup()
clear_cache()
{
{
     scrubKeys();
     gEventsReceived = 0;
     llOwnerSay("You chat at the mirror, mirror, on the wall ...");
     avatarLegacyName = "";
     list lines = [llGetObjectName(), llGetObjectDesc()];
     avatarBirthday = "";
     string label = llDumpList2String(lines, "\n---\n");
     avatarPayinfo = "";
     llSetText(label, <1.0, 1.0, 1.0>, 1.0);
     avatarOnlineStatus = "";
}
}


// Forget old chat
default
 
scrubKeys()
{
{
     llSetText("", <0.0, 0.0, 0.0>, 1.0);
     state_entry()
      
    {
     theDataNameKey = NULL_KEY;
        llSetTimerEvent(0);
     theDataBornKey = NULL_KEY;
        //  yellow and opaque
    theDataPayInfoKey = NULL_KEY;
        llSetText("<~!~ touch to get avatar info ~!~>", <1, 1, 0>, 1);
     theDataOnlineKey = NULL_KEY;
     }
   
     on_rez(integer start_param)
    receivedKeyings = 0;   
     {
}
        llResetScript();
     }


// Float an image of the chatter above the object
    changed(integer change)
    {
        if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
            llResetScript();
    }


receiveKeys()
     touch_end(integer num_detected)
{
     {
     string text = ""
         gToucher = llDetectedKey(0);
        + "---\n" + " \n"
         state working;
        + 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
 
string toPayInfoEcho(string 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
state working
 
string toOnlineEcho(string data)
{
{
     integer online = (integer) data;
     state_entry()
    if (!online)
     {
     {
         return "Not online";
         llSetText("=== please wait ===", <1, 0, 0>, 1);
        clear_cache();
        nameRequestId = llRequestAgentData(gToucher, DATA_NAME);
        birthdayRequestId = llRequestAgentData(gToucher, DATA_BORN);
        payinfoRequestId = llRequestAgentData(gToucher, DATA_PAYINFO);
        onlineStatusRequestId = llRequestAgentData(gToucher, DATA_ONLINE);
        llSetTimerEvent(10);
     }
     }
    return "Online";
}


// Receive an image of the chatter
    dataserver(key query_id, string data)
    {
        if (query_id == NULL_KEY)
            return;


catchKey(key queryid, string data)
         if (query_id == nameRequestId)
{
         if (queryid == theDataNameKey)
         {
         {
             theDataNameString = data;
             gEventsReceived = gEventsReceived | gMaskName;
            avatarLegacyName = data;
         }
         }
         else if (queryid == theDataBornKey)
         else if (query_id == birthdayRequestId)
         {
         {
             theDataBornString = data;
             gEventsReceived = gEventsReceived | gMaskBirthday;
         }      
            avatarBirthday = data;
         else if (queryid == theDataPayInfoKey)
         }
         else if (query_id == payinfoRequestId)
         {
         {
             theDataPayInfoString = data;
             gEventsReceived = gEventsReceived | gMaskPayinfo;
            integer payInfo = (integer)data;
            if (payInfo  & ~(PAYMENT_INFO_ON_FILE | PAYMENT_INFO_USED))
                avatarPayinfo = "- payinfo request failed -";
 
            else
            {
                integer hasPayinfo = (payInfo & PAYMENT_INFO_ON_FILE);
                integer usedPayinfo = (payInfo & PAYMENT_INFO_USED);
                avatarPayinfo = "Has no payment info on file.";
                if (hasPayinfo)
                {
                    avatarPayinfo = "Has unused payment info on file.";
                    if (usedPayinfo)
                        avatarPayinfo =  "Has used payment info on file.";
                }
            }
         }
         }
         else if (queryid == theDataOnlineKey)
         else if (query_id == onlineStatusRequestId)
         {
         {
             theDataOnlineString = data;
             gEventsReceived = gEventsReceived | gMaskOnline;
            avatarOnlineStatus = "Offline";
            if ( (integer) data )
                avatarOnlineStatus = "Online";
         }
         }
}


// Ask to receive an image of the chatter in pieces
        if (gEventsReceived == (gMaskName | gMaskBirthday | gMaskPayinfo | gMaskOnline ) )
 
sendKeys(key who)
{
    theDataNameKey = llRequestAgentData(who, DATA_NAME);
    theDataBornKey = llRequestAgentData(who, DATA_BORN);
    theDataPayInfoKey = llRequestAgentData(who, DATA_PAYINFO);
    theDataOnlineKey = llRequestAgentData(who, DATA_ONLINE);
}
 
// For each reset ...
 
default
{
 
    // Listen to all ordinary chat
   
    state_entry()
    {
        startup();
        llListen(0, "", NULL_KEY, "");
    }
   
    // Ask to receive an image of the chatter in pieces
   
    listen(integer channel, string name, key id, string message)
    {
        if (llGetAgentSize(id) != ZERO_VECTOR)
         {
         {
             scrubKeys();
             llSay(0, "Avatar info:"
             sendKeys(id);
                + "\n\tName: " + avatarLegacyName
                + "\n\tBirthday: " + avatarBirthday
                + "\n\tPayinfo: " + avatarPayinfo
                + "\n\tOnline status: " + avatarOnlineStatus);
             state default;
         }
         }
     }
     }
   
 
    // Receive every piece of an image of the chatter
     timer()
   
     {
     dataserver(key queryid, string data)
         llSay(0, "Sorry, did not get a response for all requested info. Please try again!");
     {      
         state default;
         catchKey(queryid, data)
        receivedKeyings += 1;
         if (receivedKeyings == sendableKeyings)
        {
            receiveKeys();
        }       
     }
     }
}
}
</pre>
</source>
 
= Instructions =
 
Add the script to an object and start chatting with a friend. See the object remember who chatted last.


= See Also =
= See Also =
Line 196: Line 158:
'''Functions'''
'''Functions'''


[[llDumpList2String]] - insert new lines (or whatever you wish) between strings
[[llRequestAgentData]] - ask to receive information about of an agent, such as birth date
 
[[llRequestAgentData]] - ask to receive an image of an agent, such as a chatter, in pieces


[[llSetText]] - float text over a prim
[[llSetText]] - float text over a prim


{{LSLC|Library}}{{LSLC|Examples}}
{{LSLC|Library}}{{LSLC|Examples}}

Latest revision as of 09:41, 21 January 2016

Introduction

Another avatar or object 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 will return this information without asking you for permission and without notifying you.

If you can see an avatar's profile, then Profile > 2nd Life will tell you things like Currently Online, Born mm/dd/yyyy, No Payment Info On File. If you can't, then this script can tell you those kinds of things.

Sample Results

---
Avatar info:
    Name: John Doe
    Birthday: 2007-09-23
    Payinfo: Has unused payment info on file.
    Online status: Offline
---

Code

//  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;

integer    gEventsReceived;               // Bit pattern of received dataserver events
integer    gMaskName = 1;
integer    gMaskBirthday = 2;
integer    gMaskPayinfo = 4;
integer    gMaskOnline  = 8;

key        gToucher;

clear_cache()
{
    gEventsReceived = 0;
    avatarLegacyName = "";
    avatarBirthday = "";
    avatarPayinfo = "";
    avatarOnlineStatus = "";
}

default
{
    state_entry()
    {
        llSetTimerEvent(0);
        //  yellow and opaque
        llSetText("<~!~ touch to get avatar info ~!~>", <1, 1, 0>, 1);
    }
    on_rez(integer start_param)
    {
        llResetScript();
    }

    changed(integer change)
    {
        if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
            llResetScript();
    }

    touch_end(integer num_detected)
    {
        gToucher = llDetectedKey(0);
        state working;
    }
}

state working
{
    state_entry()
    {
        llSetText("=== please wait ===", <1, 0, 0>, 1);
        clear_cache();
        nameRequestId = llRequestAgentData(gToucher, DATA_NAME);
        birthdayRequestId = llRequestAgentData(gToucher, DATA_BORN);
        payinfoRequestId = llRequestAgentData(gToucher, DATA_PAYINFO);
        onlineStatusRequestId = llRequestAgentData(gToucher, DATA_ONLINE);
        llSetTimerEvent(10);
    }

    dataserver(key query_id, string data)
    {
        if (query_id == NULL_KEY)
            return;

        if (query_id == nameRequestId)
        {
            gEventsReceived = gEventsReceived | gMaskName;
            avatarLegacyName = data;
        }
        else if (query_id == birthdayRequestId)
        {
            gEventsReceived = gEventsReceived | gMaskBirthday;
            avatarBirthday = data;
        }
        else if (query_id == payinfoRequestId)
        {
            gEventsReceived = gEventsReceived | gMaskPayinfo;
            integer payInfo = (integer)data;
            if (payInfo  & ~(PAYMENT_INFO_ON_FILE | PAYMENT_INFO_USED))
                avatarPayinfo = "- payinfo request failed -";

            else
            {
                integer hasPayinfo = (payInfo & PAYMENT_INFO_ON_FILE);
                integer usedPayinfo = (payInfo & PAYMENT_INFO_USED);
                avatarPayinfo = "Has no payment info on file.";
                if (hasPayinfo)
                {
                    avatarPayinfo = "Has unused payment info on file.";
                    if (usedPayinfo)
                        avatarPayinfo =  "Has used payment info on file.";
                }
            }
        }
        else if (query_id == onlineStatusRequestId)
        {
            gEventsReceived = gEventsReceived | gMaskOnline;
            avatarOnlineStatus = "Offline";
            if ( (integer) data )
                avatarOnlineStatus = "Online";
        }

        if (gEventsReceived == (gMaskName | gMaskBirthday | gMaskPayinfo | gMaskOnline ) )
        {
            llSay(0, "Avatar info:"
                + "\n\tName: " + avatarLegacyName
                + "\n\tBirthday: " + avatarBirthday
                + "\n\tPayinfo: " + avatarPayinfo
                + "\n\tOnline status: " + avatarOnlineStatus);
            state default;
        }
    }

    timer()
    {
        llSay(0, "Sorry, did not get a response for all requested info. Please try again!");
        state default;
    }
}

See Also

Functions

llRequestAgentData - ask to receive information about of an agent, such as birth date

llSetText - float text over a prim