How to detect a specific day?
#1

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?
Reply
#2

The easiest way I can think of is invoking a PHP script with the HTTP method.
Reply
#3

Check this link.
https://sampwiki.blast.hk/wiki/Getdate
Reply
#4

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.
Reply
#5

Paste this somewhere on your script.
Note: Don't put it on callbacks.

pawn Код:
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 :
pawn Код:
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
Reply
#6

Wow,I'm gonna try this out,good job you have done here.
Reply
#7

Quote:
Originally Posted by Facerafter
Посмотреть сообщение
I think he means that he wants to implement the real date in game, not a date which he can setup himself (virtual date).
Reply
#8

Quote:
Originally Posted by Red_Dragon.
Посмотреть сообщение
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)