Raised This Month: $ Target: $400
 0% 

Nvault problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 12-19-2014 , 01:44   Nvault problem
Reply With Quote #1

I tried to convert a plugin from 'vault' to 'nVault' but its not working properly. It resets data on mapchange/server restart.

PHP Code:
public SaveData(id)
{
    new 
name[35];
    
get_user_name(idname34);
    new 
vaultkey[64], vaultdata[328];
    
    
formatex(vaultkey63"Yo_%s"name);
    
formatex(vaultdata327"%i#"g_Points[id]);
    
    
nvault_setg_Vaultvaultkeyvaultdata)
}

public 
LoadData(id)
{    
    new 
name[35];
    
get_user_name(idname34);
    
    new 
vaultkey[64], vaultdata[328];
    
    
format(vaultkey63"Yo_%s"name);
    
format(vaultdata327"%i#"g_Points[id]);
    
    
nvault_get(g_Vaultvaultkeyvaultdata327)
    
    
    
replace_all(vaultdata327"#"" ");
    new 
g_point[32];
    
parse(vaultdatag_point31);
    
g_Points[id] = str_to_num(g_point);

Syturi0 is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 12-19-2014 , 03:11   Re: Nvault problem
Reply With Quote #2

This tutorial will help you: https://forums.alliedmods.net/showthread.php?t=91503
zmd94 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-20-2014 , 12:40   Re: Nvault problem
Reply With Quote #3

  • Use steam id, not name. This only needs to be read once per player connection.
  • Use charsmax() instead of manually specifying max chars
  • I would need to see your full code to determine your issue, there's a chance you were not loading\saving at an appropriate time.

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

const MAX_PLAYERS 32;

new 
g_Vaultg_PointsMAX_PLAYERS ], g_szAuthIDMAX_PLAYERS ][ 35 ];

public 
plugin_init() 
{
    
register_clcmd"say set" "cmdSet" );
    
register_clcmd"say show" "cmdShow" );

    
g_Vault nvault_open"hello" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
cmdSetid )
{
    
g_Pointsid ] = 12345;
    
client_printid print_chat "Set 12345" );
}

public 
cmdShowid )
{
    
client_printid print_chat "%d" g_Pointsid ] );
}

public 
client_authorizedid )
{
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
LoadDataid );
}

public 
client_disconnectid )
{
    
SaveDataid );
}

public 
SaveData(id)
{
    new 
vaultkey[64] , vaultdata[328];
    
    
formatexvaultkey charsmaxvaultkey ) , "Yo_%s" g_szAuthIDid ] );
    
formatexvaultdata charsmaxvaultdata ) , "%i#" g_Pointsid ] );
    
    
nvault_setg_Vault vaultkey vaultdata )
}

public 
LoadData(id)
{    
    new 
vaultkey[64], vaultdata[328] , g_point[32];
    
    
formatvaultkey charsmaxvaultkey ) , "Yo_%s" g_szAuthIDid ] );
    
    
//You are about to read data from vault into the vaultdata variable so there is
    //no reason to format it since it will be overwritten anyway.
    //Don't do this -> format( vaultdata , 327 , "%i#", g_Points[id]);
    
    
nvault_getg_Vault vaultkey vaultdata charsmaxvaultdata ) )
    
    
replace_allvaultdata charsmaxvaultdata ) , "#" " " );
    
parsevaultdata g_point charsmaxg_point ) );
    
g_Pointsid ] = str_to_numg_point );

__________________

Last edited by Bugsy; 12-22-2014 at 21:39.
Bugsy is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 12-22-2014 , 04:23   Re: Nvault problem
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
  • Use steam id, not name. This only needs to be read once per player connection.
  • Use charsmax() instead of manually specifying max chars
  • I would need to see your full code to determine your issue, there's a chance you were not loading\saving at an appropriate time.

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

const MAX_PLAYERS 32;

new 
g_Vaultg_PointsMAX_PLAYERS ], g_szAuthIDMAX_PLAYERS ][ 35 ];

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

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
LoadDataid );
}

public 
client_disconnectid )
{
    
SaveDataid );
}

public 
SaveData(id)
{
    new 
vaultkey[64] , vaultdata[328];
    
    
formatexvaultkey charsmaxvaultkey ) , "Yo_%s" g_szAuthIDid ] );
    
formatexvaultdata charsmaxvaultdata ) , "%i#" g_Pointsid ] );
    
    
nvault_setg_Vault vaultkey vaultdata )
}

public 
LoadData(id)
{    
    new 
vaultkey[64], vaultdata[328] , g_point[32];
    
    
formatvaultkey charsmaxvaultkey ) , "Yo_%s" g_szAuthIDid ] );
    
    
//You are about to read data from vault into the vaultdata variable so there is
    //no reason to format it since it will be overwritten anyway.
    //Don't do this -> format( vaultdata , 327 , "%i#", g_Points[id]);
    
    
nvault_getg_Vault vaultkey vaultdata charsmaxvaultdata ) )
    
    
replace_allvaultdata charsmaxvaultdata ) , "#" " " );
    
parsevaultdata g_point charsmaxg_point ) );
    
g_Pointsid ] = str_to_numg_point );

With that code, it is not saving, and it doesnt even create any file.
Syturi0 is offline
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 12-22-2014 , 08:00   Re: Nvault problem
Reply With Quote #5

Quote:
Originally Posted by Syturi0 View Post
With that code, it is not saving, and it doesnt even create any file.
May be your server is non-steam !!
Edit: post full code
__________________
Thanks everyone. #miss_you_all

Last edited by indraraj striker; 12-22-2014 at 08:03.
indraraj striker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-22-2014 , 21:45   Re: Nvault problem
Reply With Quote #6

No, it works, he's doing something wrong. I added 2 commands to my above code, one to set data to the variable and another to display it to the user.

Before doing anything to the code, I only connected and disconnected. Oh look, a vault file exists with my data in it.


Next I connected, set data to the variable, then disconnected.


And here I connected again and just showed the value which means it successfully loaded from nvault.
__________________

Last edited by Bugsy; 12-22-2014 at 21:47.
Bugsy is offline
Reply



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:25.


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