Script onlineindicator

From The SchomEmunity Wiki
Jump to: navigation, search

I've been asked to provide this as a freebie with a quick explanation, so here we go.

Online Indicators

The script is designed to be part of an 'online indicator board'. These should include a prim showing a picture of the avatar who is being reported on or offline, with a separate prim containing this script and two images, one for online one for offline. (see picture for Schome Park example). The idea is that when the avatar represented by the board is online the 'online' image is displayed, and when the avatar is not online the 'offline' image is displayed.

The latest version of the script (as detailed below) is set to no avatar at all when it is first rezzed. The first avatar to touch the object will be the one that the board then performs the online/offline check on.

The script itself is very simple with three key areas. Firstly a timer is set to check the status of the avatar every 60 seconds. Secondly the 'touch_start' function detects the first avatar to touch the board and locks the script to that avatar, and finally the 'dataserver' event (called by the timer event) checks whether said avatar is online or offline.


Here comes the script...


// Online Status Indicator Script v3.  Dan Seamans / Woop Superior

// The online indicator will become active for the first
// user that clicks/touches the indicator


string  whotocheck= "";
integer UUIDlocked = 0;

default
{
    state_entry()
    {
        llSetTimerEvent(60); 
    }
    
    touch_start(integer num)
    {
        if (UUIDlocked == 0)
        {
            UUIDlocked = 1;
            whotocheck = llDetectedKey(0);
            llSay(0,"Indicator set to " + llKey2Name(llDetectedKey(0))); 
            llSay(0,"It may take a minute to update the status indicator");
        }
    } 
    
    timer()
    {
        llRequestAgentData(whotocheck, DATA_ONLINE);
    } 
    
    dataserver(key queryid, string data)
    {
        if ((integer)data == 1)
        {
            llSetTexture("online",ALL_SIDES);    
        }
        else
        {
            llSetTexture("offline",ALL_SIDES);
        }    
    }
}