RealTime and Hour [+REP] -
arlindi - 20.01.2015
Hello i want to make something IF you can help mee please
I want to create: when the day its monday and the hour is 12:00 (in real life) Set The pInfo[playerid][pAdminLevel] == 0);
Please help mee
Re: RealTime and Hour [+REP] -
Kaperstone - 20.01.2015
Time:
https://sampwiki.blast.hk/wiki/Gettime
Date:
https://sampwiki.blast.hk/wiki/Getdate
Note: this will get the server date and time, if you want to fit this into a the player's real time, then you will need to get his location and calculate the timezone, from there calculate the server time and his timezone, and done.
Re: RealTime and Hour [+REP] -
xVIP3Rx - 20.01.2015
after 30 seconds search
Quote:
Originally Posted by Red_Dragon.
I searched for something similar to this a while ago and I got two snippets saved.
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
pawn Код:
switch(GetDayName()) { case 1: //Sunday case 2: //Monday case 3: //Tuesday case 4: //Wednesday case 5: //Thursday case 6: //Friday case 7: //Saturday default: //error }
|
Re: RealTime and Hour [+REP] -
arlindi - 20.01.2015
I dont want name just tosetvadmin level 0
I dont need nothing name or something just to set it 0
Re: RealTime and Hour [+REP] -
xVIP3Rx - 20.01.2015
People these days, too lazy to apply the fix..
pawn Код:
//Whereever you want it
new Hour, Minutes, Seconds; gettime(hour, minute, Seconds);
if(GetDayName() == 2 && Hour == 12 && !Minutes && !Seconds) pInfo[playerid][pAdminLevel] = 0;
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;
}
Re: RealTime and Hour [+REP] -
arlindi - 20.01.2015
I want every month every mondey
Re: RealTime and Hour [+REP] -
xVIP3Rx - 20.01.2015
Quote:
Originally Posted by arlindi
I want every month every mondey
|
The code I gave checks if it's Monday, No matter what month/year it is
Meaning it'll be called every Monday.
Re: RealTime and Hour [+REP] -
arlindi - 20.01.2015
Ok I but where tovadd it to check if is monday
Re: RealTime and Hour [+REP] -
xVIP3Rx - 20.01.2015
pawn Код:
public OnGameModeInit()
{
SetTimer("OneSecondTimer", 1000, true);
return 1;
}
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;
}
forward OneSecondTimer();
public OneSecondTimer()
{
new Hour, Minutes, Seconds; gettime(Hour, Minutes, Seconds);
if(GetDayName() == 2 && Hour == 12 && !Minutes && !Seconds) pInfo[playerid][pAdminLevel] = 0;
return 1;
}
Not the best way to do it, but it works
Re: RealTime and Hour [+REP] -
arlindi - 20.01.2015
I thing to add it on player connect
And how can I make it if[playerid][admin level]
Its more than 1 set it 0