Raised This Month: $12 Target: $400
 3% 

str_to_num question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-07-2021 , 14:20   str_to_num question
Reply With Quote #1

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 ?
lexzor is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-07-2021 , 15:23   Re: str_to_num question
Reply With Quote #2

%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]) 
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-07-2021 , 15:48   Re: str_to_num question
Reply With Quote #3

in that case, what is better to use ?

if i use %i for number 35 will print just 3 or 5 ?
lexzor is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 05-07-2021 , 16:04   Re: str_to_num question
Reply With Quote #4

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'.
__________________
LondoN is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-07-2021 , 16:29   Re: str_to_num question
Reply With Quote #5

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] ); 
__________________

Last edited by Bugsy; 05-07-2021 at 16:30.
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-07-2021 , 16:32   Re: str_to_num question
Reply With Quote #6

Quote:
Originally Posted by lexzor View Post
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.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:30.


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