Untitled
unknown
plain_text
2 years ago
6.2 kB
14
Indexable
//Visitors list 1.0
//by Paradox
//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 = FALSE; // TRUE - on, FALSE - off
integer sensor_timer;
integer sensor_timer_time = 50; //in timer event cycles
integer touch_timer;
integer touch_timer_time = 30; //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, [llKey2Name(llDetectedKey(num_det))]) != -1);
}
integer ListFindListLastElement(list src, list test)
{
if (llListFindList(src, test) == -1)
{
return -1;
}
else
{
integer index;
do
{
index = llListFindList(src, test);
src = llDeleteSubList(src, llListFindList(src, test), llListFindList(src, test) + llGetListLength(test) - 1);
}
while (llListFindList(src, test) == -1);
return index;
}
}
// 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_start(integer total_number)
{
//Admin touch (triggers at 'Admin long touch' too)
llSay (0, llDumpList2String(visitors_list, "\n"));
}
touch(integer num_detected)
{
//Admin long touch
if (isAdmin() == TRUE)
{
touch_timer += 1;
}
if (touch_timer == touch_timer_time)
{
}
}
touch_end(integer num_detected)
{
//For admin long touch (admin is checked in the event 'touch')
touch_timer = 0;
}
sensor(integer num_detected)
{
integer i;
for(i = 0; i < num_detected; ++i)
{
//For tests
llSay (0, (string) my_land_only_ModeControl(i));
llSay (0, (string) isNameOnVisitorsList(i));
llSay (0, (string) ListFindListLastElement(visitors_list, [llKey2Name(llDetectedKey(i))]));
//
if (my_land_only_ModeControl(i) == TRUE && isNameOnVisitorsList(i) == FALSE)
{
visitors_list += [llGetDisplayName(llDetectedKey(i)) + " ("] + [llKey2Name(llDetectedKey(i))] + [") - " + Unix2PST_PDT(llGetUnixTime())] + [0];
}
// if (my_land_only_ModeControl(i) == TRUE && isNameOnVisitorsList(i) == TRUE && llList2Integer(visitors_list, ListFindListLastElement(visitors_list, [llKey2Name(llDetectedKey(i))]) + 2) == 1)
// {
// visitors_list += [llGetDisplayName(llDetectedKey(i)) + " ("] + [llKey2Name(llDetectedKey(i))] + [") - " + Unix2PST_PDT(llGetUnixTime())] + [0];
// }
}
}
timer()
{
sensor_timer += 1;
if (sensor_timer == sensor_timer_time)
{
llSensor("", "", AGENT, range, PI);
sensor_timer = 0;
}
}
}Editor is loading...
Leave a Comment