AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   nVault Tutorial (https://forums.alliedmods.net/showthread.php?t=91503)

Supremache 09-09-2020 16:57

Re: nVault Tutorial
 
Quote:

Originally Posted by Bugsy (Post 2717215)
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

Bugsy 09-09-2020 19:13

Re: nVault Tutorial
 
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.

Supremache 09-10-2020 21:38

Re: nVault Tutorial
 
Quote:

Originally Posted by Bugsy (Post 2717321)
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 04-30-2022 22:18

Re: nVault Tutorial
 
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

Bugsy 04-30-2022 22:21

Re: nVault Tutorial
 
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.

Supremache 04-30-2022 22:30

Re: nVault Tutorial
 
Quote:

Originally Posted by Bugsy (Post 2778380)
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 :)

Bugsy 04-30-2022 22:34

Re: nVault Tutorial
 
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 


Supremache 04-30-2022 23:18

Re: nVault Tutorial
 
Quote:

Originally Posted by Bugsy (Post 2778383)
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;
       
}


Bugsy 04-30-2022 23:38

Re: nVault Tutorial
 
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;



Supremache 04-30-2022 23:49

Re: nVault Tutorial
 
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


All times are GMT -4. The time now is 18:17.

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