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-08-2020 , 19:10   Re: nVault Tutorial
Reply With Quote #101

Quote:
Originally Posted by uvprint View Post
good job
How to reset date ??

I did it but not worked

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

    if (
access(idFLAGS_RESET_BANK))
    {
        
get_user_nameidszAdminNamecharsmax(szAdminName))
        
get_user_authididszAdminAuthidcharsmax(szAdminAuthid))

        
//Remove the entry that was just saved
        
nvault_remove(iVaultiMoney[id]); 
        
        
console_print(id"[ADMIN] %s Reset Bank"szAdminName)
        
Log("[RESETMONEY] Admin: %s || SteamID: %s Reset Bank"szAdminNameszAdminAuthid)
        
        
ChatColor(0"^x01[ADMIN]^x04 %s^x01: Reset bank."szAdminName)
        
        return 
PLUGIN_HANDLED
        
    
}
    return 
PLUGIN_HANDLED    
    

Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2020 , 19:23   Re: nVault Tutorial
Reply With Quote #102

It looks like you are trying to remove a record by it's value, which, based on the variable name, will likely not be unique. You should store data using steam id as key and then pass that to nvault_remove.
__________________
Bugsy is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-08-2020 , 20:10   Re: nVault Tutorial
Reply With Quote #103

Quote:
Originally Posted by Bugsy View Post
It looks like you are trying to remove a record by it's value, which, based on the variable name, will likely not be unique. You should store data using steam id as key and then pass that to nvault_remove.
Like This ?

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

    if (
access(idFLAGS_RESET_BANK))
    {
        
        new 
szAuth[35], szTemp[10];
        
get_user_nameidszAdminNamecharsmax(szAdminName))
        
get_user_authid(idszAuthcharsmax(szAuth));
        
        
formatex(szTempcharsmax(szTemp), "%i"iMoney[id]);
        
        
nvault_remove(iVaultszAuthszTemp);
        
        
console_print(id"[ADMIN] %s Reset Bank"szAdminName)
        
Log("[RESETMONEY] Admin: %s || SteamID: %s Reset Bank"szAdminNameszAuth)
        
        
ChatColor(0"^x01[ADMIN]^x04 %s^x01: Reset bank."szAdminName)
        
        return 
PLUGIN_HANDLED
        
    
}
    return 
PLUGIN_HANDLED    
    


Last edited by Supremache; 09-08-2020 at 20:21.
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2020 , 20:20   Re: nVault Tutorial
Reply With Quote #104

Think about it logically.

1. Read this tutorial again
2. Read how nvault_remove() works, specifically what you pass to it.

http://www.amxmodx.org/api/nvault/nvault_remove
Code:
public ResetBank(id) {     if (!is_user_connected(id))         return PLUGIN_HANDLED;     if (access(id, FLAGS_RESET_BANK))     {
        //Why are you retrieving the name when it is never used?
        get_user_name( id, szAdminName, charsmax(szAdminName))         get_user_authid( id, szAdminAuthid, charsmax(szAdminAuthid))                 new szAuth[35], szTemp[10];         get_user_authid(id, szAuth, charsmax(szAuth));    
        //Why are you formatting the money value into szTemp? nVault stores data using a KEY and you need only this to remove a vault record.
        formatex(szTemp, charsmax(szTemp), "%i", iMoney[id]);        
        //No, nvault remove works by specifying the vault iD (iVault) and the key for the data to be removed (szAuth)      
        //You basically used nvault_remove() as you would to SET data in the vault with nvault_set().
        nvault_remove(iVault, szAuth, szTemp);                 console_print(id, "[ADMIN] %s Reset Bank", szAdminName)         Log("[RESETMONEY] Admin: %s || SteamID: %s Reset Bank", szAdminName, szAdminAuthid)                 ChatColor(0, "^x01[ADMIN]^x04 %s^x01: Reset bank.", szAdminName)                 return PLUGIN_HANDLED             }     return PLUGIN_HANDLED        }
__________________
Bugsy is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-08-2020 , 20:42   Re: nVault Tutorial
Reply With Quote #105

Quote:
Originally Posted by Bugsy View Post
Think about it logically.

1. Read this tutorial again
2. Read how nvault_remove() works, specifically what you pass to it.

http://www.amxmodx.org/api/nvault/nvault_remove
Code:
public ResetBank(id) {     if (!is_user_connected(id))         return PLUGIN_HANDLED;     if (access(id, FLAGS_RESET_BANK))     {
        //Why are you retrieving the name when it is never used?
        get_user_name( id, szAdminName, charsmax(szAdminName))         get_user_authid( id, szAdminAuthid, charsmax(szAdminAuthid))                 new szAuth[35], szTemp[10];         get_user_authid(id, szAuth, charsmax(szAuth));    
        //Why are you formatting the money value into szTemp? nVault stores data using a KEY and you need only this to remove a vault record.
        formatex(szTemp, charsmax(szTemp), "%i", iMoney[id]);        
        //No, nvault remove works by specifying the vault iD (iVault) and the key for the data to be removed (szAuth)      
        //You basically used nvault_remove() as you would to SET data in the vault with nvault_set().
        nvault_remove(iVault, szAuth, szTemp);                 console_print(id, "[ADMIN] %s Reset Bank", szAdminName)         Log("[RESETMONEY] Admin: %s || SteamID: %s Reset Bank", szAdminName, szAdminAuthid)                 ChatColor(0, "^x01[ADMIN]^x04 %s^x01: Reset bank.", szAdminName)                 return PLUGIN_HANDLED             }     return PLUGIN_HANDLED        }
I read it again is this correct ?? if it's not then please give me an example

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

    if (
access(idFLAGS_RESET_BANK))
    {
        new 
szData[8];
        new 
szKey[40];

        
get_user_nameidszAdminNamecharsmax(szAdminName))
        
