PDA

View Full Version : How to detect a specific day?


Tamer
09/06/2013, 11:10 PM
I came up with this idea,on my server the sundays must be special,more score,money,rewards,events etc. Which will make more fun,since the servers are mostly crowded on sundays.

I want the script to detect if it's sunday or not on its own,I don't want to define all days,simply the script should check what day it is,if it's sunday,start the mayhem.

So I wonder if there is a possibility to do this or not,If there isn't,I'll need to define all days ,as an example,Script gets the date and month,if it's June 16,it's Sunday obviously,but this needs us to put effort and define all months to the script,uses too much lines etc. etc. Maybe there is a possible formula to do this?

Vince
09/06/2013, 11:23 PM
The easiest way I can think of is invoking a PHP script with the HTTP method.

Facerafter
09/06/2013, 11:25 PM
Check this link.
http://wiki.sa-mp.com/wiki/Getdate

Tamer
09/06/2013, 11:41 PM
You didn't read what I said. I don't want a number,I want a day! Not a number. That function will return a number,not a day name.

DeMoX
09/06/2013, 11:41 PM
Paste this somewhere on your script.
Note: Don't put it on callbacks.

stock GetDayName(d=0,m=0,y=0) {
/*
0=Invalid date
1=Sunday
2=Monday
...
7=Saturday
*/
if(d==0&&m==0&&y==0) { //set to today if no values passed
getdate(y, m, d);
}

new month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
i;

if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
month[1] = 29;

if (y < 1900 || m < 1 || m > 12 || d < 1 || d > month[m - 1])
return 0;

for (i = 1900; i < y; i++) {
if (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0))
d += 366;
else
d += 365;
}

for (i = 0; i < m - 1; i++) {
d += month[i];
}

return d%7+1;
}

And use this :
new day=GetDayName();
if(day == 1) // Sunday
if(day == 2) // Monday
if(day == 3) // Tuesday
if(day == 4) // Wednesday
if(day == 5) // Thursday
if(day == 6) // Friday
if(day == 7) // Saturday

Tamer
09/06/2013, 11:44 PM
Wow,I'm gonna try this out,good job you have done here.

Red_Dragon.
09/06/2013, 11:56 PM
Check this link.
http://wiki.sa-mp.com/wiki/Getdate
I think he means that he wants to implement the real date in game, not a date which he can setup himself (virtual date).

DeMoX
10/06/2013, 10:57 AM
I think he means that he wants to implement the real date in game, not a date which he can setup himself (virtual date).

It's real life time, and it's working perfectly