View Single Post
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 06-10-2018 , 08:52   Re: Saving all of this in nVault?
Reply With Quote #3

Thanks,

Here's what I've done.

PHP Code:
#include <amxmodx>
#include <nvault>
#include <nvault_array>

// The Data
enum _:SomeValuableData{coinskeyschipsrocksgemsgoldsuccessinpawn};

// 1st Dimension: Player's ID
// 2nd Dimension: Max Data
new g_iDataHolder[33][SomeValuableData];

new 
g_iVault;

public 
plugin_init()
{
    
register_plugin("qwe""rty""uiop");

    
register_clcmd("change_data""ChangeYourOwnData");
    
register_clcmd("save_data""SaveVault");

    
g_iVault nvault_open("hgrp");
}

public 
plugin_end()
    
nvault_close(g_iVault);

public 
client_putinserver(id)
{
    new 
i;

    
// First set every data to 0
    
for(08i++)
        
g_iDataHolder[id][i] = 0

    
// successinpawn aka g_iDataHolder[id][7] should be set to 100 by default (For newcomers aka people who didn't save anything in vault)
    
g_iDataHolder[id][successinpawn] = 100;

    
LoadVault(id);
}

public 
ChangeYourOwnData(id)
{
    new 
szArgv_Select[2], szArgv_Set[4];

    
read_argv(1szArgv_Selectcharsmax(szArgv_Select));
    
read_argv(2szArgv_Setcharsmax(szArgv_Set));

    
// No checks for empty strings/boundaries necessary since its known what to type in this small temporary example

    
g_iDataHolder[id][str_to_num(szArgv_Select)] = str_to_num(szArgv_Set);

    
SaveVault(id);

    return 
PLUGIN_CONTINUE;
}

public 
SaveVault(id
{
    new 
szAuthID[32], szKey[32];

    
get_user_authid(idszAuthIDcharsmax(szAuthID));

    
format(szKeycharsmax(szKey), "%s-heyo"szAuthID);

    
nvault_set_array(g_iVaultszKeyg_iDataHolder[id], sizeof(g_iDataHolder[]));

    return 
PLUGIN_HANDLED;


public 
LoadVault(id

    new 
szAuthID[32], szKey[32];

    
get_user_authid(idszAuthIDcharsmax(szAuthID));

    
format(szKeycharsmax(szKey), "%s-heyo"szAuthID);
     
    
nvault_get_array(g_iVaultszKeyg_iDataHolder[id], sizeof(g_iDataHolder[]));

    return 
PLUGIN_HANDLED;

But, here's an error

Code:
L 06/10/2018 - 14:37:11: [AMXX] Plugin ("nvault_problem.amxx") is setting itself as failed.
L 06/10/2018 - 14:37:12: [AMXX] Plugin says: [nVault Array] Can only use nvault_get_array() on data that was saved using nvault_set_array().
L 06/10/2018 - 14:37:12: [AMXX] Displaying debug trace (plugin "nvault_problem.amxx")
L 06/10/2018 - 14:37:12: [AMXX] Run time error 1: forced exit 
L 06/10/2018 - 14:37:12: [AMXX]    [0] nvault_array.inc::nvault_get_array (line 107)
L 06/10/2018 - 14:37:12: [AMXX]    [1] nvault_problem.sma::LoadVault (line 78)
L 06/10/2018 - 14:37:12: [AMXX]    [2] nvault_problem.sma::client_putinserver (line 38)
It is supposed to load the client's data when they connect. I performed a check before getting your modified nvault and the new nvault_array lib using nvault_lookup, but it doesn't work properly with arrays, I guess, I always seemed to get false when checking whether data existed with its suitable key.

Last edited by redivcram; 06-10-2018 at 08:53.
redivcram is offline