The Online Detector by Gaz Hornpipe is a cheap, fully-functional object that detects whether people are on or off line. Free to distribute.
Features:
- Does not have to be owned by the person it is detecting like other similar products.
- Simple menu-based setup.
- Free to copy/transfer to friends.
Functions:
Online:
- Detector turns green for instant online recognition.
- Detector shows name of person being detected.
- May send IM messages to the person being detected when touched.
- Person being detected may touch the detector to turn IMs on or off.
Offline:
- Detector turns red for instant offline recognition.
- Detector shows name of person being detected.
- Detector shows time and date the person logged off.
- Will not send IMs when person is offline.
CODE
string name_str = "";
string last_online = "";
key person_id = "";
integer listening = 0;
integer IM = TRUE;
integer ONLINE = FALSE;
string get_date()
{
integer t;
integer hours;
integer minutes;
integer seconds;
string time;
t = llRound(llGetWallclock());
// one hour has 3600 seconds
hours = t / 3600; // get hours (integer division chops off the decimals)
// the modulo operator % gets the remainder of a divison
// in this case, the remaining seconds after removing the full hours
minutes = (t % 3600) / 60; // divide by 60 because we want minutes, chops off decimals again
seconds = t % 60; // get the seconds that didn't fit into full minutes
time = (string)hours + ":";
if(minutes < 10) time += "0" + (string)minutes + ":";
else time += (string)minutes + ":";
if(seconds < 10) time += "0" + (string)seconds;
else time += (string)seconds;
string DateToday = "";
string DateUTC = llGetDate();
list DateList = llParseString2List(DateUTC, ["-", "-"], []);
integer year = llList2Integer(DateList, 0);
integer month = llList2Integer(DateList, 1);
integer day = llList2Integer(DateList, 2);
if(day < 10) DateToday = "0";
DateToday += (string)day + "-";
if(month == 1) DateToday += "Jan-";
if(month == 2) DateToday += "Feb-";
if(month == 3) DateToday += "Mar-";
if(month == 4) DateToday += "Apr-";
if(month == 5) DateToday += "May-";
if(month == 6) DateToday += "Jun-";
if(month == 7) DateToday += "Jul-";
if(month == 8) DateToday += "Aug-";
if(month == 9) DateToday += "Sep-";
if(month == 10) DateToday += "Oct-";
if(month == 11) DateToday += "Nov-";
if(month == 12) DateToday += "Dec-";
DateToday += (string)year;
time = time + " " + DateToday;
return time;
}
start_listen(key id)
{
if(listening) llListenRemove(listening);
listening = llListen(512,"",id,"");
}
default
{
on_rez(integer p)
{
llResetScript();
}
state_entry()
{
llSetText("Online Detector\nTouch for Menu",<1,1,1>,1);
}
touch_start(integer total_number)
{
if(name_str == "")
{
start_listen(llDetectedKey(0));
llDialog(llDetectedKey(0),"Click Set ID to use your ID for the detection:",["Set ID"],512);
return;
}
if(llDetectedName(0) == name_str)
{
start_listen(llDetectedKey(0));
llDialog(llDetectedKey(0),"Turn the InstantMessager ON or OFF:",["On","Off"],512);
return;
}
else
{
if(IM && ONLINE)
{
llInstantMessage(person_id, llDetectedName(0) + " is paging you from " + llGetRegionName());
llWhisper(0,"A message has been sent to " + llKey2Name(person_id));
}
}
}
listen(integer channel, string name, key id, string message)
{
if(message == "Set ID")
{
person_id = id;
name_str = name;
llListenRemove(listening);
llWhisper(0, "/me will now detect if " + name_str + " is online or not.");
llSetText(name_str + "\nInitializing...",<1,1,1>,1);
llSetTimerEvent(5.0);
return;
}
if(message == "On")
{
IM = TRUE;
llWhisper(0, "/me will send you IMs when touched.");
llListenRemove(listening);
return;
}
if(message == "Off")
{
IM = FALSE;
llWhisper(0, "/me will no longer send IMs when touched.");
llListenRemove(listening);
return;
}
}
timer()
{
if(person_id)
{
llRequestAgentData(person_id,DATA_ONLINE);
}
}
dataserver(key query, string data)
{
string text = "";
if((integer)data == 1)
{
ONLINE = TRUE;
llSetColor(<0,1,0>,ALL_SIDES);
text = name_str + " is ONLINE";
if(IM) text += "\nClick to Send IM";
llSetText(text, <0.25,1.0,0.25>,1);
last_online = "";
}
else
{
ONLINE = FALSE;
llSetColor(<1,0,0>,ALL_SIDES);
text = name_str + " is OFFLINE";
if(last_online == "") last_online = get_date();
text += "\nLast Online: " + last_online;
llSetText(text, <1.0,0.25,0.25>,1);
}
}
}