De DigiWiki.
/*//( v7-D Advanced Avatar Greeter v1.4.2 Annotated )//*/
/*//-- Notes:
This script attempts (within the limits of LSL) To only greet avatars once per timeout period
The timeout period start when they leave, and favors not re-greeting frequent visitors (perceived as spam)
Remove Lines marked **Dynamic Memory Limitation Section** if you are sure of the max avs you want to store
Remove Lines marked **Timeout Culling Section** if you want to greet the same avatar only once
--//*/
/*//-- Core Variables --//*/
list gLstAvs; //-- List Of Avatars Keys Greeted
list vLstChk; //-- List Of Single Av Key Checked During Sensor Processing
integer vIdxLst; //-- Index Of Checked Item In List (reused)
integer gIntMax = 500; //-- Maximum Number of Names To Store (ignored if Dynamic Memory used)
/*//-- Next Line: **Dynamic Memory Limitation Section** --//*/
integer cINT_MEM = 1024; //-- Memory bytes to preserve for safety (Needs to be > ~768)
/*//-- Start **Timeout Culling Section** --//*/
integer gIntTmt = 172800; //-- Number Of Seconds since last visit to store Av
integer vIntNow; //-- Integer To Store Current Time During Sensor Processing
list gLstTms; //-- List Of Most Recent Times Avs Were Greeted At
list vLstTmt; //-- List To Store Calculated Timeout During Sensor Processing
/*//-- End **Timeout Culling Section** --//*/
default{
state_entry(){
//-- Next Line: **Dynamic Memory Limitation Section**
gIntMax = cINT_MEM; //--< **Dynamic Memory Limitation Section**
llSensor( "", "", AGENT, 95.0, PI ); //-- Pre-Fire Sensor for immediate results
llSetTimerEvent( 30.0 ); //-- How often (in seconds) to look for new people
}
timer(){
llSensor( "", "", AGENT, 95.0, PI ); //-- Look for avatars
}
sensor( integer vIntSns ){ //-- Get "now" and "timeout" once, saving timeout as a list for eas of use
vLstTmt = (list)(gIntTmt + (vIntNow = llGetUnixTime())); //--< **Timeout Culling Section**
do{ //-- Have we greeted these av's in our time frame?
if (~(vIdxLst = llListFindList( gLstAvs, (vLstChk = (list)llDetectedKey( --vIntSns )) ))){
gLstAvs = vLstChk + llDeleteSubList( gLstAvs, vIdxLst, vIdxLst ); //-- prevents spamming frequent visitors
gLstTms = vLstTmt + llDeleteSubList( gLstTms, vIdxLst, vIdxLst ); //--< **Timeout Culling Section**
}else{ //-- New Av, greet and save
llRegionSayTo( (string)vLstChk, 0, "Hello " + llDetectedName( vIntSns ) );
gLstAvs = llList2List( vLstChk + gLstAvs, 0, gIntMax );
gLstTms = llList2List( vLstTmt + gLstTms, 0, gIntMax ); //--< **Timeout Culling Section**
}
}while (vIntSns);
/*//-- Start **Dynamic Memory Limitation Section** --//*/
if (cINT_MEM == gIntMax){ //-- check value to see if we need to do this, should happen 1 time only
if (cINT_MEM > llGetFreeMemory()){ //-- are we running out of free space?
gIntMax = ~([] != gLstAvs); //-- Limit list to current_length - 1 to prevent stack/heap collision
}
} /*//-- End **Dynamic Memory Limitation Section** --//*/
/*//-- Start **Timeout Culling Section** --//*/
if (vIdxLst = (gLstTms != [])){
if (vIntNow > llList2Integer( gLstTms, --vIdxLst )){
@Loop; //-- Find first index of avatars whose time since last greeting expired
if (--vIdxLst){ //-- special loop structure to emulate short circuiting, while preserving vIndLst
if (vIntNow < llList2Integer( gLstTms, vIdxLst )){
jump Loop;
}
} //-- Next 2 Lines: Remove Avs whose time has expired
gLstAvs = llList2List( (gLstAvs = []) + gLstAvs, 0, vIdxLst );
gLstTms = llList2List( (gLstTms = []) + gLstTms, 0, vIdxLst );
}
} /*//-- End **Timeout Culling Section** --//*/
}
}
/*//-- License Text --//*/
/*// Free to copy, use, modify, distribute, or sell, with attribution. //*/
/*// (C)2009 (CC-BY) [ http://creativecommons.org/licenses/by/3.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*// All usages must contain a plain text copy of the previous 2 lines. //*/
/*//-- --//*/