//      Avatar Bump Detector
//      
//  Review "Custom Variables" and change if
//  necessary.  Then, place this script in
//  a visible attachment (it must be TOUCHED
//  to initiate eMail reporting of bump list).

//////////////////////////////////////////////
//  CUSTOM VARIABLES (3)    //////////////////
//////////////////////////////////////////////

//  Reporting bumps in Chat Console: change
//  to zero for no chat reporting
integer     reportInChat = 1;   

//  Enter destination email address here;
//  leave blank to skip email reporting
string      address = "someone@address.com";

//  The following value is inserted to the
//  email's Subject line
string      subject = "Avatar Bump Report";

//////////////////////////////////////////////
//  DO NOT CHANGE ANYTHING BELOW THIS LINE  //
//////////////////////////////////////////////
list        avatars_list;

//      FUNCTIONS       //////////////////
init() {
    avatars_list = [];
    if ( address == "someone@address.com" ) {
        llOwnerSay("Please change the Email address in script.");
    } else {
        llOwnerSay( "Bumped avatars list is cleared. \n" + llGetObjectName() + " is ready...");
    }
}

reportCollisions() {
    
    string msg = "Bumped by these avatars:\n" + llDumpList2String( avatars_list, "\n" ) ;
    
    if ( address != "someone@address.com" ) {
        llEmail(address, subject, msg );
    } else {
        llOwnerSay("Please change the Email address in script.");
    }
    
    avatars_list = [];
    
    llOwnerSay( subject + " has been sent. Bump list has been cleared.");
}
//      STATES      //////////////////////
default
{    
    on_rez(integer param) {
        init();
    }
    
    collision(integer num_detected) {
        
        if (llDetectedType(0) & AGENT) {
            
            integer i;
            
            for ( i = 0 ; i < num_detected ; i++ ) {
                
                string avatar = llDetectedName(i);
                
                if ( reportInChat ) {
                    llOwnerSay( "Collision: " + avatar );
                }
                
                if ( llListFindList( avatars_list, [avatar] ) == -1 ) {
                    avatars_list = ( avatars_list = [] ) + avatars_list + avatar ;
                }
                
            }
            
        }
        
    }
    
    touch_start(integer num) {
        llOwnerSay("+++touch detected +++");
        if ( llDetectedKey(0) == llGetOwner() ) {
            llOwnerSay("+++toucher is owner +++");
            reportCollisions();
        }
        
    }
    
}