Raised This Month: $170 Target: $400
 42% 

Solved Saving all of this in nVault?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Old 06-09-2018 , 18:41   Saving all of this in nVault?
Reply With Quote #1

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

// The Data
enum {coinskeyschipsrocksgemsgoldsuccessinpawn};

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

new 
g_iVault;

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

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

    
g_iVault nvault_open("hgrp");
}

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();
}

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);

    return 
PLUGIN_CONTINUE;
}

public 
SaveVault() {return PLUGIN_CONTINUE;}
public 
LoadVault() {return PLUGIN_CONTINUE;} 
I know how to use nVault for storing simple data. This right here is not simple at all. I tried a couple of dumb ways, but none seem to do the thing. I can see the data in the vault file, but it never loads. How should it be done properly?
__________________
I'm a Goldsource level designer looking for paid mapping jobs. "Private Message" me if you're interested.

Quote:
Originally Posted by CrazY. View Post
Why you slowhack the fucking CS 1.6 to connect to you piece of shit that you call server? Next time I will slowhack your ass, motherfucker Fuck you man.

Last edited by redivcram; 06-10-2018 at 15:04.
redivcram is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-09-2018 , 19:09   Re: Saving all of this in nVault?
Reply With Quote #2

Look at nVault array. You can save arrays, including arrays sized with an enumerator.
__________________
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
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.
__________________
I'm a Goldsource level designer looking for paid mapping jobs. "Private Message" me if you're interested.

Quote:
Originally Posted by CrazY. View Post
Why you slowhack the fucking CS 1.6 to connect to you piece of shit that you call server? Next time I will slowhack your ass, motherfucker Fuck you man.

Last edited by redivcram; 06-10-2018 at 08:53.
redivcram is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-10-2018 , 10:09   Re: Saving all of this in nVault?
Reply With Quote #4

Code:
[nVault Array] Can only use nvault_get_array() on data that was saved using nvault_set_array().
Based on the error it looks like you may have already stored data in string format under the same vault file and key for the player. When nvault_array attempts to load the data, it finds a string instead of the nvault_array-formatted data so it throws the error. If using nvault_array on a vault file that was previously used with nvault_set(), you must prune everything or use a new vault file.
__________________
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Old 06-10-2018 , 10:33   Re: Saving all of this in nVault?
Reply With Quote #5

Thanks! I forgot to delete the vault file before using your codes. Everything works fine, for now.
__________________
I'm a Goldsource level designer looking for paid mapping jobs. "Private Message" me if you're interested.

Quote:
Originally Posted by CrazY. View Post
Why you slowhack the fucking CS 1.6 to connect to you piece of shit that you call server? Next time I will slowhack your ass, motherfucker Fuck you man.

Last edited by redivcram; 06-10-2018 at 10:33.
redivcram is online now
redivcram
Veteran Member
Join Date: Jul 2014
Old 06-10-2018 , 14:30   Re: Saving all of this in nVault?
Reply With Quote #6

Can I save a 3dimensional array the same way or is there another way or no way at all?
__________________
I'm a Goldsource level designer looking for paid mapping jobs. "Private Message" me if you're interested.

Quote:
Originally Posted by CrazY. View Post
Why you slowhack the fucking CS 1.6 to connect to you piece of shit that you call server? Next time I will slowhack your ass, motherfucker Fuck you man.
redivcram is online now
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 06-10-2018 , 14:32   Re: Saving all of this in nVault?
Reply With Quote #7

Quote:
Multidimensional arrays are not directly supported, but if you use an enum to size your array, it can be accomplished.
maqi 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 15:08.


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