SA-MP Forums Archive
[Problem] Day calculation - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Problem] Day calculation (/showthread.php?tid=322638)



[Problem] Day calculation - rAzvAn18 - 03.03.2012

I have a problem with day calculation of my ban sistem , There are months with 29 day , 30 and 31 .


Код:
while(hour > 24)
	{
		day++;
		hour -= 24;
	}
	while(day > 30)
	{
		 month++;
		 day -= 30;
	}
	while(month > 12)
	{
		year++;
		month -= 12;
	}



Re: [Problem] Day calculation - DarkScripter - 03.03.2012

Try this:

pawn Код:
new LastDays2012[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 }; // lookin the calender of 2012

if(hour > 24)
{
    day++;
    hour -= 24;
}
if(day > LastDays2012[month])
{
    month++;
    day -= LastDays2012[month];
}
if(month > 12)
{
    year++;
    month -= 12;
}



Re: [Problem] Day calculation - Deduction - 03.03.2012

That is a good system DarkScripter shows, but you could create a better system using GetTime and GetDate.


Re: [Problem] Day calculation - DarkScripter - 03.03.2012

Quote:
Originally Posted by Deduction
Посмотреть сообщение
That is a good system DarkScripter shows, but you could create a better system using GetTime and GetDate.
the gettime and getdate don't get last days of month...


Re: [Problem] Day calculation - rAzvAn18 - 03.03.2012

Thanks , but better use while it's repeating untill the condition is false


Re: [Problem] Day calculation - rAzvAn18 - 03.03.2012

It's not working so good


Re: [Problem] Day calculation - Jochemd - 03.03.2012

Use timestamps!

Gettime returns a Unix Timestamp, which is the seconds past since 1 January 1970. If you want to give a two-days ban, you can do it this way:

pawn Код:
unbantime = gettime() + (60 * 60 * 24 * DAYS); // returns the timestamp which the player should be unbanned
Then create a simple one-day-timer which loops through a file with banned IPs and their unban-timestamp. If the timestamp matches the current timestamp or if it's lower, unban!


Re: [Problem] Day calculation - rAzvAn18 - 03.03.2012

No , it's not good with time stamp And I have an ideea how to make , thanks.