Difference between revisions of "Online Indicator"

From Second Life Wiki
Jump to navigation Jump to search
Line 7: Line 7:
<lsl>key owner_key = "00000000-0000-0000-0000-000000000000";      // must be agent UUID whose status it will indicate
<lsl>key owner_key = "00000000-0000-0000-0000-000000000000";      // must be agent UUID whose status it will indicate
integer time = 30;                                          // time within the message should be written.
integer time = 30;                                          // time within the message should be written.
string RESIDENT_URL = "http://world.secondlife.com/resident/";
string url = "http://world.secondlife.com/resident/";
key blank = "5748decc-f629-461c-9a36-a35a221fe21f";
key blank = "5748decc-f629-461c-9a36-a35a221fe21f";
string name;
string name;
key toucher;
key toucher;
string status;
string status;
 
default
default
{
{
Line 19: Line 19:
         llSetText("", <1,0,0>, 1.0);
         llSetText("", <1,0,0>, 1.0);
         llSetTexture(blank, ALL_SIDES);
         llSetTexture(blank, ALL_SIDES);
         llRequestAgentData( owner_key, DATA_NAME);   
         llRequestAgentData( user_key, DATA_NAME);   
     }
     }
     dataserver(key queryid, string data)
     dataserver(key queryid, string data)
     {
     {
         name = data;
         name = data;
        llSetObjectName(name + "'s Online Detector");
         state show;
         state show;
     }
     }
Line 35: Line 36:
     timer()
     timer()
     {
     {
         llHTTPRequest( RESIDENT_URL + (string)owner_key,[HTTP_METHOD,"GET"],"");
         llHTTPRequest( url + (string)user_key,[HTTP_METHOD,"GET"],"");
         llRequestAgentData( owner_key, DATA_ONLINE);   
         llRequestAgentData( user_key, DATA_ONLINE);   
     }  
     }  
     on_rez(integer start_param)
     on_rez(integer start_param)
Line 62: Line 63:
         {
         {
             status = " is online";
             status = " is online";
   
             llSetText(name + status, <0,1,0>, 1.0);
             llSetText(name + status, <0,1,0>, 1.0);
         }
         }
Line 68: Line 69:
         {
         {
             status = " is offline";
             status = " is offline";
           
             llSetText(name + status, <1,0,0>, 1.0);
             llSetText(name + status, <1,0,0>, 1.0);
         }
         }
       
     }
     }
     touch_start(integer num_detected)
     touch_start(integer num_detected)
Line 89: Line 90:
     listen(integer ch, string name, key id, string msg)
     listen(integer ch, string name, key id, string msg)
     {
     {
         llInstantMessage(owner_key, msg);
         llInstantMessage(user_key, msg);
         llInstantMessage(toucher, "message is sent");
         llInstantMessage(toucher, "message is sent");
         llListenRemove(0);
         llListenRemove(0);
Line 96: Line 97:
     timer()
     timer()
     {
     {
         llInstantMessage(toucher, "time is up - touch again to write a message");
         llInstantMessage(toucher, "time is up - touch again to write a message or open " + name + "'s profile by clicking this link: secondlife:///app/agent/" + (string)user_key + "/about and start IM from there, if the user is online.");
         llListenRemove(0);  
         llListenRemove(0);  
         state show;
         state show;

Revision as of 13:15, 14 January 2009

This script will show if the user is online or offline - will create hover text.

Will show user profile picture on the object and when touched, then toucher can send IM to user.

<lsl>key owner_key = "00000000-0000-0000-0000-000000000000"; // must be agent UUID whose status it will indicate integer time = 30; // time within the message should be written. string url = "http://world.secondlife.com/resident/"; key blank = "5748decc-f629-461c-9a36-a35a221fe21f"; string name; key toucher; string status;

default {

   state_entry()
   {
       llSetText("", <1,0,0>, 1.0);
       llSetTexture(blank, ALL_SIDES);
       llRequestAgentData( user_key, DATA_NAME);   
   }
   dataserver(key queryid, string data)
   {
       name = data;
       llSetObjectName(name + "'s Online Detector");
       state show;
   }

} state show {

   state_entry()
   {
       llSetTimerEvent(10);
   } 
   timer()
   {
       llHTTPRequest( url + (string)user_key,[HTTP_METHOD,"GET"],"");
       llRequestAgentData( user_key, DATA_ONLINE);   
   } 
   on_rez(integer start_param)
   {
       llSetText("", <1,0,0>, 1.0);
       llSetTexture(blank, ALL_SIDES);
   } 
   http_response(key request_id,integer status, list metadata, string body)
   { 
       if (llSubStringIndex(body, "blank.jpg") == -1)
       {
           integer start_UUID = llSubStringIndex(body,"<img alt=\"profile image\" src=\"http://secondlife.com/app/image/") + llStringLength("<img alt=\"profile image\" src=\"http://secondlife.com/app/image/");
           integer end_UUID = llSubStringIndex(body,"\" class=\"parcelimg\" />") - 3;
           string profile_pic = llGetSubString(body, start_UUID, end_UUID);
           llSetTexture((key)profile_pic, ALL_SIDES);
       }
       else
       {
           llSetTexture(blank, ALL_SIDES);
       }
   }
   dataserver(key queryid, string data)
   {
       if ( data == "1" ) 
       {
           status = " is online";

           llSetText(name + status, <0,1,0>, 1.0);
       }
       else if (data == "0")
       {
           status = " is offline";

           llSetText(name + status, <1,0,0>, 1.0);
       }

   }
   touch_start(integer num_detected)
   {
       toucher = llDetectedKey(0);
       state msg;
   }

} state msg {

    state_entry()
   {
       llListen(0,"",toucher,"");
       llInstantMessage(toucher, "write your message to " + name +" - you have " +(string)time + " seconds");
       llSetTimerEvent(time);   
   }
   listen(integer ch, string name, key id, string msg)
   {
       llInstantMessage(user_key, msg);
       llInstantMessage(toucher, "message is sent");
       llListenRemove(0);
       state show;
   }
   timer()
   {
       llInstantMessage(toucher, "time is up - touch again to write a message or open " + name + "'s profile by clicking this link: secondlife:///app/agent/" + (string)user_key + "/about and start IM from there, if the user is online.");
       llListenRemove(0); 
       state show;
   }

}</lsl>