AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   str_to_num question (https://forums.alliedmods.net/showthread.php?t=332364)

lexzor 05-07-2021 14:20

str_to_num question
 
hello. i have this code

PHP Code:

replace_all(szTemp[id], charsmax(szTemp[]), ":"" ")
        
parse(szTemp[id], szHoursTemp[id], charsmax(szHoursTemp[]), szMinutesTemp[id], charsmax(szMinutesTemp[]), szSecondsTemp[id], charsmax(szSecondsTemp[]))

        
iHoursTemp[id] = str_to_num(szHoursTemp[id]) + g_iPlayedTime[id][Hours]
        
iMinutesTemp[id] = str_to_num(szMinutesTemp[id]) + g_iPlayedTime[id][Minutes]
        
iSecondsTemp[id] = str_to_num(szSecondsTemp[id]) + g_iPlayedTime[id][Seconds]

        
server_print("%i %i %i"iHoursTemp[id], iMinutesTemp[id], iSecondsTemp[id])

        
formatex(g_iPlayersInfo[id][PlayedTime], charsmax(g_iPlayersInfo[][PlayedTime]), "%s%i:%s%i:%s%i",
        
iHoursTemp[id] < 10 "0" ""iHoursTemp[id], iMinutesTemp[id] < 10 "0" "",
        
iMinutesTemp[id], iSecondsTemp[id] < 10 "0" ""iSecondsTemp[id]) 

i'm trying to get the time. the problem is that the format is 00:00:00 (example of 5 hours, 14 mins and 7 second: 05:14:07)

The problem is that i think i can t use str_to_num like that (i mean to use it for a number like 05 or 07). some ideas ?

Shadows Adi 05-07-2021 15:23

Re: str_to_num question
 
%i is the same as %01, printing a one digit integer: 5
%02i will print a too digit integer: 05
%03i will print a three digit integer: 005
and so on...

PHP Code:

 server_print("%02i %02i %02i"iHoursTemp[id], iMinutesTemp[id], iSecondsTemp[id]) 


lexzor 05-07-2021 15:48

Re: str_to_num question
 
in that case, what is better to use ?

if i use %i for number 35 will print just 3 or 5 ?

LondoN 05-07-2021 16:04

Re: str_to_num question
 
strbeak or parse will resolve your problem.


you need to elimitate the ":" from the string.

Also replace get_time with time(h,m,s).
And after this use str_to_num.

If you dont want, compare the strings, it's more easyer, but more 'hardcoded'.

Bugsy 05-07-2021 16:29

Re: str_to_num question
 
If your time will always be in ##:##:## format eg. 05:14:07, you can do

PHP Code:

new szTime[] = "05:14:07";

szTime] = EOS;
szTime] = EOS;

iHour str_to_numszTime );
iMin str_to_numszTime] );
iSec str_to_numszTime] ); 


Shadows Adi 05-07-2021 16:32

Re: str_to_num question
 
Quote:

Originally Posted by lexzor (Post 2746233)
in that case, what is better to use ?

if i use %i for number 35 will print just 3 or 5 ?

No, it will print the entire integer.


All times are GMT -4. The time now is 16:03.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.