Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: 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;

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);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Ă–riginal Thread
08-28-2005 04:09
/15/30/59251/1.html
_____________________
i've got nothing. ;)
Robin Peel
Registered User
Join date: 8 Feb 2005
Posts: 163
10-31-2005 15:59
nice. i've been looking for one that does this.
Thanks for posting
Padraig Stygian
The thin mick
Join date: 15 Aug 2004
Posts: 111
10-31-2005 16:21
I was just about to write something like that... :) Thanks for beating me to it.
_____________________
(You): Aww! My pants won't rez! Does this texture look okay on me?

Incidental Radio :: Because nothing is by design
Now featuring Torley-tastic technomusic!
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
01-20-2006 12:47
Thank you Gaz! I think I'm going to use this as an enhancement to some of my retail locations, so my customers can easily page me if they want assistance!

A few questions:

Will it detect if the keyed person is on-line, but not in the same sim?

If I read the code correctly, it looks like it checks once every 5 minutes to see if the keyed person is on-line. Is that correct? Or is that once every 5 seconds? Either way, if the keyed user went off-line before the detector realized this, it would just send an IM that would get stored until next time, right?

Would there be a way to modify this script so it would also do a quick online-check at the time the object was clicked, just in case you had gone off-line less than 5 min ago? That way a customer won't think you intentionally went off-line while ignoring their IM Page.
Illya Sullivan
Wench
Join date: 3 Dec 2005
Posts: 61
01-20-2006 13:30
Very nice. Instead of the ifs to select the month name, why not try this:

CODE

list months = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
string month = llList2String(months, monthIndex);
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-20-2006 15:29
From: Ceera Murakami
Would there be a way to modify this script so it would also do a quick online-check at the time the object was clicked, just in case you had gone off-line less than 5 min ago? That way a customer won't think you intentionally went off-line while ignoring their IM Page.


Looking at this code...

CODE
//Original code
{
if(IM && ONLINE)
{
llInstantMessage(person_id, llDetectedName(0) + " is paging you from " + llGetRegionName());
llWhisper(0,"A message has been sent to " + llKey2Name(person_id));
}
}


Add this routine:

CODE

string pager;
checkPage()
{
if(pager == "") return;
if(ONLINE)
{
llInstantMessage(person_id, pager + " is paging you from " + llGetRegionName());
llWhisper(0,"A message has been sent to " + llKey2Name(person_id));
}
else
{
llWhisper(0,"Sorry, "+pager+", "+person_id+" just went offline.");
}
pager = "";
}


Change the original touch code to:

CODE
//Changed code
{
if(IM && ONLINE)
{
pager = llDetectedName(0);
llRequestAgentData(person_id,DATA_ONLINE);
}
}


And at the end of dataserver():

CODE
//See if there's any work to do
checkPage();
Abraham Attenborough
Registered User
Join date: 4 Feb 2007
Posts: 96
08-10-2007 02:44
*edit, sorry but the problem i had had resolved itself