LoD_PRC8/_module/nss/inc_timecheck.nss
Jaysyn904 94990edc60 Initial Upload
Initial Upload
2023-09-21 21:20:34 -04:00

112 lines
3.4 KiB
Plaintext

// HardCore Modular Base
// 2002 Sep Archaegeo
// 2003 Jul Mhzentul Lafarius added milliseconds since begin.
// hc_i0_timecheck
// Include file for use by all scripts.
// nConv returns the number of seconds in an hour based on timescale of module
// SecondsSinceBegin() returns the number of seconds since the module loaded.
int nConv=FloatToInt(HoursToSeconds(1));
int SecondsSinceBegin();
void SetUpTimer()
{
object oMod=GetModule();
SetLocalInt(oMod, "HourStart", GetTimeHour());
SetLocalInt(oMod, "DayStart", GetCalendarDay());
SetLocalInt(oMod, "MonthStart", GetCalendarMonth());
SetLocalInt(oMod, "YearStart", GetCalendarYear());
}
float MillisecondsSinceBegin()
{
int nMilliseconds = SecondsSinceBegin()*1000;
return(IntToFloat(nMilliseconds) + GetTimeMillisecond());
}
int SecondsSinceBegin()
{
object oMod=GetModule();
float fStartHour=IntToFloat(GetLocalInt(oMod,"HourStart"));
float fStartDay=IntToFloat(GetLocalInt(oMod,"DayStart"));
float fStartMonth=IntToFloat(GetLocalInt(oMod,"MonthStart"));
float fStartYear=IntToFloat(GetLocalInt(oMod,"YearStart"));
float fCurDay=IntToFloat(GetCalendarDay());
float fCurMonth=IntToFloat(GetCalendarMonth());
float fCurYear=IntToFloat(GetCalendarYear());
float fCurHour=IntToFloat(GetTimeHour());
float fCurMin=IntToFloat(GetTimeMinute());
float fCurSec=IntToFloat(GetTimeSecond());
float fElapsed=0.000;
if(fCurYear==fStartYear)
{
if(fCurMonth==fStartMonth)
{
if(fCurDay==fStartDay)
{
fElapsed += (fCurHour-fStartHour);
}
else
{
if(fCurHour>fStartHour)
{
fElapsed += 24.0 * (fCurDay-fStartDay);
fElapsed += fCurHour-fStartHour;
}
else
{
fElapsed += 24.0 * (fCurDay-fStartDay-1.0);
fElapsed += 24.0 - fStartHour + fCurHour;
}
}
}
else
{
if(fCurDay>fStartDay)
{
fElapsed += 28.0 * 24.0 * (fCurMonth - fStartMonth);
fElapsed += 24.0 * (fCurDay-fStartDay);
}
else
{
fElapsed += 28.0 * 24.0 * (fCurMonth - fStartMonth - 1.0);
fElapsed += 24.0 * (28.0 - fStartDay + fCurDay);
}
if(fCurHour > fStartHour)
fElapsed += fCurHour-fStartHour+2.0;
else
fElapsed += -24.0 + fStartHour + fCurHour;
}
}
else
{
if(fCurMonth>fStartMonth)
{
fElapsed += 12.0 * 28.0 * 24.0 * (fCurYear - fStartYear);
fElapsed += 28.0 * 24.0 * (fCurMonth-fStartMonth);
}
else
{
fElapsed += 12.0 * 28.0 * 24.0 * (fCurYear - fStartYear - 1.0);
fElapsed += 28.0 * 24.0 * (12.0 - fStartMonth + fCurMonth);
}
if(fCurDay> fStartDay)
fElapsed += 24.0 * (fCurDay-fStartDay);
else
fElapsed += 24.0 * (28.0 - fStartDay + fCurDay);
if(fCurHour > fStartHour)
fElapsed += fCurHour-fStartHour+2.0;
else
fElapsed += -24.0 + fStartHour + fCurHour;
}
fElapsed = IntToFloat(nConv)*fElapsed;
fElapsed+=fCurMin*60.0;
fElapsed+=fCurSec;
return FloatToInt(fElapsed);
}