SA-MP Forums Archive
I need a stock to get a correct date - 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: I need a stock to get a correct date (/showthread.php?tid=385032)



I need a stock to get a correct date - [FSaF]Jarno - 14.10.2012

I need a stock to count days/hours/minutes/seconds ect. from minutes, i don't know how to explain it and therefore i didn't know what to search for in the forums. All i want is this:

stock GetDateAfterMinutes(minutes,&day,&month,&year)

I know how to make it in theory, but my brain capacity isn't enough to think about it.

It needs to get a correct date everytime, so it has to know how many days are in every month, is it a leap year (does febhave 28 or 29 days) and so on. Post me some links to existing threads, or even give me the stock if you have one.

Thanks, Jarno.


Re: I need a stock to get a correct date - ikkentim - 14.10.2012

Could you explain better what this stoch should do?
What values do you put in? What values should come out? (An example with values please?)


Re: I need a stock to get a correct date - [FSaF]Jarno - 14.10.2012

I tried to make the example as clear as possible, you put in minutes, and it gives you a date and time that will be after the amount of minutes.

example:

It's 12:40 in 15.6.2012

when i put in 60 minutes, the outcome is:

13:40 in 15.6.2012

if the minutes exceed the day, it will add more days, years, months ect. Hopefully you understood.


Re: I need a stock to get a correct date - ikkentim - 14.10.2012

Notice this is untested, but should work:
GetDateAfterMinutes(minutes,&day,&month,&year)
{
new sec = gettime() + minutes*60;
getdate(year,month,day);
day+=sec / 60 / 60 / 24;
new dim[12]={31,28,31,30,31,30,31,31,30,31,30,31};
while(day > dim[month-1]+(month==2 && year%4 == 0 ? 1 : 0))
{
day -= dim[month-1]+(month==2 && year%4 == 0 ? 1 : 0);
month++;
year+=month/12;
month=month%12;

}
}



I think that works!
If not, tell me!(im not on my pc and unable to test.)


Re: I need a stock to get a correct date - [FSaF]Jarno - 14.10.2012

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
Notice this is untested, but should work:
GetDateAfterMinutes(minutes,&day,&month,&year)
{
new sec = gettime() + minutes*60;
getdate(year,month,day);
day+=sec / 60 / 60 / 24;
new dim[12]={31,28,31,30,31,30,31,31,30,31,30,31};
while(day > dim[month-1]+(month==2 && year%4 == 0 ? 1 : 0))
{
day -= dim[month-1]+(month==2 && year%4 == 0 ? 1 : 0);
month++;
year+=month/12;
month=month%12;

}
}



I think that works!
If not, tell me!(im not on my pc and unable to test.)
Imma check if it works.
Note: According to the rules it is unallowed to post untested code, but i don't mind.


Re: I need a stock to get a correct date - [FSaF]Jarno - 14.10.2012

Actually, i also need the time. I am making a tempban script so minutes and hours are also needed. Thanks anyways!

(Don't tell me to download a pre made tempban script, i don't like to use scripts made by others...)


Re: I need a stock to get a correct date - ikkentim - 14.10.2012

Quote:
Originally Posted by [FSaF]Jarno
Посмотреть сообщение
(Don't tell me to download a pre made tempban script, i don't like to use scripts made by others...)
Good, you think the way I think too


AW: I need a stock to get a correct date - s3rserii - 14.10.2012

The unix timestamp is fine for tempbans
To learn for noobs: https://sampforum.blast.hk/showthread.php?tid=254915

Код:
stock Now()
{
	new hour,minute,second,year,month,day;
	gettime(hour, minute, second);
	getdate(year, month, day);
	return mktime(hour,minute,second,day,month,year);
}
For 60 minutes ban
Код:
PlayerInfo[playerid][pBanTime] += (Now() + 3600);
Than a timer for look if time now is higher than pBanTime like:
Код:
if(PlayerInfo[playerid][pBanTime] <= Now())
{
   PlayerInfo[playerid][pBanTime] = 0;
}
easy


Re: AW: I need a stock to get a correct date - [FSaF]Jarno - 14.10.2012

Quote:
Originally Posted by s3rserii
Посмотреть сообщение
The unix timestamp is fine for tempbans
To learn for noobs: https://sampforum.blast.hk/showthread.php?tid=254915

Код:
stock Now()
{
	new hour,minute,second,year,month,day;
	gettime(hour, minute, second);
	getdate(year, month, day);
	return mktime(hour,minute,second,day,month,year);
}
For 60 minutes ban
Код:
PlayerInfo[playerid][pBanTime] += (Now() + 3600);
Than a timer for look if time now is higher than pBanTime like:
Код:
if(PlayerInfo[playerid][pBanTime] <= Now())
{
   PlayerInfo[playerid][pBanTime] = 0;
}
easy
That won't work, it uses playerid wich can and will change once you kick him out. Also, what is this "mktime" you are talking about? Get lost unless you actually have the stock to give to me. (Not meaning to offend anyone)


AW: I need a stock to get a correct date - s3rserii - 14.10.2012

what? now, i show you only the variables.. but it is right you must save it to your files or to your mysql database after u use your ban command. and it will work 100%.

mktime is a good stock to become the correct date.
here is the stock but it is not my code

Код:
stock mktime(hour, minute, second, day, month, year)
{
        static
                days_of_month[12] =
                {
                        31,
                        29,
                        31,
                        30,
                        31,
                        30,
                        31,
                        31,
                        30,
                        31,
                        30,
                        31
                },
                lMinute,
                lHour,
                lDay,
                lMonth,
                lYear,
                lMinuteS,
                lHourS,
                lDayS,
                lMonthS,
                lYearS;
        if (year != lYear)
        {
                lYearS = 0;
                for (new j = 1970; j < year; j++)
                {
                        lYearS += 31536000;
                        if ((!(j % 4) && (j % 100)) || !(j % 400)) lYearS += 86400;
                }
                lYear = year;
        }
        if (month != lMonth)
        {
                lMonthS = 0;
                month--;
                for (new i = 0; i < month; i++)
                {
                        lMonthS += days_of_month[i] * 86400;
                        if ((i == 1) && ((!(year % 4) && (year % 100)) || !(year % 400))) lMonthS += 86400;
                }
                lMonth = month;
        }
        if (day != lDay)
        {
                lDayS = day * 86400;
                lDay = day;
        }
        if (hour != lHour)
        {
                lHourS = hour * 3600;
                lHour = hour;
        }
        if (minute != lMinute)
        {
                lMinuteS = minute * 60;
                lMinute = minute;
        }
        return lYearS + lMonthS + lDayS + lHourS + lMinuteS + second;
}