Untitled

 avatar
unknown
plain_text
2 years ago
10 kB
9
Indexable
// Visitors list 1.0
// by Paradox
//
// (English)
// Instructions
// You can add or remove admins by adding or removing an identifier (key) to the 'admins' variable.
// The 'range' variable sets the scanning radius (in meters from 0 to 96). If the 'my_land_only' variable is set to 'TRUE', then the scan does not extend beyond the plot of land whose owner coincides with the owner of the object in which the script is located. (If the land is owned by a group, then the object containing the script must also be given to the group.) If the variable 'my_land_only' is set to 'FALSE', then the boundaries of the land are ignored.
// By simply clicking on an object, the administrator displays a list of visitors to the site.
// By long pressing on an object by the administrator, the list of visitors to the site is reset to zero.
// The 'Same group' status indicates whether the visitor had the same group active as the one assigned to the object in which the script is located.
// The 'Was out range' status indicates whether the visitor has left the land. If a visitor leaves the land, he will added to the list again the next time his visits.
//
// (Русский)
// Инструкция
// Добавлять или удалять админов можно, добавляя или удаляя идентификатор (ключ) в переменную 'admins'.
// Переменная 'range' задаёт радиус сканирования (в метрах от 0 до 96). Если при этом переменной 'my_land_only' присвоено значение 'TRUE', то сканирование не выходит за рамки участка земли, владелец которой совпадает с владельцем объекта, в котором находится скрипт. (Если землёй владеет группа, то объект, в котором находится скрипт, должен быть тоже передан группе.) Если переменной 'my_land_only' присвоено значение 'FALSE', то границы участка земли игнорируются.
// По простому нажатию на объект админом выводится список посетителей участка.
// По длительному нажатию на объект админом список посетителей участка обнуляется.
// Статус 'Same group' говорит о том, была ли у посетителя активна та же группа, что назначена объекту, в котором находится скрипт.
// Статус 'Was out range' говорит о том, покидал ли посетитель землю. Если посетитель покидал землю, то он вносится в список снова при следующем посещении.

//Global variables

list admins = ["7405e11e-67d8-4ac7-ad98-e9e90316e2e4", "559f590e-7016-4273-ba0d-6d8b6b7c0516", "ba2e1323-4dae-4076-8762-d7bc2317e2f6"]; //Admins list. Admins: Paradox, Iskorka, ObiAi
float range = 96.0; // in meters from 0 to 96
integer my_land_only = TRUE; // TRUE - on, FALSE - off

integer sensor_timer;
integer sensor_timer_time = 50; //in timer event cycles

integer touch_timer;
integer touch_timer_time = 40; //in touch event cycles

list visitors_list;

//Functions

integer isAdmin()
{
    return (llListFindList(admins, [(string) llDetectedKey(0)]) != -1);
}
integer my_land_only_ModeControl(integer num_det)
{
    if ((my_land_only == TRUE && llOverMyLand(llDetectedKey(num_det)) == TRUE) || my_land_only == FALSE)
    {
        return TRUE;
    }
    else return FALSE;
}
integer isNameOnVisitorsList(integer num_det)
{
    return (llListFindList(visitors_list, ["User name: " + llDetectedName(num_det)]) != -1);
}
integer ListFindListLastElement(list src, list test)
{
    integer srclen = llGetListLength(src);
    integer testlen = llGetListLength(test);
    
    integer idx = 0;
    integer cidx = 0;
    
    do
    {
        if ((idx = llListFindList(llList2List(src, cidx, -1), test)) != -1) 
        {
            cidx += idx + testlen;
        }
    }
    while (idx != -1 && cidx < srclen);    
    
    return cidx-testlen;
}
list isSameGroup(integer num_det)
{
    if (llSameGroup(llDetectedKey(num_det)) == TRUE)
    {
        return ["Same group: Yes"];
    }
    else return ["Same group: No"];
}
// Convert Unix Time to SLT, identifying whether it is currently PST or PDT (i.e. Daylight Saving aware)
// Omei Qunhua December 2013
list weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

string Unix2PST_PDT(integer insecs)
{
    string str = Convert(insecs - (3600 * 8) );   // PST is 8 hours behind GMT
    if (llGetSubString(str, -3, -1) == "PDT")     // if the result indicates Daylight Saving Time ...
        str = Convert(insecs - (3600 * 7) );      // ... Recompute at 1 hour later
    return str;
}

// This leap year test is correct for all years from 1901 to 2099 and hence is quite adequate for Unix Time computations
integer LeapYear(integer year)
{
    return !(year & 3);
}

integer DaysPerMonth(integer year, integer month)
{
    if (month == 2)      return 28 + LeapYear(year);
    return 30 + ( (month + (month > 7) ) & 1);           // Odd months up to July, and even months after July, have 31 days
}

