Hey there Lightfoot. This is perfect. Thank you for the reply. I was thinking about how to store it as one big int and then breaking it up but couldn't figure out the math. Still can't, even though you just showed me.
EDIT: The modules month and day can not be a 0. They have to start on 1. Not sure if that adds any problems to this math at all. So the mod would start with the standard year 1372. The month and day can both start on 1 if that is necessary and the hour can be 0. Would i just get rid of the -1's and +1's?
So this is what I did with what you explained. I changed it slightly to allow for keeping the year at its current number and not having to set it to 0. I hope I didn't screw anything up. I only tested this for the passing of 2 hours so I don't know whether or not there will be any issues when numbers get smaller again, y2k or what not. Seems to work ok so far. But please let me know if I messed it up.
//Function to save current calendar date and time to a database.
void SaveCurrentDateTime()
{
string sDBName = "PERSISTENT_DATE_TIME";
int iYear = GetCalendarYear();
int iMonth = GetCalendarMonth();
int iDay = GetCalendarDay();
int iHour = GetTimeHour();
int iDate = (iYear * 8064) + ((iMonth - 1) * 672) + ((iDay -1) * 24) + iHour;
SetCampaignInt(sDBName, "INT_DATE_TIME", iDate);
//test lines
object oPC = GetFirstPC();
SendMessageToPC(oPC, "Time Saved!");
//
}
void RecursiveStoreDateTime()
{
DelayCommand(2.0, SaveCurrentDateTime());
DelayCommand(120.0, RecursiveStoreDateTime());
}
//Function to set the stored calendar date and time onto the PW.
void SetPWDateTime()
{
string sDBName = "PERSISTENT_DATE_TIME";
int iStored = GetCampaignInt(sDBName, "DATE_TIME_STORED");
int iDate = GetCampaignInt(sDBName, "INT_DATE_TIME");
int iYear = iDate / 8064;
int iMonth = ((iDate % 8064) / 672) + 1;
int iDay =((iDate % 672) / 24) + 1;
int iHour = iDate % 24;
//test lines. This will show 0,1,1,0 until database entry is added.
string sYear = IntToString(iYear);
string sMonth = IntToString(iMonth);
string sDay = IntToString(iDay);
string sHour = IntToString(iHour);
DelayCommand(10.0, SendMessageToPC(GetFirstPC(),"The year is: " + sYear +
"\\nThe month is: " + sMonth +
"\\nThe day is: " + sDay +
"\\nThe hour is: " + sHour));
//
if (iStored != TRUE)
{
SetCampaignInt(sDBName, "DATE_TIME_STORED", TRUE);
RecursiveStoreDateTime();
}
else
{
SetCalendar(iYear, iMonth, iDay);
SetTime(iHour, GetTimeMinute(), GetTimeSecond(), GetTimeMillisecond());
RecursiveStoreDateTime();
}
}
Oh and on this subject:
Lightfoot8 wrote...
I dont think I would use a HB. I think I would use something more
like OnClient leave. Who really cares if time passes or not if no one
is on the server?
I was thinking about this too. But there is a little problem. If say only like 3 people are on the server and they have been playing for a few hours and suddenly the server crashes, then the date and time will not have had a chance to save. Then when they got back on, time might have gone backwards a couple days and who knows what hour.
Modifié par GhostOfGod, 19 août 2010 - 03:49 .