Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Online Detector v1.1

a lost user
Join date: ?
Posts: ?
08-27-2005 06:06
Online Detector v1.1 by Gaz Hornpipe

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;


// The get_date() function was pulled irectly from the wiki and changed.. again.
// The original function was made by a Linden, changed by me and then
// changed again by someone else, who in my opinion, broke the function.

// Returns the current time and date as a formatted string
// eg. 02:30:64 29-Aug-2005
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 listening to someone using the dialog menu
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 noone has set their ID yet
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 the person touching is the same person who set their ID
if(llDetectedName(0) == name_str)
{
start_listen(llDetectedKey(0));
llDialog(llDetectedKey(0),"Turn the InstantMessager ON or OFF:",["On","Off"],512);
return;
}
else
{ // For everyone else who touches
if(IM && ONLINE) // Only send an IM if person is online and has IMs engaged
{
llInstantMessage(person_id, llDetectedName(0) + " is paging you from " + llGetRegionName());
llWhisper(0,"A message has been sent to " + name_str);
}
}
}

listen(integer channel, string name, key id, string message)
{
// Remove the listen.. it's not needed anymore.
llListenRemove(listening);

// Set up the detector to detect this person.
if(message == "Set ID")
{
person_id = id;
name_str = name;
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;
}

// Turn IMs on
if(message == "On")
{
IM = TRUE;
llWhisper(0, "/me will send you IMs when touched.");
llListenRemove(listening);
return;
}

// Turn IMs off
if(message == "Off")
{
IM = FALSE;
llWhisper(0, "/me will no longer send IMs when touched.");
llListenRemove(listening);
return;
}
}

timer()
{
// Only request agent data if someone has set their ID to be detected
if(person_id)
{
llRequestAgentData(person_id,DATA_ONLINE);
}
}

dataserver(key query, string data)
{
// A string to use for the set text
string text = "";

// If the data is 1, that means they are Online
if((integer)data == 1)
{
ONLINE = TRUE;
llSetColor(<0,1,0>,ALL_SIDES); // Set color to green
text = name_str + " is ONLINE";
if(IM) text += "\nClick to Send IM"; // only display this if IMs are engaged
llSetText(text, <0.25,1.0,0.25>,1);
last_online = ""; // NULL the last_online variable.
}
else
{
ONLINE = FALSE;
llSetColor(<1,0,0>,ALL_SIDES); // Set color to red
text = name_str + " is OFFLINE";

// Grab the time and date but only if the last_online variable doesn't
// contain a value yet.
if(last_online == "") last_online = get_date();
text += "\nLast Online: " + last_online;
llSetText(text, <1.0,0.25,0.25>,1);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
08-28-2005 04:09
/54/48/59350/1.html
_____________________
i've got nothing. ;)