Advertisement
cyber_Ahn

vistitor_counter (counts the visits of visitors)

Apr 10th, 2015
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //---settings----
  2. integer range = 96;
  3. integer rate = 15;
  4. list non_detect = ["348dc1b0-2d77-421f-90c5-813ec441a4fd","76095f37-ffb6-4908-abe9-60b22438f004"];//ad your AV-UUID
  5. integer debug = FALSE;
  6. //---var---------
  7. list visitors = [];
  8. list count = [];
  9. list on_land = [];
  10. list v_key = [];
  11. integer handle;
  12. integer menuChan;
  13. integer on_power = 0;
  14. //---functions---
  15. build_list(list av,list key_v)
  16. {
  17.     integer num = llGetListLength(av);
  18.     integer x;
  19.     for(x=0;x<=(num-1);x++)
  20.     {
  21.         integer n = llListFindList(visitors,[llList2String(av,x)]);
  22.         if(n == -1)
  23.         {
  24.             visitors += llList2String(av,x);
  25.             count += "1";
  26.             on_land += "1";
  27.             v_key += llList2String(key_v,x);
  28.         }
  29.         string land = llList2String(on_land,n);
  30.         if(land == "0" && n != -1)
  31.         {
  32.             integer z = (integer)llList2String(count,n) + 1;
  33.             count = llListReplaceList(count, [(string)z],n,n);
  34.             on_land = llListReplaceList(on_land, ["1"],n,n);
  35.         }
  36.     }
  37.     integer nu = llGetListLength(visitors);
  38.     integer i;
  39.     for(i=0;i<=(nu-1);i++)
  40.     {
  41.         key v = (key)llList2String(v_key,i);
  42.         string l = llList2String(on_land,i);
  43.         if(l == "1")
  44.         {
  45.             if(llOverMyLand(v)==FALSE)
  46.             {
  47.                 on_land = llListReplaceList(on_land, ["0"],i,i);
  48.             }
  49.         }
  50.     }
  51.     if(debug)
  52.     {
  53.         debug_out("in: "+llList2CSV(av));
  54.         debug_out("visitors: "+llList2CSV(visitors));
  55.         debug_out("count: "+llList2CSV(count));
  56.         debug_out("land: "+llList2CSV(on_land));
  57.         debug_out("key: "+llList2CSV(v_key));
  58.     }
  59. }
  60. debug_out(string data)
  61. {
  62.     llSay(0,data);
  63. }
  64. menu(key av)
  65. {
  66.     list button = [];
  67.     if(on_power == 0)
  68.     {
  69.         button += "Power On";
  70.     }
  71.     else
  72.     {
  73.         button += "Power Off";
  74.     }
  75.     button += "See List";
  76.     button += "Reset List";
  77.     llListenRemove(handle);
  78.     menuChan = 50000 + (integer)llFrand(50000.00);
  79.     handle = llListen(menuChan,"",NULL_KEY,"");
  80.     llDialog(av,"Choose a Option",button,menuChan);
  81.     llSetTimerEvent(30);
  82. }
  83. default
  84. {
  85.     state_entry()
  86.     {
  87.         llOwnerSay("Add your AV-UUID to the 'non_detect' list in this script"),
  88.         llOwnerSay("Add me to Landgroup");
  89.     }
  90.     touch_start(integer total_number)
  91.     {
  92.         integer f = llListFindList(non_detect,[(string)llDetectedKey(0)]);
  93.         if(f != -1)
  94.         {
  95.             menu(llDetectedKey(0));
  96.         }
  97.     }
  98.     listen(integer channel, string name, key id, string msg)
  99.     {
  100.         if(msg == "Power On")
  101.         {
  102.             llWhisper(0,"Start Sensor");
  103.             on_power = 1;
  104.             llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
  105.         }
  106.         if(msg == "Power Off")
  107.         {
  108.             llWhisper(0,"Remove Sensor");
  109.             on_power = 0;
  110.             llSensorRemove();
  111.         }
  112.         if(msg == "Reset List")
  113.         {
  114.             llWhisper(0,"List deleted, reset Script");
  115.             llWhisper(0,"Turn me on now");
  116.             llResetScript();
  117.         }
  118.         if(msg == "See List")
  119.         {
  120.             integer length = llGetListLength(visitors);
  121.             integer t;
  122.             for(t=0;t<=(length-1);t++)
  123.             {
  124.                 llWhisper(0,llList2String(visitors,t)+":"+llList2String(count,t));
  125.             }
  126.         }
  127.         llSetTimerEvent(0);
  128.         llListenRemove(handle);
  129.     }
  130.     timer()
  131.     {
  132.         llSetTimerEvent(0);
  133.         llListenRemove(handle);
  134.     }
  135.     on_rez(integer param)
  136.     {
  137.         llResetScript();
  138.     }
  139.     sensor(integer number_detected)
  140.     {
  141.         list visitor_found;
  142.         list v_key_v;
  143.         integer i;
  144.         for(i = 0;i<number_detected;i++)
  145.         {
  146.             integer nu = llListFindList(non_detect,[(string)llDetectedKey(i)]);
  147.             if(nu == -1)
  148.             {
  149.                 visitor_found += llDetectedName(i);
  150.                 v_key_v += (string)llDetectedKey(i);
  151.             }
  152.         }
  153.         build_list(visitor_found,v_key_v);  
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement