Online Status Display & Pager ( V1 )

Written by Kitsune

This will display the owners profile picture and a color coded and text texture sign that changes depending on the owners online status.

 

Just drop the script into a fresh prim.

 

// V1 //
 
key owner_id; // Use to store the UUID of the owner to save having to keep asking.
 
string owner_name; // Use to store the name of the owner to save having to keep asking.
 
// This a UUID of a texture I created to show either the word "ONLINE" or "OFFLINE".
key ON_OFF_line = "124cfcec-6b8d-552c-42b8-6a1179884e74";
 
// This is added to the owner UUID to make an HTTP request for the owners profile image UUID.
string profile_url = "http://world.secondlife.com/resident/";
 
key name_id; // This key is used to recognize the dataserver request if it is for the name of the owner.
 
key online_id; // This key is used to recognize the dataserver request if it is made automatically.
 
key touch_request_id; // This key is used to recognize the dataserver request if it is made by a user.
 
key update_id; // Used to verify that the HTTP request is for an update of the profile texture.
 
integer lis; // This is used to store the value of a listen and to remove it when not needed.
 
integer channel; // This is used to store the value of the listen channel.
 
key requester; // This is used to store the name of a user who asks to page the owner.
 
string date; // Used to store the date (just in case you couldn't guess).
 
OnlineStatus(integer ol, integer tr) // This function carries two integer type pieces of info.
{ // integer ol is the the boolean online data. 1 for online and zero for offline.
  // integer tr is also boolean. It carries whether the function is being called by a user or automatically.
    list ol_params = []; // This is a local list creation.
    if(ol) // If the owner is online...
    ol_params = [17, 5, ON_OFF_line, <1.4,0.25,0.0>, <0.0,0.375,0.0>, (90*DEG_TO_RAD), // ..list the object parameters for displaying ONLINE.
                 18, 5, <0.0,1.0,0.0>, 1.0,
                 18, 6, <1.0,1.0,1.0>, 1.0];
    else // If not...
    ol_params = [17, 5, ON_OFF_line, <1.4,0.25,0.0>, <0.0,0.625,0.0>, (90*DEG_TO_RAD), // ..list the object parameters for displaying OFFLINE.
                 18, 5, <1.0,0.0,0.0>, 1.0,
                 18, 6, <0.5,0.5,0.5>, 1.0];
    llSetPrimitiveParams(ol_params); // Set the object parameters to show whatever the list is.
    if(tr) // If this was a touch request...
    {
        llSetTimerEvent(30.0); // Prepare to be ignored (we need to switch the listen off if we are ignored).
        if(ol) // If the owner is online...
        {
            lis = llListen(channel, "", requester, ""); // Open a listen for the user who made the request.
            llDialog(requester, ("\nWould you like to page " + owner_name + "?"), ["YES", "NO"], channel); // Send them a dialog.
        }
        else // If not...
        llInstantMessage(requester, (owner_name + " is currently offline.")); // Send a message explaining that the owner is offline.
    }
}
 
default // Create an area for the events to play in. This is called a "state".
{
    state_entry() // On state entry...
    {
        owner_id = llGetOwner(); // Get the owner UUID (key) and store it.
        name_id = llRequestAgentData(owner_id, DATA_NAME); // Make a request for the owners name.
        channel = -5647; // Set a channel to use for the dialog.
    }
    dataserver(key q, string data) // Triggered when a reply to a data request is recieved.
    {
        if(q == name_id) // Check the id of the request.
        {
            owner_name = data; // Store the result.
            llSetObjectName(owner_name + "'s Online Status"); // Set the name of the object to the owner name + "'s Online Status".
            llHTTPRequest((profile_url + ((string)owner_id)), [], ""); // Request the UUID of the owners profile.
        }
        else if(q == online_id) // Check the id of the request.
        OnlineStatus(((integer)data), FALSE); // Call the OnlineStatus function for an automatic return.
        else if(q == touch_request_id) // Check the id of the request.
        OnlineStatus(((integer)data), TRUE); // Call the OnlineStatus function for a touch-by-user return.
    }
    http_response(key q, integer status, list metadata, string body) // Triggered when a response for an HTTP request is recieved.
    {
        integer tex_key_start = (llSubStringIndex(body, "imageid") + 18); // Establish the point where the image UUID is written in the page.
        integer tex_key_end = (tex_key_start + 35); // Establish the point where the image UUID ends.
        key profile_image = ((key)llGetSubString(body, tex_key_start, tex_key_end)); // Store the the profile image UUID found.
        if(q != update_id) // Check the source of the request.
        {
            llSetPrimitiveParams([9, 0, 0, <0.6,0.875,0.0>, 0.02, ZERO_VECTOR, <1.0,1.0,0.0>, ZERO_VECTOR, // Shape the object...
                                  8, llEuler2Rot(<0.0,90.0,0.0>*DEG_TO_RAD),
                                  7, <0.85,0.01,0.6>,
                                  17, -1, TEXTURE_BLANK, <1.0,1.0,0.0>, ZERO_VECTOR, 0.0,
                                  18, -1, ZERO_VECTOR, 1.0]); // ...and texture it with the owners profile image and...
            llSetPrimitiveParams([17, 6, profile_image, <1.0,1.0,0.0>, ZERO_VECTOR, (90*DEG_TO_RAD),
                                  17, 5, ON_OFF_line, <1.4,0.25,0.0>, <0.0,0.375,0.0>, (90*DEG_TO_RAD), // the ON/OFFline texture.
                                  19, 5, 0, 1,
                                  18, 6, <1.0,1.0,1.0>, 1.0,
                                  18, 5, <0.0,1.0,0.0>, 1.0,
                                  20, 5, 1,
                                  20, 6, 1]);
            llSetTimerEvent(0.1); // Move to the timer quickly to run the first OnlineStatus check.
        }
        else
        llSetPrimitiveParams([17, 6, profile_image, <1.0,1.0,0.0>, ZERO_VECTOR, (90*DEG_TO_RAD)]); // Apply the updated profile texture.
    }
    timer() // Triggered if a timer event is set to a non zero amount.
    {
        llSetTimerEvent(10.0); // Reset the timer event to trigger every 10 seconds.
        llListenRemove(lis); // Always remove any listen we have open.
        online_id = llRequestAgentData(owner_id, DATA_ONLINE); // So every 10 seconds we check if the owner is online.
        string t_date = llGetDate(); // Find out what the date is.
        if(t_date != date) // Check if the date has changed. If it has...
        {
            date = t_date; // ...store the date so the next check to return true will be roughly 24 hours later.
            update_id = llHTTPRequest((profile_url + ((string)owner_id)), [], ""); // Request an update of the UUID of the owners profile.
        }
    }
    touch_start(integer nd) // Triggered on clicking the object that contains the script.
    {
        llSetTimerEvent(0.0); // Stop the timer.
        requester = llDetectedKey(0); // Store the UUID of the person who touched us.
        touch_request_id = llRequestAgentData(owner_id, DATA_ONLINE); // Request the online status of the owner before issuing any dialogs.
    } // We do this becuse if the owner went offline 9 seconds ago we wouldn't know.
    listen(integer chan, string name, key id, string msg) // Triggered when all the specified info is recieved by the script if it has a listen open.
    {
        llListenRemove(lis); // Remove the listen.
        llSetTimerEvent(10.0); // Set the timer to run automatically.
        if(msg == "YES") // If the toucher wants to page the owner (the owner must be online)...
        { // Instant message the owner with a link that when clicked will bring up the touchers profile. This saves searching for the touchers profile.
            llInstantMessage(owner_id, ("secondlife:///app/agent/" + ((string)requester) + "/about has requested to message you."));
            llInstantMessage(requester, owner_name + " has been paged."); // Inform the toucher that the owner has been paged.
        }
    }
}