Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sim Crash Counter

Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
04-08-2005 04:54
This script counts the number of sim crashes. It does this by polling the seconds since sim midnight then compairing the number to the previous polling results. If the sim crashes 300 seconds prior to sim midnight it will not be counted (if sim crashes are evenly distributed random event then thats a 2% chance that a sim crash will not be counted).

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);
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
04-08-2005 13:22
/54/47/42053/1.html
_____________________
i've got nothing. ;)
Jacob Thatch
Senior Member
Join date: 31 Mar 2005
Posts: 146
04-20-2005 21:51
thnx for this