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

Solved need help to calculate remaining time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-13-2023 , 09:48   need help to calculate remaining time
Reply With Quote #1

here is where i need help:

Code:
public playerMenuHanler( client, menu, item )
{
	/*	
	if( item < 0 )  
	{
		menu_cancel( client );
		show_menu( client, 0, "^n", 1 );
		
		return 1;
	}
	*/
	
	new szCmd[ 3 ], iAccess, iCallback;
	
	menu_item_getinfo( menu, item, iAccess, szCmd, charsmax( szCmd ), _,_, iCallback );
	
	new szData[ MAX_LENGTH ], szArrayData[ 4 ][ MAX_LENGTH ];
	
	ArrayGetString( g_aBannedList, str_to_num( szCmd ), szData, charsmax( szData ) );
	
	parse( szData, szArrayData[ 0 ], charsmax( szArrayData[] ), szArrayData[ 1 ], charsmax( szArrayData[] ), szArrayData[ 2 ], charsmax( szArrayData[] ), szArrayData[ 3 ], charsmax( szArrayData[] ) );
	
	new szMenu[ MAX_LENGTH ];
	
	new iBanTime = str_to_num( szArrayData[ 1 ] );
	new iTimeStamp = str_to_num( szArrayData[ 2 ] );
	new actualTime = (iTimeStamp - iBanTime);
	
	new iHours, iMinutes, iSeconds;
	GetRemainingTime(  actualTime, iHours, iMinutes, iSeconds );
	
	new victim = find_player( "ch", szArrayData[0] );
	
	if( !strcmp( szArrayData[ 1 ], "PERM" ) )
		formatex( szMenu, charsmax( szMenu ), "\wPlayer Name: \y%s \r|| \wPlayer SteamID: \y%s^n\wBan Duration: \yPERMANENTLY \r|| \wPlayer Status: \y%s\r", szArrayData[3], szArrayData[0], is_user_connected( victim ) ? "ONLINE" : "OFFLINE" );
	else
		formatex( szMenu, charsmax( szMenu ), "\wPlayer Name: \y%s \r|| \wPlayer SteamID: \y%s^n\wBan Duration: \y%d \whours \y%d \wminutes \y%d \wseconds^n\wPlayer Status: \y%s\r", szArrayData[3], szArrayData[0], iHours, iMinutes, iSeconds, is_user_connected( victim ) ? "ONLINE" : "OFFLINE" );
	
	new subMenu = menu_create( szMenu, "subBanned" );
	
	menu_additem( subMenu, "\yUnban Player\r" );
	menu_additem( subMenu, "\yChoose Other Player\r" );
	menu_setprop( subMenu, MPROP_EXIT, MEXIT_NEVER );
	
	menu_display( client, subMenu ); 
	
	return 1;
}
i have to calculate the remaining time but i have no idea how to calculate it properly, i forgot everything about amxx coding.. please help me to calculate remaining time.

__________________

Last edited by xDrugz; 11-13-2023 at 12:03.
xDrugz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-13-2023 , 11:09   Re: need help to calculate remaining time
Reply With Quote #2

It depends on how the data is stored. If you store the expiration time (the most efficient way to go about it) then you simply subtract the expiration timestamp from the current timestamp (get_systime()). If you store the timestamp when the ban started then you simply need to add the ban length to that timestamp to get the expiration timestamp and then do the same as sated previously.

E.g.

Code:
ExpirationTimestamp = BanStartTimestamp + BanLength
SecondRemainig = ExpirationTimestamp - get_systime()
__________________

Last edited by fysiks; 11-13-2023 at 11:11.
fysiks is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-13-2023 , 11:28   Re: need help to calculate remaining time
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
It depends on how the data is stored. If you store the expiration time (the most efficient way to go about it) then you simply subtract the expiration timestamp from the current timestamp (get_systime()). If you store the timestamp when the ban started then you simply need to add the ban length to that timestamp to get the expiration timestamp and then do the same as sated previously.

E.g.

Code:
ExpirationTimestamp = BanStartTimestamp + BanLength
SecondRemainig = ExpirationTimestamp - get_systime()
tried your way but menu shows 2 hours instead of decreasing the time

