Flight Time , Seconds to Minutes -
Robbin237 - 19.02.2009
Im resuming my flight script but ran into a problem.
The flighttime is set using
pawn Код:
FlightTime[player] = FLTime_LosSantos;
Or whatever city is chosen. On the top of my script i have:
pawn Код:
#define FLTime_LosSantos 70
#define FLTime_SanFierro 43
#define FLTime_LasVenturas 41
new FlightTime[MAX_PLAYERS];
pawn Код:
if(FlightTime[player] > 9)
{
if(FlightTime[player] > 59 & < 120)
{
Minutes++1
Seconds = Minutes-FlightTime[player];
format(string, sizeof(string), "~w~Flight Time: ~g~0%d:%d", Minutes, FlightTime[player]);
} else {
format(string, sizeof(string), "~w~Flight Time: ~g~00:%d", Minutes, FlightTime[player]);
}
} else {
format(string, sizeof(string), "~w~Flight Time: ~g~00:0%d", FlightTime[player]);
}
}
Now what i want is that if the seconds are above 60 like defined in FLTime_LosSantos (70 seconds), it will count + one minute, and then also displays the seconds. So like 01:10 it must display then.
The other code, is if the seconds are above 9 it wont display an extra 0, because if its below 9 (the seconds) it will do like: 00:05.
Can somebody help me with this?
Thanks a million.
Re: Flight Time , Seconds to Minutes -
Joe Staff - 19.02.2009
flighttime[playerid]-(Minutes*60) is how you would get the seconds
[qupte]
The other code, is if the seconds are above 9 it wont display an extra 0, because if its below 9 (the seconds) it will do like: 00:05.
[/quote]
usings just %02d adds 2 '0's unless a number is presented, so if it's 0, you'll get 00, if it's 9 you'll get 09, if it's 10, you'll get 10
Re: Flight Time , Seconds to Minutes -
Robbin237 - 19.02.2009
EDIT: Can you please correct my code?
Re: Flight Time , Seconds to Minutes -
yom - 19.02.2009
Tired of posting this function, anyway..
pawn Код:
enum tc_method
{
tc_milliseconds,
tc_seconds,
tc_minutes
}
stock TimeConvert(time, &dd, &hh, &mm=0, &ss=0, &ms=0, tc_method:method=tc_milliseconds)
{
if (method == tc_milliseconds)
{
ms = time % 1000;
time = (time - ms)/1000;
ss = time % 60;
time = (time - ss)/60;
}
else if (method == tc_seconds)
{
ss = time % 60;
time = (time - ss)/60;
}
mm = time % 60;
time = (time - mm)/60;
hh = time % 24;
time = (time - hh)/24;
dd = time;
}
And for you it's just something like that:
pawn Код:
new minutes, seconds;
TimeConvert(FLTime_LosSantos, minutes, minutes, minutes, seconds, .method = tc_seconds);
format(string, sizeof(string), "~w~Flight Time: %02d:%02d", minutes, seconds);
Re: Flight Time , Seconds to Minutes -
Robbin237 - 20.02.2009
This only displays 00:30
This is my code:
pawn Код:
if(FlightTime[player] > 9)
{
new minutes, seconds;
TimeConvert(FLTime_LosSantos, minutes, minutes, minutes, seconds, .method = tc_seconds);
format(string, sizeof(string), "~w~Flight Time: %02d:%02d", minutes, seconds);
} else {
format(string, sizeof(string), "~w~Flight Time: ~g~00:0%d", FlightTime[player]);
}
GameTextForPlayer(player, string, 3000, 4);
Re: Flight Time , Seconds to Minutes -
yom - 20.02.2009
my bad, i forgot that my function first set ms, ss, mm, then hh and dd (so the final value of minutes in the example would be in fact, the days..)
You have to create a dummy variable.
pawn Код:
new useless, minutes, seconds;
TimeConvert(FLTime_LosSantos, useless, useless, minutes, seconds, .method = tc_seconds);
Or, to avoid creating an extra unused variable (waste of memory), change the function header to:
pawn Код:
stock TimeConvert(time, &dd=0, &hh=0, &mm=0, &ss=0, &ms=0, tc_method:method=tc_milliseconds)
and then you can do like that:
pawn Код:
new minutes, seconds;
TimeConvert(FLTime_LosSantos, _, _, minutes, seconds, .method = tc_seconds);