string Convert(integer insecs)
{
    integer w; integer month; integer daysinyear;
    integer mins = insecs / 60;
    integer secs = insecs % 60;
    integer hours = mins / 60;
    mins = mins % 60;
    integer days = hours / 24;
    hours = hours % 24;
    integer DayOfWeek = (days + 4) % 7;    // 0=Sun thru 6=Sat

    integer years = 1970 +  4 * (days / 1461);
    days = days % 1461;                  // number of days into a 4-year cycle

    @loop;
    daysinyear = 365 + LeapYear(years);
    if (days >= daysinyear)
    {
        days -= daysinyear;
        ++years;
        jump loop;
    }
    ++days;

    for (w = month = 0; days > w; )
    {
        days -= w;
        w = DaysPerMonth(years, ++month);
    }
    string str =  ((string) years + "-" + llGetSubString ("0" + (string) month, -2, -1) + "-" + llGetSubString ("0" + (string) days, -2, -1) + " " +
    llGetSubString ("0" + (string) hours, -2, -1) + ":" + llGetSubString ("0" + (string) mins, -2, -1) );

    integer LastSunday = days - DayOfWeek;
    string PST_PDT = " PST";                  // start by assuming Pacific Standard Time
    // Up to 2006, PDT is from the first Sunday in April to the last Sunday in October
    // After 2006, PDT is from the 2nd Sunday in March to the first Sunday in November
    if (years > 2006 && month == 3  && LastSunday >  7)     PST_PDT = " PDT";
    if (month > 3)                                          PST_PDT = " PDT";
    if (month > 10)                                         PST_PDT = " PST";
    if (years < 2007 && month == 10 && LastSunday > 24)     PST_PDT = " PST";
    return (llList2String(weekdays, DayOfWeek) + " " + str + PST_PDT);
}

default
{
    state_entry()
    {
        llSetTimerEvent(0.01);
    }
    
    touch(integer num_detected)
    {
        //Admin long touch
        if (isAdmin() == TRUE)
        {
            touch_timer += 1;
        }
        if (touch_timer == touch_timer_time)
        {
            visitors_list = [];
            llSay (0, "Выполнено обнуление списка.");
            llSay (0, "\nСписок посетителей:\n____________________\n" + llDumpList2String(visitors_list, "\n") + "\n____________________\nВсего: " + (string) (llGetListLength(visitors_list) / 5));
            llSay (0, "Через несколько секунд сканирование начнётся снова...");
            llSleep(1.5);       
        }
    }
    
    touch_end(integer total_number)
    {
        //Admin touch
        if (isAdmin() == TRUE && touch_timer < touch_timer_time)
        {
        llSay (0, "\nСписок посетителей:\n____________________\n" + llDumpList2String(visitors_list, "\n") + "\n____________________\nВсего: " + (string) (llGetListLength(visitors_list) / 5));
        }
        
        touch_timer = 0;
    }
    
    sensor(integer num_detected)
    {
        integer i;
        list scan; 
        for(i = 0; i < num_detected; ++i)
        {
            if (my_land_only_ModeControl(i) == TRUE)
            {
                scan += ["User name: " + llDetectedName(i)];
            }
            
         //Adding to visitors_list          
            if (my_land_only_ModeControl(i) == TRUE && isNameOnVisitorsList(i) == FALSE)
            {
                visitors_list += ["\nDisplay name: " + llGetDisplayName(llDetectedKey(i))] + ["User name: " + llDetectedName(i)] + ["Time: " + Unix2PST_PDT(llGetUnixTime())] + isSameGroup(i) + ["Was out range: No"];                   
            }
            if (my_land_only_ModeControl(i) == TRUE && isNameOnVisitorsList(i) == TRUE && llList2String(visitors_list, ListFindListLastElement(visitors_list, ["User name: " + llDetectedName(i)]) + 3) == "Was out range: Yes")
            {
                visitors_list += ["\nDisplay name: " + llGetDisplayName(llDetectedKey(i))] + ["User name: " + llDetectedName(i)] + ["Time: " + Unix2PST_PDT(llGetUnixTime())] + isSameGroup(i) + ["Was out range: No"];
            }    
        }
        
        //Was out range status control
        i = 1;
        integer len = llGetListLength(visitors_list);
        for (i = 1; i < (len - 2); i += 5)
        {
            if (llList2String(visitors_list, i + 3) == "Was out range: No" && llListFindList(scan, llList2List(visitors_list, i, i)) == -1)
            {
                visitors_list = llListInsertList(visitors_list, ["Was out range: Yes"], i + 3);
                visitors_list = llDeleteSubList(visitors_list, i + 4, i + 4);
            }     
        }  
    }
        
    timer()
    {
        sensor_timer += 1;
        if (sensor_timer == sensor_timer_time)
        {
            llSensor("", "", AGENT, range, PI);
            sensor_timer = 0;
        }
    }    
}
Editor is loading...
Leave a Comment