Code:
public playerMenuHanler( client, menu, item )
{
	/*	
	if( item < 0 )  
	{
		menu_cancel( client );
		show_menu( client, 0, "^n", 1 );
		
		return 1;
	}
	*/
	
	new szCmd[ 3 ], iAccess, iCallback;
	
	menu_item_getinfo( menu, item, iAccess, szCmd, charsmax( szCmd ), _,_, iCallback );
	
	new szData[ MAX_LENGTH ], szArrayData[ 4 ][ MAX_LENGTH ];
	
	ArrayGetString( g_aBannedList, str_to_num( szCmd ), szData, charsmax( szData ) );
	
	parse( szData, szArrayData[ 0 ], charsmax( szArrayData[] ), szArrayData[ 1 ], charsmax( szArrayData[] ), szArrayData[ 2 ], charsmax( szArrayData[] ), szArrayData[ 3 ], charsmax( szArrayData[] ) );
	
	new szMenu[ MAX_LENGTH ];
	
	new ExpirationTimestamp = ( str_to_num( szArrayData[ 2 ] ) + str_to_num( szArrayData[ 1 ] ) );
	
	client_print( client, print_chat, "%d", ExpirationTimestamp );
	
	new SecondRemaining = ( get_systime() - ExpirationTimestamp );
	
	client_print( client, print_chat, "%d", SecondRemaining );
	
	new iHours, iMinutes, iSeconds;
	GetRemainingTime( SecondRemaining, iHours, iMinutes, iSeconds );
	
	new victim = find_player( "ch", szArrayData[0] );
	
	if( !strcmp( szArrayData[ 1 ], "PERM" ) )
		formatex( szMenu, charsmax( szMenu ), "\wPlayer Name: \y%s \r|| \wPlayer SteamID: \y%s^n\wBan Duration: \yPERMANENTLY \r|| \wPlayer Status: \y%s\r", szArrayData[3], szArrayData[0], is_user_connected( victim ) ? "ONLINE" : "OFFLINE" );
	else
		formatex( szMenu, charsmax( szMenu ), "\wPlayer Name: \y%s \r|| \wPlayer SteamID: \y%s^n\wBan Duration: \y%d \whours \y%d \wminutes \y%d \wseconds^n\wPlayer Status: \y%s\r", szArrayData[3], szArrayData[0], iHours, iMinutes, iSeconds, is_user_connected( victim ) ? "ONLINE" : "OFFLINE" );
	
	new subMenu = menu_create( szMenu, "subBanned" );
	
	menu_additem( subMenu, "\yUnban Player\r" );
	menu_additem( subMenu, "\yChoose Other Player\r" );
	menu_setprop( subMenu, MPROP_EXIT, MEXIT_NEVER );
	
	menu_display( client, subMenu ); 
	
	return 1;
}
here how data is stored
Code:
"STEAM_0:0:300995351" "3600" "1699879112" "TEST NAME"
"STEAM_0:0:300995352" "PERM" "1699879112" "TEST NAME2"
"STEAM_0:0:300995353" "PERM" "1699879112" "TEST NAME3"
"STEAM_0:0:300995354" "PERM" "1699879112" "TEST NAME4"
__________________

Last edited by xDrugz; 11-13-2023 at 11:30.
xDrugz is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-13-2023 , 12:04   Re: need help to calculate remaining time
Reply With Quote #4

problem solved, thanks to fysiks
__________________

Last edited by xDrugz; 11-13-2023 at 12:04.
xDrugz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-13-2023 , 23:41   Re: need help to calculate remaining time
Reply With Quote #5

What did you do to solve the issue? I see issues with your code that you posted. "get_systime() - ExpirationTimestamp" will give a negative number if the player is still banned.
__________________
fysiks is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-14-2023 , 08:58   Re: need help to calculate remaining time
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
What did you do to solve the issue? I see issues with your code that you posted. "get_systime() - ExpirationTimestamp" will give a negative number if the player is still banned.
Code:
new iBanTime = str_to_num( szArrayData[ 1 ] );
new iPassedTime = ( get_systime() - str_to_num( szArrayData[ 2 ] ) );
new iRemainingTime = ( iBanTime - iPassedTime );
__________________
xDrugz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-14-2023 , 22:36   Re: need help to calculate remaining time
Reply With Quote #7

Ah ok, that's exactly the same as what I wrote above.

Code:
BanStartTimestamp = str_to_num(szArrayData[2])
iRemainingTime = (iBanTime + BanStartTimestamp) - get_systime()
where

Code:
ExpirationTimestamp = (iBanTime + BanStartTimestamp)
__________________

Last edited by fysiks; 11-14-2023 at 22:38.
fysiks is offline
Reply



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 13:04.


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