Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Proximity pager

Folk Singer
Buddhist Monk
Join date: 13 Sep 2005
Posts: 5
09-20-2005 21:32
I found a script called "Visitor List Maker" that keeps a running list of visitors that pass within a given proximity of the object which I use to keep track of who ahs visited my shop. I would like to add to the script so that it pages me when someone stops by and I am online. If someone has a paging script I might be able to figure out how to combine the two. Any help would be greatly appreciated :)

Here's the other script:

// Global variables
list visitor_list;
float range = 10.0; // in meters
float rate = 1.0; // in seconds


// Functions
integer isNameOnList( string name )
{
integer len = llGetListLength( visitor_list );
integer i;
for( i = 0; i < len; i++ )
{
if( llList2String(visitor_list, i) == name )
{
return TRUE;
}
}
return FALSE;
}

// States
default
{
state_entry()
{
llSay(0, "Visitor List Maker started...";);
llSay(0, "The owner can say 'help' for instructions.";);
llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
llListen(0, "", llGetOwner(), "";);
}


sensor( integer number_detected )
{
integer i;
for( i = 0; i < number_detected; i++ )
{
if( llDetectedKey( i ) != llGetOwner() )
{
string detected_name = llDetectedName( i );
if( isNameOnList( detected_name ) == FALSE )
{
visitor_list += detected_name;
}
}
}
}

listen( integer channel, string name, key id, string message )
{
if( id != llGetOwner() )
{
return;
}

if( message == "help" )
{
llSay( 0, "This object records the names of everyone who" );
llSay( 0, "comes within "+ (string)range + " meters." );
llSay( 0, "Commands the owner can say:" );
llSay( 0, "'help' - Shows these instructions." );
llSay( 0, "'say list' - Says the names of all visitors on the list.";);
llSay( 0, "'reset list' - Removes all the names from the list." );
}
else
if( message == "say list" )
{
llSay( 0, "Visitor List:" );
integer len = llGetListLength( visitor_list );
integer i;
for( i = 0; i < len; i++ )
{
llSay( 0, llList2String(visitor_list, i) );
}
llSay( 0, "Total = " + (string)len );
}
else
if( message == "reset list" )
{
visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
llSay( 0, "Done resetting.";);
}
}
}
Julian Fate
80's Pop Star
Join date: 19 Oct 2003
Posts: 1,020
09-21-2005 01:03
The quick and easy way is after the line:

visitor_list += detected_name;


Add the line:

llInstantMessage(llGetOwner(), detected_name +" has dropped in.";);


However, I fixed a couple problems with the script (listen event checked owner even though the listener is filtered by llGetOwner(), changed all llSay() calls to llOwnerSay() to reduce spam) and set it up to check if you are online and only IM you if you are. It would not hurt for someone to double check me and see if it can be optimized more but this compiles.

One way to optimize and make it easier to use would be to remove the listener and put in a llDialog() menu that only opens a listener when needed, takes input, and removes the listener. There are only three commands, two if 'help' is replaced by a touch event, and neither of those take arguments so it looks perfect for replacement. I leave that as an exercise for the reader. :)

Slightly prettier version that IM's the owner if they are online:
CODE
// Global variables
list visitor_list;
float range = 10.0; // in meters
float rate = 10.0; // in seconds
string detected_name; // Needs to be global.
integer listener;

// Functions
integer isNameOnList(string name) {
integer len = llGetListLength(visitor_list);
integer i;
for (i = 0; i < len; i++) {
if (llList2String(visitor_list, i) == name) {
return TRUE;
}
}
return FALSE;
}

// States
default {
on_rez(integer parameter) {
llResetScript();
}// on_rez

state_entry() {
llListenRemove(listener);
listener = llListen(0, "", llGetOwner(), "");
llOwnerSay("Visitor List Maker started. Say 'help' for instructions.");
llSensorRepeat("", "", AGENT, range, TWO_PI, rate);
}// state_entry

sensor(integer number_detected) {
integer i;
for (i = 0; i < number_detected; i++) {
if (llDetectedKey(i) != llGetOwner()) {
detected_name = llDetectedName(i);
if (isNameOnList(detected_name) == FALSE) {
visitor_list += detected_name;
// New visitor so check if the owner is online to IM.
llRequestAgentData(llGetOwner(), DATA_ONLINE);
}
}
}
}// sensor

// Check if the owner is online and if so, tell them someone is here.
dataserver(key queryid, string data) {
if ((integer)data) {
llInstantMessage(llGetOwner(), detected_name +" has dropped in.");
}
}// dataserver

listen( integer channel, string name, key id, string message ) {
// Shouldn't need this since the listener only listens to llGetOwner().
//if (id != llGetOwner()) { return; }

if (message == "help") {
llOwnerSay("This object records the names of everyone who");
llOwnerSay("comes within "+ (string)range + " meters.");
llOwnerSay("Commands the owner can say:");
llOwnerSay("'help' - Shows these instructions.");
llOwnerSay("'say list' - Says the names of all visitors on the list.");
llOwnerSay("'reset list' - Removes all the names from the list.");
} else if (message == "say list") {
llOwnerSay("Visitor List:" );
integer len = llGetListLength(visitor_list);
integer i;
for (i = 0; i < len; i++) {
llOwnerSay(llList2String(visitor_list, i));
}
llOwnerSay("Total = " + (string)len );
} else if (message == "reset list") {
visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
llOwnerSay("Done resetting.");
}
}// listen

}
Folk Singer
Buddhist Monk
Join date: 13 Sep 2005
Posts: 5
09-22-2005 11:52
Thanks alot. This is very helpful.