PDA

View Full Version : For best scripters


Kraeror
22/07/2017, 07:00 PM
Hello guys, I have problem with my clock. My host is in another country and the time there is different. I need to add 1 hour 3 minutes and 16 seconds to fix it. How can I add to my clock? Can you give me.

Kaperstone
22/07/2017, 07:06 PM
(3600 + 3 * 60 + 16) + gettime()) = your unix timestamp.

Kraeror
22/07/2017, 07:35 PM
(3600 + 3 * 60 + 16) + gettime()) = your unix timestamp.

Can you enter it here?

new string[256],year,month,day,hours,minutes,seconds;
getdate(year, month, day), gettime(hours, minutes, seconds);
format(string, sizeof string, "%d/%s%d/%s%d", day, ((month < 10) ? ("0") : ("")), month, (year < 10) ? ("0") : (""), year);
TextDrawSetString(Date, string);
format(string, sizeof string, "%s%d:%s%d:%s%d", (hours < 10) ? ("0") : (""), hours, (minutes < 10) ? ("0") : (""), minutes, (seconds < 10) ? ("0") : (""), seconds);
TextDrawSetString(Time, string);

Vince
22/07/2017, 07:44 PM
Oh, I don't like the replies on my earlier topic so I'll just post it again without taking in any information. (http://forum.sa-mp.com/showthread.php?t=637787)

Kraeror
22/07/2017, 07:46 PM
Oh, I don't like the replies on my earlier topic so I'll just post it again without taking in any information. (http://forum.sa-mp.com/showthread.php?t=637787)

I'm so sorry, but I could do nothing... I'm very disappointed!

Kaperstone
22/07/2017, 08:20 PM
I'm so sorry, but I could do nothing... I'm very disappointed!
That he actually did answer your question?

It's doing all the work for you.
Maybe its time to learn to code yourself or not code at all.


Its not that hard either, its actually just entering pluses and few numbers, not to mention Vince already gave you an explanatory.

Nevertheless, the fact that you said that you're disappointed in Vince, who actually spend his time (Which I guess can be called "wasted his time on you" by now) is very rude of you and you are the one to be disappointed in yourself.


Don't ask for help if you're not willing to learn and looking for people to waste their time doing job for you.

Paulice
22/07/2017, 09:08 PM
This should work :D ** /me copies others with their emoji **:
main()
{
printf("%s", GetDateAndTime());
printf("%s", GetDateAndTime(3796)); // 3796 seconds = 1 hour, 3 minutes and 16 seconds
}

GetDateAndTime(second_diff = 0)
{
new string[21], year, month, day, hour, minute, second;
getdate(year, month, day), gettime(hour, minute, second);

second += second_diff;

while(second >= 60)
{
second -= 60;
minute += 1;

if(minute >= 60)
{
minute -= 60;
hour += 1;

if(hour >= 24)
{
hour -= 24;

switch(month)
{
case 1, 3, 5, 7, 8, 10, 12: // January, March, May, July, August, October and December
{
if(day < 31)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
case 2: // February
{
if(IsLeapYear(year))
{
if(day < 29)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
else
{
if(day < 28)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
}
case 4, 6, 9, 11: // April, June, September and November
{
if(day < 30)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
}

if(month > 12)
{
month = 1;
year ++;
}
}
}
}

format(string, sizeof(string), "%02d-%02d-%04d, %02d:%02d:%02d", month, day, year, hour, minute, second);
return string;
}

IsLeapYear(year)
{
return (((!(year % 4)) && (year % 100)) || (!(year % 400)));
}

Kaperstone
22/07/2017, 10:53 PM
This won't do the work.

He'd want you to show this in a textdraw.
You don't have a textdraw code.

Code one.

Paulice
22/07/2017, 11:00 PM
This won't do the work.

He'd want you to show this in a textdraw.
You don't have a textdraw code.

Code one.

How about you give me some chocolate :cool:

Kraeror
23/07/2017, 08:58 AM
This should work :D ** /me copies others with their emoji **:
main()
{
printf("%s", GetDateAndTime());
printf("%s", GetDateAndTime(3796)); // 3796 seconds = 1 hour, 3 minutes and 16 seconds
}

GetDateAndTime(second_diff = 0)
{
new string[21], year, month, day, hour, minute, second;
getdate(year, month, day), gettime(hour, minute, second);

second += second_diff;

while(second >= 60)
{
second -= 60;
minute += 1;

if(minute >= 60)
{
minute -= 60;
hour += 1;

if(hour >= 24)
{
hour -= 24;

switch(month)
{
case 1, 3, 5, 7, 8, 10, 12: // January, March, May, July, August, October and December
{
if(day < 31)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
case 2: // February
{
if(IsLeapYear(year))
{
if(day < 29)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
else
{
if(day < 28)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
}
case 4, 6, 9, 11: // April, June, September and November
{
if(day < 30)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
}

if(month > 12)
{
month = 1;
year ++;
}
}
}
}

format(string, sizeof(string), "%02d-%02d-%04d, %02d:%02d:%02d", month, day, year, hour, minute, second);
return string;
}

IsLeapYear(year)
{
return (((!(year % 4)) && (year % 100)) || (!(year % 400)));
}

Okay, It works perfect, but can you help me with hour to /ban command? (give me an example)