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-08-2020 19:10

Re: nVault Tutorial
 
Quote:

Originally Posted by uvprint (Post 2685715)
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    
    



Bugsy 09-08-2020 19:23

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

Supremache 09-08-2020 20:10

Re: nVault Tutorial
 
Quote:

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



Bugsy 09-08-2020 20:20

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

Supremache 09-08-2020 20:42

Re: nVault Tutorial
 
Quote:

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



Bugsy 09-08-2020 21:11

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



Supremache 09-08-2020 21:38

Re: nVault Tutorial
 
Quote:

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

Bugsy 09-08-2020 21:40

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


Supremache 09-08-2020 21:57

Re: nVault Tutorial
 
Quote:

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



Bugsy 09-08-2020 22:06

Re: nVault Tutorial
 
Your savedata and loaddata look good, though you can just do: iMoney[id] = nvault_get(iVault, szAuth )


All times are GMT -4. The time now is 05:45.

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