get_user_authid(idszPlayerIDcharsmax(szPlayerID));
        
        
formatexszKey charsmaxszKey ) , "%s"szPlayerID[id] );
        
formatexszKey charsmaxszKey ) , "%i"iMoney[id] );
        
        
nvault_removeiVault szKey szData );
        
        
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    
    

Edit: I did it but not worked too
PHP Code:
public ResetBank(id)
{
    if (!
is_user_connected(id))
        return 
PLUGIN_HANDLED;

    if (
access(idFLAGS_RESET_BANK))
    {
        new 
szPlayer[32]
        
read_argv(1szPlayercharsmax(szPlayer))
            
        new 
iPlayer find_player("a"szPlayer)
            
        if(
iPlayer)
        {
                
iMoney[iPlayer] = 0;
        }
        new 
szData[32], iTimestamp
            
        
if(nvault_lookup(iVaultszPlayerszDatacharsmax(szData), iTimestamp))
                
nvault_remove(iVaultszPlayer)
            
            
        
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    
    


Last edited by Supremache; 09-08-2020 at 20:52.
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2020 , 21:11   Re: nVault Tutorial
Reply With Quote #106

This is probably the simplest nvault transaction, I'm not sure what you do not understand. This is as simple as I can get it.

PHP Code:

#include <amxmodx>
#include <nvault>

#define MAX_PLAYERS 32

new g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
g_Vault;

public 
plugin_init() 
{
    
g_Vault nvault_open"test" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    
//Get users steam id
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
    
//Store something using this steam id as the key
    
nvault_setg_Vault g_szAuthIDid ] , "asdasjhdaskjdh" );
}

public 
client_disconnectid )
{
    
//Delete value stored at client_authorized() using his steam id. Note, we do not need to know the value to delete it, just the key it was stored under.
    
nvault_removeg_Vault g_szAuthIDid ] );

__________________
Bugsy is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-08-2020 , 21:38   Re: nVault Tutorial
Reply With Quote #107

Quote:
Originally Posted by Bugsy View Post
This is probably the simplest nvault transaction, I'm not sure what you do not understand. This is as simple as I can get it.

PHP Code:

#include <amxmodx>
#include <nvault>

#define MAX_PLAYERS 32

new g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
g_Vault;

public 
plugin_init() 
{
    
g_Vault nvault_open"test" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    
//Get users steam id
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
    
//Store something using this steam id as the key
    
nvault_setg_Vault g_szAuthIDid ] , "asdasjhdaskjdh" );
}

public 
client_disconnectid )
{
    
//Delete value stored at client_authorized() using his steam id. Note, we do not need to know the value to delete it, just the key it was stored under.
    
nvault_removeg_Vault g_szAuthIDid ] );

I did it, but it didn't get reset, This is tiring
Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2020 , 21:40   Re: nVault Tutorial
Reply With Quote #108

What do you mean "it didnt get reset"? I think you need to learn more of the basic stuff before jumping in to this if you are having problems.

Based on this code I can tell you are not understanding the basic fundamentals. To make this work, you should be reading the steam id into szPlayer. You should NEVER store data by a players name...or anything other than steam id since this is guaranteed unique to a single player.
PHP Code:
        new szPlayer[32]
        
read_argv(1szPlayercharsmax(szPlayer))
            
        new 
iPlayer find_player("a"szPlayer)
            
        if(
iPlayer)
        {
                
iMoney[iPlayer] = 0;
        }
        new 
szData[32], iTimestamp
            
        
if(nvault_lookup(iVaultszPlayerszDatacharsmax(szData), iTimestamp))
                
nvault_remove(iVaultszPlayer
__________________

Last edited by Bugsy; 09-08-2020 at 21:41.
Bugsy is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-08-2020 , 21:57   Re: nVault Tutorial
Reply With Quote #109

Quote:
Originally Posted by Bugsy View Post
What do you mean "it didnt get reset"? I think you need to learn more of the basic stuff before jumping in to this if you are having problems.

Based on this code I can tell you are not understanding the basic fundamentals. To make this work, you should be reading the steam id into szPlayer. You should NEVER store data by a players name...or anything other than steam id since this is guaranteed unique to a single player.
PHP Code:
        new szPlayer[32]
        
read_argv(1szPlayercharsmax(szPlayer))
            
        new 
iPlayer find_player("a"szPlayer)
            
        if(
iPlayer)
        {
                
iMoney[iPlayer] = 0;
        }
        new 
szData[32], iTimestamp
            
        
if(nvault_lookup(iVaultszPlayerszDatacharsmax(szData), iTimestamp))
                
nvault_remove(iVaultszPlayer
1. I mean the money on the bank didn't got reset
2. I already using steam id on save/load data and I did similar codes as you did exampling but it's never worked

PHP Code:
public SaveData(id) {
    new 
szAuth[35], szTemp[10];
    
get_user_authid(idszAuthcharsmax(szAuth));

    
formatex(szTempcharsmax(szTemp), "%i"iMoney[id]);

    
nvault_set(iVaultszAuthszTemp);
}

public 
LoadData(id) {
    new 
szAuth[35], szMoney[10], szTemp[10];
    
get_user_authid(idszAuthcharsmax(szAuth));

    
nvault_get(iVaultszAuthszTempcharsmax(szTemp));

    
parse(szTempszMoneycharsmax(szMoney));

    
iMoney[id] = str_to_num(szMoney);

Supremache is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-08-2020 , 22:06   Re: nVault Tutorial
Reply With Quote #110

Your savedata and loaddata look good, though you can just do: iMoney[id] = nvault_get(iVault, szAuth )
__________________
Bugsy 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 21:03.


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