AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Time Format (https://forums.alliedmods.net/showthread.php?t=316012)

gabuch2 05-04-2019 01:24

Time Format
 
Hello

I'm using get_time_length() to display a time remaining hud message.
Code:
new hud[125] get_time_length(iPlayers[i], g_iRoundTime, timeunit_seconds, hud, charsmax(hud));

But it gets formated like this:
https://i.imgur.com/YogpW0w.png

Is there anyway to use the HH:MM:SS format?

EDIT: Fixed it by borrowing the code from another plugin.

Code:
new hud[125] new m = g_iRoundTime/60 new h = m/60 new s = g_iRoundTime-m*60 m = m-h*60 if(h)     formatex(hud,charsmax(hud),"%d:%02d:%02d",h,m,s) else     formatex(hud,charsmax(hud),"%d:%02d",m,s)

fysiks 05-04-2019 02:35

Re: Time Format
 
Try format_time() from amxmodx.inc.

gabuch2 05-04-2019 13:04

Re: Time Format
 
Quote:

Originally Posted by fysiks (Post 2650143)
Try format_time() from amxmodx.inc.

Hello.

Sadly, format_time() accepts a unix timestamp as a parameter, while I'm using seconds remaning in g_iRoundTime.

Natsheh 05-04-2019 13:07

Re: Time Format
 
g_iRoundTime += g_Current_timestamp.......

fysiks 05-04-2019 16:10

Re: Time Format
 
Quote:

Originally Posted by Natsheh (Post 2650259)
g_iRoundTime += g_Current_timestamp.......

No, that won't work in this case.

Quote:

Originally Posted by Gabe Iggy (Post 2650257)
Hello.

Sadly, format_time() accepts a unix timestamp as a parameter, while I'm using seconds remaning in g_iRoundTime.

The idea was that you would format only the time (and not the date) and I assumed that your values wouldn't ever exceed 24 hours. In that case, it should work just fine. However, I just tested it and I realized that it gets the time/date from your PC which will take into account the timezone. If it used GMT always, it would work just fine.

Now, if you subtract the timezone offset, it works the way I was suggesting. However, subtracting the timezone offset will only work if you are west of the GMT. If you are east of the GMT you'd need to also add 24 hours.

The only other obstacle is accounting for daylights savings which actually shifts your timezone offset.


So, this works for me:

PHP Code:

public cmdTest()
{
    new 
szArg[100], iArg
    read_args
(szArgcharsmax(szArg))
    
remove_quotes(szArg)
    
iArg str_to_num(szArg)
    
    new 
iGMTOffset_h = -// GMT-06:00
    
    
new szTime[100]
    
format_time(szTimecharsmax(szTime), "%H:%M:%S"iArg 3600*iGMTOffset_h)
    
server_print(szTime)



However, it's going to be better to write a new function to do this:

PHP Code:

public relative_time_string(szTimeString[], leniSeconds)
{
    
formatex(szTimeStringlen"%02d:%02d:%02d"iSeconds 3600, (iSeconds 3600) / 60iSeconds 60)




All times are GMT -4. The time now is 11:48.

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