AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Nvault problem (https://forums.alliedmods.net/showthread.php?t=253271)

Syturi0 12-19-2014 01:44

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



zmd94 12-19-2014 03:11

Re: Nvault problem
 
This tutorial will help you: https://forums.alliedmods.net/showthread.php?t=91503

Bugsy 12-20-2014 12:40

Re: Nvault problem
 
  • 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 );



Syturi0 12-22-2014 04:23

Re: Nvault problem
 
Quote:

Originally Posted by Bugsy (Post 2237629)
  • 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.

indraraj striker 12-22-2014 08:00

Re: Nvault problem
 
Quote:

Originally Posted by Syturi0 (Post 2238334)
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

Bugsy 12-22-2014 21:45

Re: Nvault problem
 
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.
https://dl.dropboxusercontent.com/u/...2021.33.42.png

Next I connected, set data to the variable, then disconnected.
https://dl.dropboxusercontent.com/u/...2021.35.01.png

And here I connected again and just showed the value which means it successfully loaded from nvault.
https://dl.dropboxusercontent.com/u/...2021.38.09.png


All times are GMT -4. The time now is 15:25.

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