Setup:
Drop the script in an object.
CODE
//Sim Crash Counter Version 1.41
//By: Strife Onizuka
// timestamp_difference
// Based on timestamp_to_unixtime, unixtime_to_timestamp, elapsed
// timestamp_to_unixtime & unixtime_to_timestamp
// By: Masakazu Kojima, Francis Chung, Strife Onizuka
// elapsed
// By: Chromal Brodsky
// string timestamp_difference(string sTimeStart, string sTimeEnd)
//
// At the end of the above example, timestamp_difference is in the format of ddddd:hh:mm:ss.ssssss,
// e.g.: "00000:00:01:10.605000"
string timestamp_difference(string sTimeStart, string sTimeEnd)
{
list daysPerMonth = [ 0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333 ];
if (sTimeStart == "" )
return sTimeEnd;
if (sTimeEnd == "")
sTimeEnd = llGetTimestamp();
integer year = (integer) llGetSubString(sTimeEnd, 0, 3);
integer month = (integer) llGetSubString(sTimeEnd, 5, 6);
integer iDay = (year * 365) + ((year - 2878169) / 4)
+ llList2Integer( daysPerMonth, month )
+ (integer) llGetSubString(sTimeEnd, 8, 9)
+ (month>2) * !(year % 4);
integer iHour = (integer)llGetSubString( sTimeEnd, 11, 12 );
integer iMin = (integer)llGetSubString( sTimeEnd, 14, 15 );
float fSec = (float)llGetSubString( sTimeEnd, 17, 22 );
year = (integer) llGetSubString(sTimeStart, 0, 3);
month = (integer) llGetSubString(sTimeStart, 5, 6);
integer iDay_start = (year * 365) + ((year - 2878169) / 4)
+ llList2Integer( daysPerMonth, month )
+ (integer) llGetSubString(sTimeStart, 8, 9)
+ (month>2) * !(year % 4);
integer iHour_start = (integer)llGetSubString( sTimeStart, 11, 12 );
integer iMin_start = (integer)llGetSubString( sTimeStart, 14, 15 );
float fSec_start = (float)llGetSubString( sTimeStart, 17, 22 );
while (fSec < fSec_start)
{
fSec += 60.0;
--iMin;
}
while (iMin < iMin_start)
{
iMin += 60;
--iHour;
}
while (iHour < iHour_start)
{
iHour += 24;
--iDay;
}
iHour = iHour - iHour_start;
iMin = iMin - iMin_start;
fSec = fSec - fSec_start;
string sH = ":";
string sM = sH;
string sS = sH;
string sD;
if (iHour < 10)
sH = ":0";
if (iMin < 10)
sM = ":0";
if (fSec < 10.0)
sS = ":0";
sD=(string)iDay;
return llGetSubString("00000",llStringLength(sD),5) + sD + sH + (string)iHour + sM + (string)iMin + sS + (string)fSec;
}
integer crashes;
string Nstart;
string Nrecent = "None";
string Upre;
string Ulast;
vector b1;
vector b2;
vector a1;
integer count = -2147483639;
update()
{
llSetText("Number Of Crashes: "+(string)(crashes)+
"\nSince: "+Nstart+
"\nMost Recent: "+Nrecent,<1,1,1>,1);
}
string time(string a)
{
if(a=="") a = llGetTimestamp();
return llGetSubString(a,0,9) + "\t" + llGetSubString(a,11,18) + "\tZulu";
}
default
{
state_entry()
{
llSetObjectName("Sim Crash Counter 1.41");
Nstart = time("");
llSetTimerEvent(60.0);
update();
}
on_rez(integer a)
{
llResetScript();
}
timer()
{
vector p = llGetSunDirection();
if(llGetTimeOfDay()<360 && count > -2147483640)
{
if(a1 == ZERO_VECTOR)
a1 = p;
else
{
if(!(b2.z > b1.z && a1.z < p.z))
{
++crashes;
string t = llGetTimestamp();
Ulast = timestamp_difference(Upre, t);
Nrecent = time(Upre = t);
update();
}
b2 = a1;
b1 = p;
a1 = ZERO_VECTOR;
count = -2147483644;
}
}
else
{
b2 = b1;
b1 = p;
if(++count > 2147483640)
count = -2147483639;
}
}
touch_start(integer a)
{
llWhisper(0,"Current Time: "+time(""));
llWhisper(0,"Time Since Last Crash: "+timestamp_difference(Upre,""));
llWhisper(0,"Time Between Last Crashes: "+Ulast);
}
}