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

nVault Tutorial


Post New Thread Reply   
 
Thread Tools Display Modes
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-09-2020 , 16:57   Re: nVault Tutorial
Reply With Quote #111

Quote:
Originally Posted by Bugsy View Post
Your savedata and loaddata look good, though you can just do: iMoney[id] = nvault_get(iVault, szAuth )
So what i want to do it this ?
PHP Code:

new szAuth[MAX_PLAYERS+1][35// Set userid in global var

public ResetBank(id)
{
    if (!
is_user_connected(id))
        return 
PLUGIN_HANDLED;

    if (
access(idFLAGS_RESET_BANK))
    {
        
iMoney[id] = nvault_get(iVaultszAuth[id] )
            
nvault_remove(iVaultszAuth[id]);
   
        
get_user_nameidszAdminNamecharsmax(szAdminName))
        
get_user_authid(idszPlayerIDcharsmax(szPlayerID));
        
        
console_print(id"[ADMIN] %s Reset Bank"szAdminName)
        
Log("[RESETMONEY] Admin: %s || SteamID: %s Reset Bank"szAdminNameszPlayerID)
        
        
ChatColor(0"^x01[ADMIN]^x04 %s^x01: Reset bank."szAdminName)
        
        return 
PLUGIN_HANDLED
        
    
}
    return 
PLUGIN_HANDLED    
    

I will try another idea

Last edited by Supremache; 09-09-2020 at 17:29.
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-09-2020 , 19:13   Re: nVault Tutorial
Reply With Quote #112

1. The player cannot execute the command if he is not connected, remove the is_user_connected() check.
2. Ensure this player has teh flags..or remove the if(access()) check.
3. Why are you assigning the value to iMoney[] before deleting the nvault record? i thought the intend was to clear the bank which IMO should include setting the variable to 0.
4. You do not need to call get_user_authid() again, just use the value in szAuth[id] in your log to get the steamid.
5. Are you setting steam id into szAuth[id] at client_authorized()?

I'm tapping out after this. You need to put time in to learn and debug on your own.
__________________
Bugsy is online now
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-10-2020 , 21:38   Re: nVault Tutorial
Reply With Quote #113

Quote:
Originally Posted by Bugsy View Post
1. The player cannot execute the command if he is not connected, remove the is_user_connected() check.
2. Ensure this player has teh flags..or remove the if(access()) check.
3. Why are you assigning the value to iMoney[] before deleting the nvault record? i thought the intend was to clear the bank which IMO should include setting the variable to 0.
4. You do not need to call get_user_authid() again, just use the value in szAuth[id] in your log to get the steamid.
5. Are you setting steam id into szAuth[id] at client_authorized()?

I'm tapping out after this. You need to put time in to learn and debug on your own.
Okay thanks for your time, i will learn it
Supremache is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-30-2022 , 22:18   Re: nVault Tutorial
Reply With Quote #114

Hi Bugsy,
I have a question I'm trying to create a shop to buy the items on time for X hours and saves it to nvault But if the player does not choose the purchased item the time will not run out and i already did it but i think the code wierd or complicated.

Is there a simple way that can be used by nvault, because I tried to use nvault_touch but I can't control it to remove the item once the time is up while I choose it
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-30-2022 , 22:21   Re: nVault Tutorial
Reply With Quote #115

Set the timestamp of the item to a future date when you want it to expire using nvault_touch(). On plugin_cfg(), call nvault_prune( vault , 0 , get_systime() ). When a player attempts to use an item, if the key is not in the vault, its expired.
__________________
Bugsy is online now
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-30-2022 , 22:30   Re: nVault Tutorial
Reply With Quote #116

Quote:
Originally Posted by Bugsy View Post
Set the timestamp of the item to a future date when you want it to expire using nvault_touch(). On plugin_cfg(), call nvault_prune( vault , 0 , get_systime() ). When a player attempts to use an item, if the key is not in the vault, its expired.
Sorry but I don't understand, can you give a quick example
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-30-2022 , 22:34   Re: nVault Tutorial
Reply With Quote #117

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 
__________________

Last edited by Bugsy; 04-30-2022 at 22:53.
Bugsy is online now
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
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-30-2022 , 23:38   Re: nVault Tutorial
Reply With Quote #119

If the intent is to show the menu only if the vault record exists, you'd do:
PHP Code:
@SkinsMenuid )
{
    new 
szData64 ], szID], szVal12 ], iTSiMenu;
        
    if ( 
nvault_lookupg_iVaultg_szSteamIDid ], szVal charsmaxszVal ) , iTS ) )
    {
        
iMenu menu_create"\ySkins Menu:""@SkinsHandler" );
        for( new 
isizeof g_szSkinsDatai++ )
        {
            
formatexszDatacharsmaxszData ), "%s%s \y%i", ( g_PlayerItemsid ] & ITEMS) && iTS >= get_systime( ) ) ? "\d" "\w"g_szSkinsData][ Name ], g_szSkinsData][ Price ] )
            
num_to_striszIDcharsmaxszID ) );
            
menu_additemiMenuszDataszID );
        }
    
        
menu_displayidiMenu )
    }
    return 
PLUGIN_HANDLED;

__________________
Bugsy is online now
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-30-2022 , 23:49   Re: nVault Tutorial
Reply With Quote #120

No, as you see, I want to check if the player has this item and the item time has not expired, it will be marked as a dark color and will not check the price of the item

Code:
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 ] )

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 ] )
			}
		}
P.s: I want to check the time for each item
__________________
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:57.
Supremache 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 06:24.


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