Custom function isn't working - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Custom function isn't working (
/showthread.php?tid=140284)
Custom function isn't working -
biltong - 08.04.2010
pawn Code:
stock GetTimeEx(&Hour, &Minute, &Second)
{
gettime(Hour, Minute, Second);
new s[3], m[3];
format(s, sizeof(s), "%d", Second);
format(m, sizeof(m), "%d", Minute);
if(strlen(s) == 1)
{
new Second2[3];
format(Second2, sizeof(Second2), "0%d", Second);
Second = strval(Second2);
}
if(!strlen(s))
{
new Second2[3];
format(Second2, sizeof(Second2), "00");
Second = strval(Second2);
}
if(strlen(m) == 1)
{
new Minute2[3];
format(Minute2, sizeof(Minute2), "0%d", Minute);
Minute = strval(Minute2);
}
if(!strlen(m))
{
new Minute2[3];
format(Minute2, sizeof(Minute2), "00", Minute);
Minute = strval(Minute2);
}
}
I made it because I was annoyed that if the time was for example 14:02:05 gettime would say 14:2:5. Do I need to return something at the end?
Re: Custom function isn't working -
M4S7ERMIND - 08.04.2010
You dont need such a complicated function for that.. >_<
Code:
format(str, sizeof(str), "Time: %02d:%02d", hour, minute);
Re: Custom function isn't working -
biltong - 08.04.2010
Then if the time were 14:43:15 for example you would get 14:043:015. Otherwise I would've done that.
Re: Custom function isn't working -
Miguel - 08.04.2010
Quote:
Originally Posted by biltong
Then if the time were 14:43:15 for example you would get 14:043:015. Otherwise I would've done that.
|
Nope, it will always format two numbers.
Re: Custom function isn't working -
M4S7ERMIND - 08.04.2010
Yup,
%02d is two numbers,
%03d three numbers etc.
Re: Custom function isn't working -
biltong - 08.04.2010
Ok, but then why does it not change anything?
Re: Custom function isn't working -
M4S7ERMIND - 08.04.2010
The code below prints time 14:02:05, so I dont know what you're doing wrong.. post the code.
Code:
printf("%02d:%02d:%02d.", 14, 2, 5);
Re: Custom function isn't working -
biltong - 08.04.2010
I didn't put the 2 in >.<