AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Get remain time problem (https://forums.alliedmods.net/showthread.php?t=333989)

loiraolhosazul 08-21-2021 19:28

Get remain time problem
 
I'm trying to get the rest of the hour, but I'm in trouble.

HTML Code:

Now: 20 horas 26 minutos 50 segundos
Remain: 0 hora -60 minuto 0 segundo

Code:

public xdxd()
{
        new h, m, s, i, mm, d, now, start, discount, remain_time, gethours[3], xfmt[128]

        time(gethours[0], gethours[1], gethours[2])

        start = 22
        discount = floatround(float(start - gethours[0]), floatround_ceil)

        now = get_systime()
        remain_time = get_systime(3600 * discount) - now


        UnixToTime(now, i, mm, d, h, m, s, UT_TIMEZONE_SERVER)
        formatex(xfmt, charsmax(xfmt), "Now: %d hora%s %d minuto%s %d segundo%s", h, h > 1 ? "s" : "", m, m > 1 ? "s" : "", s, s > 1 ? "s" : "")
       
        server_print(xfmt)


        UnixToTime(remain_time, i, mm, d, h, m, s, UT_TIMEZONE_SERVER)
        formatex(xfmt, charsmax(xfmt), "Remain: %d hora%s %d minuto%s %d segundo%s", h, h > 1 ? "s" : "", m, m > 1 ? "s" : "", s, s > 1 ? "s" : "")
       
        server_print(xfmt)
}


Bugsy 08-21-2021 19:58

Re: Get remain time problem
 
Give an example of input and output.

Based on your request, you only want the number of minutes remaining in the current hour?

loiraolhosazul 08-21-2021 20:00

Re: Get remain time problem
 
Quote:

Originally Posted by Bugsy (Post 2755844)
Give an example of input and output.

Based on your request, you only want the number of minutes remaining in the current hour?

I have an event, it starts at 22
I want to get the remaining time until the time of the event

Bugsy 08-21-2021 20:01

Re: Get remain time problem
 
Is this 22 event stored via unix timestamp? What is the initial value/format I am working with to get remaining time?

loiraolhosazul 08-21-2021 20:02

Re: Get remain time problem
 
Quote:

Originally Posted by Bugsy (Post 2755846)
Is this 22 event stored via unix timestamp? What is the initial value/format I am working with to get remaining time?

the value is integer 22 by cvar, but i need to convert everything to unix for me to print 'correctly'

Bugsy 08-21-2021 20:03

Re: Get remain time problem
 
So the 22 corresponds to the 22nd hour of the current day?

loiraolhosazul 08-21-2021 20:04

Re: Get remain time problem
 
Quote:

Originally Posted by Bugsy (Post 2755849)
So the 22 corresponds to the 22nd hour of the current day?

yes

Bugsy 08-21-2021 20:31

Re: Get remain time problem
 
Try this

loiraolhosazul 08-21-2021 20:38

Re: Get remain time problem
 
Quote:

Originally Posted by Bugsy (Post 2755853)
Try this:
PHP Code:

public Test() 
{
    new 
iActionHour 22;
    
    new 
iYear iMonth iDay iHour iMinute iSecond;
    new 
iHours iMinutes iSeconds;

    
UnixToTimeget_systime() , iYear iMonth iDay iHour iMinute iSecond UT_TIMEZONE_SERVER );
    
    if ( 
iHour iActionHour )
    {
        
iHours = ( iActionHour iHour ) - 1
    }
    else
    {
        
iHours = ( iActionHour + ( 24 iActionHour ) ) - 1;
    }
    
    
iMinutes 60 iMinute;
    
iSeconds 60 iSecond;
    
    
server_print"%d hour%s, %d minute%s, %d second%s" iHours iHours == "" "s" iMinutes iMinutes == "" "s"iSeconds iSeconds == "" "s" );



worked, thank you! close

Bugsy 08-22-2021 00:23

Re: Get remain time problem
 
This needs more work, it will not always be accurate.

Bugsy 08-22-2021 12:23

Re: Get remain time problem
 
This seems to work consistently.

PHP Code:

public Test() 
{
    const 
iActionTime 22;
    
    new 
iHours iMinutes iSeconds szTime] , iUnixTSNow iUnixTSAction;
    
    
iUnixTSNow parse_timeszTime "%H:%M:%S" );
    
    
formatexszTime charsmaxszTime ) , "%d:%d:%d" iActionTime );
    
iUnixTSAction parse_timeszTime "%H:%M:%S" );
    
    
iUnixTSAction -= iUnixTSNow;
    
iHours = ( iUnixTSAction 3600 ) % 24;
    
iMinutes = ( iUnixTSAction 60 ) % 60;
    
iSeconds = ( iUnixTSAction 60 );
    
    
server_print"%d hour%s, %d minute%s, %d second%s" iHours iHours == "" "s" iMinutes iMinutes == "" "s"iSeconds iSeconds == "" "s" );




All times are GMT -4. The time now is 05:15.

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