Visitor List Script with Timed Listen/Web Profile Links
This is a modification of the existing Visitor List script that some people may be using - I don't know who wrote the original, but I do know it has been making the rounds. All I have done is made the Listen a timed event, and added some functionality that allows the URL of the visitor's web profile to be reported.
I'm not 100% happy with the way it works yet, but it could be useful for some people to adapt themselves. It has survived beta testing so far, but it does need some usability work in my opinion.
To use it, copy and paste it into a script in an object. To get the list, touch it (it presently says nothing when touched), then use channel 137 ('/137') to 'say list', 'reset list' and/or 'help'.
Released under GNU GENERAL PUBLIC LICENSE Version 2 (June 1991):
// Global variables
list visitor_list;
list visitor_keylist;
key kOwnerKey;
integer iListen;
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()
{
llOwnerSay("Visitor List Maker started...");
llOwnerSay("The owner can say 'help' for instructions.");
llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
//llListen(137, "", llGetOwner(), "");
kOwnerKey =llGetOwner();
}
touch_start(integer total_number)
{
if (llDetectedKey (0)== kOwnerKey)
{
iListen = llListen(137, "", llGetOwner(), "");
llSetTimerEvent(300);
}
}
timer ()
{
llListenRemove (iListen);
llSetTimerEvent(0);
llOwnerSay("You didn't talk, I stopped listening. Touch to make me listen.");
}
sensor( integer number_detected )
{
integer i;
string avatarkey;
for( i = 0; i < number_detected; i++ )
{
avatarkey = (string) llDetectedKey (i);
if( llDetectedKey( i ) != llGetOwner() )
{
string detected_name = llDetectedName( i );
if( isNameOnList( detected_name ) == FALSE )
{
visitor_list += detected_name;
visitor_keylist +=avatarkey;
}
}
}
}
listen( integer channel, string name, key id, string message )
{
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("Profile: http://world.secondlife.com/resident/"+llList2String(visitor_keylist, i));
}
llOwnerSay("Total = " + (string)len );
}
else
if( message == "reset list" )
{
visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
visitor_keylist=llDeleteSubList(visitor_keylist,0,llGetListLength(visitor_keylist));
llOwnerSay("Done resetting.");
}
}
}
Enjoy!
Technorati Tags:
Delicious
Digg
Technorati
Suggestion for Improvement
Instead of the wasteful and inefficient function "isNameOnList", you can just use:
if (llListFindList(visitor_list, [detected_name]) == -1)