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

How To Do command After X Hours


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Taha_rajper
Member
Join Date: Jun 2021
Location: Under The Sea
Old 08-04-2022 , 05:39   How To Do command After X Hours
Reply With Quote #1

Hello, I want A Code That Can Make A Plugin For Example /gift So Everyone Can Use It After X Hours (example 6 Hours) How To do it
Taha_rajper is offline
Alahmoh
Member
Join Date: Jun 2018
Old 08-09-2022 , 15:14   Re: How To Do command After X Hours
Reply With Quote #2

Quote:
Originally Posted by Taha_rajper View Post
Hello, I want A Code That Can Make A Plugin For Example /gift So Everyone Can Use It After X Hours (example 6 Hours) How To do it
its is originally for my own mod but since you asked i modified a bit to work as you want, give it a try.

Code:
#include < amxmodx >
#include < nvault >

new const szNvaultName[ ] = "Get_Gifts";
new g_iMessageChat;
new g_iMaxPlayers;

new g_szSteamID[ 33 ][ 32 ];
new g_iPlayerTime[ 33 ];
new bool: g_bPlayerLoaded[ 33 ];

public plugin_init( ) {
	register_plugin( "Get Gifts", "0.1", "alahmoh" );
	
	g_iMessageChat = get_user_msgid( "SayText" );
	g_iMaxPlayers = get_maxplayers( );
	
	register_clcmd( "say /gift", "fw_CmdGet" );
	register_clcmd( "say_team /gift", "fw_CmdGet" );
	
	register_dictionary( "Get_Gifts.txt" );
}

public fw_CmdGet( iPlayer ) { 
	new iVault = nvault_open( szNvaultName ); 
	
	if( iVault == INVALID_HANDLE ) {
		Chat_Print( iPlayer, "!g[Gifts] !n%L", iPlayer, "ML_FARAL_NVAULT_ERROR" ) 
		return; 
	} 
		
	new szTextTime[ 64 ]; 
	new iMinutes = 1440; // change here to the amount of hours need to pass before trying /gift again.
	
	BuildTime( iPlayer, iMinutes, szTextTime, charsmax( szTextTime ) ); 
	
	if( g_bPlayerLoaded[ iPlayer ] ) { 
				Chat_Print( iPlayer, "!g[Gifts] !n%L", iPlayer, "ML_YOUR_JUST_RECIEVED", szTextTime );
				
				// give gift here
				
				g_bPlayerLoaded[ iPlayer ] = false;
				nvault_touch( iVault, g_szSteamID[ iPlayer ], g_iPlayerTime[ iPlayer ] = get_systime( ) ); 
				return; 		
		
	}
	
	new iPlayerTime = get_systime( ) - g_iPlayerTime[ iPlayer ]; 
	new iMinutesDifference = ( iPlayerTime < ( iMinutes * 60 ) ) ? iMinutes - ( iPlayerTime / 60 ) : iMinutes; 
	BuildTime( iPlayer, iMinutesDifference, szTextTime, charsmax( szTextTime ) ); 
	
	if( iPlayerTime >= ( iMinutes * 60 ) ) { 
				Chat_Print( iPlayer, "!g[Gifts] !n%L", iPlayer, "ML_YOUR_RECIEVED_AGAIN", szTextTime );
				
				// give gift here
				
				g_bPlayerLoaded[ iPlayer ] = false;
				nvault_touch( iVault, g_szSteamID[ iPlayer ], g_iPlayerTime[ iPlayer ] = get_systime( ) ); 
				return; 
	}
	else Chat_Print( iPlayer, "!g[Gifts] !n%L", iPlayer, "ML_TRY_AGAIN", szTextTime );
	
	nvault_close( iVault ); 
} 

public client_authorized( iPlayer ) {
	new iNvault, szData[ 32 ]; 
	get_user_authid( iPlayer, g_szSteamID[ iPlayer ], charsmax( g_szSteamID[ ] ) );
	
	g_iPlayerTime[ iPlayer ] = get_systime( ); 
	g_bPlayerLoaded[ iPlayer ] = false;
	formatex( szData, charsmax( szData ), "%d", g_iPlayerTime[ iPlayer ] ); 
	
	if( ( iNvault = nvault_open( szNvaultName ) ) == INVALID_HANDLE ) 
		return; 
	
	if( !nvault_lookup( iNvault, g_szSteamID[ iPlayer ], szData, charsmax( szData ), g_iPlayerTime[ iPlayer ] ) ) { 
		nvault_set( iNvault, g_szSteamID[ iPlayer ], szData ); 
		g_bPlayerLoaded[ iPlayer ] = true; 
	}
	
	nvault_close( iNvault ); 
}

stock Chat_Print( iPlayer, const szInput[ ], any:... ) {
	static szMessage[ 191 ];
	vformat( szMessage, charsmax( szMessage ), szInput, 3 );
	replace_all( szMessage, charsmax( szMessage ), "!g", "^4" );
	replace_all( szMessage, charsmax( szMessage ), "!t", "^3" );
	replace_all( szMessage, charsmax( szMessage ), "!n", "^1" );
     
	if( !iPlayer ) {
		for( new iTarget = 1; iTarget <= g_iMaxPlayers; iTarget ++ ) {
			if( !is_user_connected( iTarget ) || is_user_bot( iTarget ) )
				continue;
		
			message_begin( MSG_ONE_UNRELIABLE, g_iMessageChat, _, iTarget );
			write_byte( iTarget );
			write_string( szMessage );
			message_end( );
		}
	} else {
		if( !is_user_connected( iPlayer ) || is_user_bot( iPlayer ) )
			return;
		
		message_begin( MSG_ONE_UNRELIABLE, g_iMessageChat, _, iPlayer );
		write_byte( iPlayer );
		write_string( szMessage );
		message_end( );
	}
}

stock BuildTime( iPlayer, iMinutes, szData[ ], iLen ) {
	new szText[ 128 ];
	
	if( iMinutes == 1 )
		formatex( szText, charsmax( szText ), "1 %L", iPlayer, "ML_MINUTE" );
	else if( iMinutes != 1 && ( iMinutes < 60 ) )
		formatex( szText, charsmax( szText ), "%d %L", iMinutes, iPlayer, "ML_MINUTES" );
	else if( iMinutes == 60 )
		formatex( szText, charsmax( szText ), "1 %L", iPlayer, "ML_HOUR" );
	else {
		new iTime = iMinutes / 60;
		if( ( iTime * 60 ) == iMinutes )
			formatex( szText, charsmax( szText ), "%d %L", iTime, iPlayer, iTime == 1 ? "ML_HOUR" : "ML_HOURS" );
		else {
			new iDifference = iMinutes - iTime * 60;
			formatex( szText, charsmax( szText ), "%d %L %L %d %L", iTime, iPlayer, "ML_HOURS", iPlayer, "ML_AND", iDifference, iPlayer, "ML_MINUTES" );
		}
	}
	
	copy( szData, iLen, szText );
}

Last edited by Alahmoh; 08-09-2022 at 15:15.
Alahmoh 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 05:37.


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