SA-MP Forums Archive
Convert seconds into minutes. - 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)
+--- Thread: Convert seconds into minutes. (/showthread.php?tid=647730)



Convert seconds into minutes. - jasperschellekens - 09.01.2018

Is it possible to convert seconds into minutes? and how would i do this?

This will display seconds:
PHP код:
format(str,sizeof(str),"{FFFFFF}Ban expire: {FF0000}in %d seconds\n\n",iDump-gettime());
              
strcat(string2,str); 
Seconds are selected from SQLlite db.

PHP код:
db_get_field_assoc(qHandle"banlength"szDumpsizeof(szDump));
        
iDump strval(szDump); 



Re: Convert seconds into minutes. - RowdyrideR - 09.01.2018

i thought of giving an idea that might help better than waiting too long for someone to reply, comment will be removed.


Re: Convert seconds into minutes. - RogueDrifter - 09.01.2018

why did you ignore rowdyrider lol he told you exactly what you needed... ex: if iDump-gettime() returns seconds then if you want it to return minutes
PHP код:
format(str,sizeof(str),"{FFFFFF}Ban expire: {FF0000}in %d seconds\n\n",iDump-gettime()/60); 
              
strcat(string2,str); 
see that /60 divide by 60 to return minutes , minute = 60 seconds
But if iDump-gettime() returns MS then you do /60*1000 which is /60000


Re: Convert seconds into minutes. - Kane - 09.01.2018

PHP код:
stock TimeConvert(seconds)
{
    new 
MS;
    new 
string[128];
    
    
seconds 60 ;
    
seconds 60 ;
    
60 ;
    
    
format(stringsizeof string"%02d:%02d"MS); 
    return 
string;

Example:

PHP код:
new time[32];
format(time32"%s"TimeConvert(200));
SendClientMessage(playerid, -1time); 



Re: Convert seconds into minutes. - jollyjoe321 - 09.01.2018

return seconds/60;

Can set the method framework up yourself.

If you're actually asking how to alter the string to contain minutes, then the quickest way would be to identify the number at a specified index (assuming the sentence is always the same length). If not, find the index of the substring "seconds", and work backwards I guess.


Re: Convert seconds into minutes. - Dayvison_ - 09.01.2018

PHP код:
stock convertTime(time, &days, &hours, &minutes, &seconds)
{
    if (
time 0)
        return 
0;

    
hours time 3600;
    
minutes = ((time 60) - (hours 60));
    
seconds time 60;
    if(
hours 23)
    {
        
days hours 24;
        
hours hours 24;
    }
    return 
1;




Re: Convert seconds into minutes. - RowdyrideR - 10.01.2018

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
why did you ignore rowdyrider lol he told you exactly what you needed... ex: if iDump-gettime() returns seconds then if you want it to return minutes
PHP код:
format(str,sizeof(str),"{FFFFFF}Ban expire: {FF0000}in %d seconds\n\n",iDump-gettime()/60); 
              
strcat(string2,str); 
see that /60 divide by 60 to return minutes , minute = 60 seconds
But if iDump-gettime() returns MS then you do /60*1000 which is /60000
I believe he wanted the exact code not how to make it lol, anyways.


Re: Convert seconds into minutes. - iLearner - 10.01.2018

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
PHP код:
stock TimeConvert(seconds)
{
    new 
MS;
    new 
string[128];
    
    
seconds 60 ;
    
seconds 60 ;
    
60 ;
    
    
format(stringsizeof string"%02d:%02d"MS); 
    return 
string;

Example:

PHP код:
new time[32];
format(time32"%s"TimeConvert(200));
SendClientMessage(playerid, -1time); 
Why do you want to format something is already formatted?


PHP код:
)
SendClientMessage(playerid, -1TimeConvert(200)); 
would work perfectly.


Re: Convert seconds into minutes. - Kane - 10.01.2018

Quote:
Originally Posted by iLearner
Посмотреть сообщение
Why do you want to format something is already formatted?


PHP код:
)
SendClientMessage(playerid, -1TimeConvert(200)); 
would work perfectly.
It's an example; that's how you would do it to use it with other text as well obviously.


Re: Convert seconds into minutes. - jasperschellekens - 10.01.2018

Quote:
Originally Posted by iLearner
Посмотреть сообщение
Why do you want to format something is already formatted?


PHP код:
)
SendClientMessage(playerid, -1TimeConvert(200)); 
would work perfectly.
Could someone explain me the code a little?? i don't really understand.. why 200 seconds? TimeConvert(200)