Advertisement
itoibo

Untitled

Jun 15th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //access by group, by owner, everyone, selected users
  2. //message
  3. integer chan;
  4. list adminList;
  5.  
  6. float scanFrequency;
  7. float spamTime;
  8. integer scanSensor = FALSE;
  9. integer IMAdmin = TRUE;
  10. key user;
  11.  
  12. string menu1Text = "Azn's Super Scan 1b \n Select an Option";
  13. list menu1 = ["Access", "Scan Type", "Scan Frequency", "Spam Time"];
  14.  
  15. /*//( v7-D Advanced Avatar Greeter v1.4.2 Annotated )//*/
  16.  
  17. /*//-- Notes:
  18.  This script attempts (within the limits of LSL) To only greet avatars once per timeout period
  19.  The timeout period start when they leave, and favors not re-greeting frequent visitors (perceived as spam)
  20.  
  21.  Remove Lines marked **Dynamic Memory Limitation Section** if you are sure of the max avs you want to store
  22.  Remove Lines marked **Timeout Culling Section** if you want to greet the same avatar only once
  23. --//*/
  24.  
  25. /*//-- Core Variables --//*/
  26. list    getListOfAvatarKeys;         //-- List Of Avatars Keys Greeted
  27. list    listOfSingleAvatarKeysWhileSensing;         //-- List Of Single Av Key Checked During Sensor Processing
  28. integer indexOfCheckedItemInList;         //-- Index Of Checked Item In List (reused)
  29. integer maximumNumberOfNamesToStore = 500;   //-- Maximum Number of Names To Store (ignored if Dynamic Memory used)
  30.  
  31.  /*//-- Next Line:  **Dynamic Memory Limitation Section** --//*/
  32. integer SafetyReserveBytesOfMemory = 1024; //-- Memory bytes to preserve for safety (Needs to be > ~768)
  33.  
  34.  /*//-- Start **Timeout Culling Section** --//*/
  35. integer secondsSinceAvatarLastVisit = 3600; //18800 = 30min //172800; //-- Number Of Seconds since last visit to store Av
  36. integer storeCurrentTimeOfSensing;          //-- Integer To Store Current Time During Sensor Processing
  37. list    listOfMostRecentAvatarVisitTimes;          //-- List Of Most Recent Times Avs Were Greeted At
  38. list    listToStoreCalculatedTimeoutDuringSensorProcessing;          //-- List To Store Calculated Timeout During Sensor Processing
  39.  /*//-- End **Timeout Culling Section** --//*/
  40.  
  41. default{
  42.     state_entry(){
  43.         chan = llGetUnixTime();
  44.         adminList += llGetOwner();
  45.         llOwnerSay(llDumpList2String(adminList, ","));
  46.          
  47.          //-- Next Line: **Dynamic Memory Limitation Section**
  48.         maximumNumberOfNamesToStore = SafetyReserveBytesOfMemory;                  //--< **Dynamic Memory Limitation Section**
  49.        
  50.  
  51.  
  52.         llSensor( "", "", AGENT, 32.0, PI ); //-- Pre-Fire Sensor for immediate results
  53.         llSetTimerEvent( 30.0 );             //-- How often (in seconds) to look for new people
  54.     }
  55.    
  56.      touch_start(integer num_detected)
  57.     {
  58.         user = llDetectedKey(0);
  59.        
  60.         if(~llListFindList(adminList, [user]))//if the toucher is on the admin list
  61.         {//it exists
  62.             llDialog(user, menu1Text, menu1, chan);  
  63.     // This works because ~(-1) produces 0, but ~ of any other value produces non-zero and causes the 'if' to succeed // So any return value (including 0) that corresponds to a found item, will make the condition succeed // It saves bytecode and is faster then doing != -1
  64.     // This is a bitwise NOT (~) not a negation (-)
  65.         }
  66.     }
  67.        
  68.         listen(integer channel, string name, key ID, string message)
  69.         {
  70.             if(message == "Access")
  71.             {
  72.                 state accessList;
  73.             }
  74.             else if(message == "Scan Type")
  75.             {
  76.                 llDialog(ID, "Choose Scan Type:", ["Sensor", "Parcel"], chan);
  77.             }
  78.             else if(message == "Scan Frequency")
  79.             {
  80.                  llDialog(user, "Choose Scan Frequency:", ["1 Second", "5 Seconds", "10 Seconds", "15 Seconds", "30 Seconds", "1 Minute", "5 Minutes", "10 Minutes", "30 Minutes", "1 Hour", "2 Hours", "4 Hours", "8 Hours", "12 Hours", "24 Hours"], chan);
  81.             }
  82.             else if(message == "Spam Time")
  83.             {
  84.                 llDialog(user, "Choose greet time since last visit:", ["Every Visit", "1 Hour", "2 Hours", "4 Hours", "8 Hours", "12 Hours", "1 Day", "2 Days", "3 Days", "4 Days", "5 Days", "6 Days", "1 Week", "2 Weeks", "1 Month"], chan);
  85.             }
  86.         }    
  87.      
  88.  
  89.  
  90.  
  91.     timer(){
  92.         llSensor( "", "", AGENT, 32.0, PI ); //-- Look for avatars
  93.     }
  94.  
  95.     sensor( integer vIntSns ){ //-- Get "now" and "timeout" once, saving timeout as a list for ease of use
  96.         listToStoreCalculatedTimeoutDuringSensorProcessing = (list)(secondsSinceAvatarLastVisit + (storeCurrentTimeOfSensing = llGetUnixTime())); //--< **Timeout Culling Section**
  97.         do{ //-- Have we greeted these av's in our time frame?
  98.             if (~(indexOfCheckedItemInList = llListFindList( getListOfAvatarKeys, (listOfSingleAvatarKeysWhileSensing = (list)llDetectedKey( --vIntSns )) ))){
  99.                 getListOfAvatarKeys = listOfSingleAvatarKeysWhileSensing + llDeleteSubList( getListOfAvatarKeys, indexOfCheckedItemInList, indexOfCheckedItemInList ); //-- prevents spamming frequent visitors
  100.                 listOfMostRecentAvatarVisitTimes = listToStoreCalculatedTimeoutDuringSensorProcessing + llDeleteSubList( listOfMostRecentAvatarVisitTimes, indexOfCheckedItemInList, indexOfCheckedItemInList ); //--< **Timeout Culling Section**
  101.             }else{ //-- New Av, greet and save
  102.            
  103.              llInstantMessage("a9780071-adcf-49f4-a862-a3f48bfd43d7",  llDetectedName(vIntSns) + " is at Azn's");
  104.             //[ " + (string)id + " ]");
  105.            
  106.             llSay(0, "Hello " + llDetectedName( vIntSns ) + ". \nWelcome to Azn's" );
  107.                 getListOfAvatarKeys = llList2List( listOfSingleAvatarKeysWhileSensing + getListOfAvatarKeys, 0, maximumNumberOfNamesToStore );
  108.                 listOfMostRecentAvatarVisitTimes = llList2List( listToStoreCalculatedTimeoutDuringSensorProcessing + listOfMostRecentAvatarVisitTimes, 0, maximumNumberOfNamesToStore ); //--< **Timeout Culling Section**
  109.             }
  110.         }while (vIntSns);
  111.          /*//-- Start **Dynamic Memory Limitation Section** --//*/
  112.         if (SafetyReserveBytesOfMemory == maximumNumberOfNamesToStore){            //-- check value to see if we need to do this, should happen 1 time only
  113.             if (SafetyReserveBytesOfMemory > llGetFreeMemory()){ //-- are we running out of free space?
  114.                 maximumNumberOfNamesToStore = ~([] != getListOfAvatarKeys);      //-- Limit list to current_length - 1 to prevent stack/heap collision
  115.             }
  116.         } /*//-- End **Dynamic Memory Limitation Section** --//*/
  117.          /*//-- Start **Timeout Culling Section** --//*/
  118.         if (indexOfCheckedItemInList = (listOfMostRecentAvatarVisitTimes != [])){
  119.             if (storeCurrentTimeOfSensing > llList2Integer( listOfMostRecentAvatarVisitTimes, --indexOfCheckedItemInList )){
  120.                 @Loop;          //-- Find first index of avatars whose time since last greeting expired
  121.                 if (--indexOfCheckedItemInList){ //-- special loop structure to emulate short circuiting, while preserving vIndLst
  122.                     if (storeCurrentTimeOfSensing < llList2Integer( listOfMostRecentAvatarVisitTimes, indexOfCheckedItemInList )){
  123.                         jump Loop;
  124.                     }
  125.                 } //-- Next 2 Lines: Remove Avs whose time has expired
  126.                 getListOfAvatarKeys = llList2List( (getListOfAvatarKeys = []) + getListOfAvatarKeys, 0, indexOfCheckedItemInList );
  127.                 listOfMostRecentAvatarVisitTimes = llList2List( (listOfMostRecentAvatarVisitTimes = []) + listOfMostRecentAvatarVisitTimes, 0, indexOfCheckedItemInList );
  128.             }
  129.         } /*//-- End **Timeout Culling Section** --//*/
  130.     }
  131. }
  132.  
  133.  
  134.  
  135. state accessList
  136. {
  137.     touch_start(integer num_detected)
  138.     {
  139.         adminList = [];
  140.     //  do a 10m spherical sweep
  141.         llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 10.0, PI);
  142.     }
  143.  
  144.     sensor (integer num_detected)
  145.     {
  146.         string message = "Detected " + (string)num_detected + " avatar(s): " ;
  147.         integer index;
  148.         string name;
  149.         while (index < num_detected)
  150.         {
  151.             name = llDetectedName(index++);
  152.             adminList += name;
  153.             message += ", " + name;
  154.         }
  155.  
  156.         llDialog(llGetOwner(), "Choose Admin:", adminList, chan);
  157.         llWhisper(0, message);
  158.     }
  159.  
  160.     no_sensor()
  161.     {
  162.         llWhisper(0, "Nobody is near me at present.");
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement