Thread: nVault Tutorial
View Single Post
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-30-2022 , 23:18   Re: nVault Tutorial
Reply With Quote #118

Quote:
Originally Posted by Bugsy View Post
PHP Code:
//plugin_cfg - Clear out everything that is in the vault up until current time
//This will eliminate all records that have expired
nvault_prunevault get_systime() );

//give playe something
nvault_setvault "STEAM:0:12345" "glock" );
//Set the timestamp to now + 1 day
nvault_touchvault "STEAM:0:12345" get_systime() + 86400 );

//player trying to do something
if ( nvault_lookupvault "STEAM:0:12345" szVal charsmaxszVal ) , iTS ) )
    
//item found
else
   
//item expired or never existed (doesnt exist in vault right now) 
You can instead not prune, and respond to the player accordingly based on the expired timestamp value returned by nvault_lookup().
PHP Code:
if ( iTS get_systime() )
   
//Sorry, this item has expired 
Check this code, I think it won't work because nothing checks the time of the item, I think it checks the time for all the item, right?

Code:
public plugin_cfg( )
{
	nvault_prune( g_iVault , 0 , get_systime() );
}

@SkinsMenu( id )
{
	new szData[ 64 ], szID[ 3 ], szVal[ 12 ], iTS, iMenu = menu_create( "\ySkins Menu:", "@SkinsHandler" );
	
	nvault_lookup( g_iVault, g_szSteamID[ id ], szVal , charsmax( szVal ) , iTS )
	
	for( new i; i < sizeof g_szSkinsData; i++ )
	{
		formatex( szData, charsmax( szData ), "%s%s \y%i", ( g_PlayerItems[ id ] & ITEMS( i ) && iTS >= get_systime( ) ) ? "\d" : "\w", g_szSkinsData[ i ][ Name ], g_szSkinsData[ i ][ Price ] )
		num_to_str( i, szID, charsmax( szID ) );
		menu_additem( iMenu, szData, szID );
	}

	menu_display( id, iMenu )
	return PLUGIN_HANDLED;
}

@SkinsHandler( id, iMenu, iItem )
{
	if( iItem != MENU_EXIT ) 
	{
		if( !is_user_alive( id ) )
		{
			client_print( id , print_chat , "You should be alive to buy this item" );
			goto @Destroy;
		}
		
		if( get_user_team( id ) != 2 )
		{
			client_print( id , print_chat , "You should be human to buy this item" );
			goto @Destroy;
		}
		
		static szData[ 10 ], iUnused, szPlayerItems[ 64 ], szVal[ 12 ], iTS;
		menu_item_getinfo( iMenu, iItem, iUnused, szData, charsmax(szData), .callback = iUnused )
		new iItemID = str_to_num( szData );
		
		nvault_lookup( g_iVault, g_szSteamID[ id ], szVal , charsmax( szVal ) , iTS )
		
		if( !( g_PlayerItems[ id ] & ITEMS( iItemID ) ) && iTS < get_systime( ) )
		{
			if( cs_get_user_money( id ) < g_szSkinsData[ iItemID  ][ Price ] )
			{
				goto @Destroy;
			}
			else
			{
				cs_set_user_money( id, cs_get_user_money( id ) - g_szSkinsData[ iItemID  ][ Price ] )
			}
		}
		
		if( g_szSkinsData[ iItemID ][ Skin ][ 0 ] != EOS )
		{
			cs_set_user_model( id, g_szSkinsData[ iItemID ][ Skin ] )
		}
		
		client_print( id , print_chat , "You were given skin ID %d", iItemID + 1 );
		g_PlayerItems[ id ] |= ITEMS( iItemID );
		formatex( szPlayerItems, charsmax( szPlayerItems ), "%i %i", g_PlayerItems[ id ], g_WeaponItems[ id ] )
		nvault_set( g_iVault, g_szSteamID[ id ], szPlayerItems );
		nvault_touch( g_iVault , g_szSteamID[ id ] , get_systime() + 3600 ); // 1 hour
	}
	@Destroy:
	menu_destroy( iMenu );
	return PLUGIN_HANDLED;
	
}


@WeaponMenu( id )
{
	new szData[ 64 ], szID[ 3 ], szVal[ 12 ], iTS, iMenu = menu_create( "\yWeapon Menu:", "@WeaponHandler" );
	
	nvault_lookup( g_iVault, g_szSteamID[ id ], szVal , charsmax( szVal ) , iTS )
	

	for( new i; i < sizeof g_szSkinsWeapon; i++ )
	{
		formatex( szData, charsmax( szData ), "%s%s \y%i", ( g_WeaponItems[ id ] & ITEMS( i ) && iTS >= get_systime( ) ) ? "\d" : "\w", g_szSkinsWeapon[ i ][ Weapon_Name ], g_szSkinsWeapon[ i ][ Weapon_Price ] )
		num_to_str( i, szID, charsmax( szID ) );
		menu_additem( iMenu, szData, szID );
	}
	menu_display( id, iMenu )
	return PLUGIN_HANDLED;
}

@WeaponHandler( id, iMenu, iItem )
{
	if( iItem != MENU_EXIT ) 
	{
		if( !is_user_alive( id ) )
		{
			client_print( id , print_chat , "You should be alive to buy this item" );
			goto @Destroy;
		}
		
		if( get_user_team( id ) != 2 )
		{
			client_print( id , print_chat , "You should be human to buy this item" );
			goto @Destroy;
		}
		
		static szData[ 10 ], iUnused, szPlayerItems[ 64 ], szVal[ 12 ], iTS;
		menu_item_getinfo( iMenu, iItem, iUnused, szData, charsmax(szData), .callback = iUnused )
		new iItemID = str_to_num( szData );
		
		nvault_lookup( g_iVault, g_szSteamID[ id ], szVal , charsmax( szVal ) , iTS )
		
		if( !( g_WeaponItems[ id ] & ITEMS( iItemID ) ) && iTS < get_systime( ) )
		{
			if( cs_get_user_money( id ) < g_szSkinsWeapon[ iItemID ][ Weapon_Price ] )
			{
				goto @Destroy;
			}
			else
			{
				cs_set_user_money( id, cs_get_user_money( id ) - g_szSkinsWeapon[ iItemID ][ Weapon_Price ] )
			}
		}
		
		if( get_user_weapon(id) == g_szSkinsWeapon[ iItemID ][ WeaponID ] )
		{
			g_iItems[ id ] = iItemID;
			RefreshWeaponModel( id );
		}

		client_print( id , print_chat , "You were given skin ID %d", iItemID + 1 );
		g_WeaponItems[ id ] |= ITEMS( iItemID );
		formatex( szPlayerItems, charsmax( szPlayerItems ), "%i %i", g_PlayerItems[ id ], g_WeaponItems[ id ] )
		nvault_set( g_iVault, g_szSteamID[ id ], szPlayerItems );
		nvault_touch( g_iVault , g_szSteamID[ id ] , get_systime() + 3600 ); // 1 hour
	}
	@Destroy:
	menu_destroy( iMenu );
	return PLUGIN_HANDLED;
	
}
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 04-30-2022 at 23:51.
Supremache is offline