Raised This Month: $10 Target: $400
 2% 

Solved Get remain time problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
loiraolhosazul
Member
Join Date: May 2020
Old 08-21-2021 , 20:28   Get remain time problem
Reply With Quote #1

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)
}

Last edited by loiraolhosazul; 08-21-2021 at 21:38.
loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 20:58   Re: Get remain time problem
Reply With Quote #2

Give an example of input and output.

Based on your request, you only want the number of minutes remaining in the current hour?
__________________
Bugsy is offline
loiraolhosazul
Member
Join Date: May 2020
Old 08-21-2021 , 21:00   Re: Get remain time problem
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
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
loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 21:01   Re: Get remain time problem
Reply With Quote #4

Is this 22 event stored via unix timestamp? What is the initial value/format I am working with to get remaining time?
__________________
Bugsy is offline
loiraolhosazul
Member
Join Date: May 2020
Old 08-21-2021 , 21:02   Re: Get remain time problem
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
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'
loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 21:03   Re: Get remain time problem
Reply With Quote #6

So the 22 corresponds to the 22nd hour of the current day?
__________________
Bugsy is offline
loiraolhosazul
Member
Join Date: May 2020
Old 08-21-2021 , 21:04   Re: Get remain time problem
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
So the 22 corresponds to the 22nd hour of the current day?
yes
loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-21-2021 , 21:31   Re: Get remain time problem
Reply With Quote #8

Try this
__________________

Last edited by Bugsy; 08-22-2021 at 13:38.
Bugsy is offline
loiraolhosazul
Member
Join Date: May 2020
Old 08-21-2021 , 21:38   Re: Get remain time problem
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
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
loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-22-2021 , 01:23   Re: Get remain time problem
Reply With Quote #10

This needs more work, it will not always be accurate.
__________________

Last edited by Bugsy; 08-22-2021 at 02:22.
Bugsy 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 01:45.


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