AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] nVault problem (https://forums.alliedmods.net/showthread.php?t=282534)

KaLoIaN 05-09-2016 10:31

[HELP] nVault problem
 
I decided to go to MySQL because nVault is very problematic on my server..
Sometimes when the server crashes everyone on the server loses his variables stored in the vault, but another plugin which also uses nVault does not loses it's variables?

PHP Code:

public SaveData(id)
{
    new 
AuthID[35]
    
get_user_name(idAuthID34)
 
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s"AuthID)
    
format(vaultdata255"%i#%i#%i#%i#"g_Health[id], g_Armor[id], g_Damage[id], g_Money[id])
    
nvault_set(g_Nvaultvaultkeyvaultdata)
    return 
PLUGIN_CONTINUE
}

public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_name(idAuthID34)
 
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s"AuthID)
    
format(vaultdata255"%i#%i#%i#%i#"g_Health[id], g_Armor[id], g_Damage[id], g_Money[id])
    
nvault_get(g_Nvaultvaultkeyvaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
PlayerHP[32], PlayerAP[32], PlayerDM[32], PlayerMY[32]
 
    
parse(vaultdataPlayerHP31PlayerAP31PlayerDM31PlayerMY31)
 
    
g_Health[id] = str_to_num(PlayerHP)
    
g_Armor[id] = str_to_num(PlayerAP)
    
g_Damage[id] = str_to_num(PlayerDM)
    
g_Money[id] = str_to_num(PlayerMY)
 
    return 
PLUGIN_CONTINUE


This code of nVault loses the stored variables on server crash. I don't found the code which does not loses the stored variables because it does not have .SMA file.

Bugsy 05-09-2016 21:06

Re: [HELP] nVault problem
 
This is because when a server does not close gracefully, client_disconnect() is not called on all clients and this is most likely where SaveData() is called from on each player.

To avoid this issue, you will need to save data as it changes for each player. It is not as efficient, but you wouldn't lose any data. My recommendation is to track down your crash issue and resolve it and not use a band-aid on all of your plugins.

KaLoIaN 05-10-2016 05:40

Re: [HELP] nVault problem
 
Here is the another part of save code i forgot :

PHP Code:

stock save_user_levels(id)
{
    
gVault nvault_open("SavedLevel")
    
    if(
gVault == INVALID_HANDLE)
        
set_fail_state("[ZE SS] nVault Open Error => Invalid Handle")
    
    
get_user_name(idgName31)
    
formatex(vKeycharsmax(vKey), "%s"gName)
    
formatex(vDatacharsmax(vData), "%i#%i#"g_iLevel[id], g_iExp[id])
    
nvault_set(gVaultvKeyvData)
    
    
nvault_close(gVault)
}

stock load_user_levels(id)
{
    
gVault nvault_open("SavedLevel")
    
    if(
gVault == INVALID_HANDLE)
        
set_fail_state("[Upgrades] nVault ERROR => Invalid Handle .")
    
    
get_user_name(idgName31)
    
formatex(vKeycharsmax(vData), "%s"gName)
    
formatex(vDatacharsmax(vData), "%i#%i#"g_iLevel[id], g_iExp[id])
    
nvault_get(gVaultvKeyvDatacharsmax(vData))
    
    
replace_all(vDatacharsmax(vData), "#"" ")
    
    new 
experience[32], playerlevel[32]
    
    
parse(vDataexperience31playerlevel31);
    
    
g_iLevel[id] = str_to_num(experience)
    
g_iExp[id] = str_to_num(playerlevel)
    
    
nvault_close(gVault);



Here are the Load/Save:

PHP Code:


public client_putinserveriPlayer )
{    
        
load_user_levels(iPlayer);
    
LoadData(iPlayer)


PHP Code:


public client_disconnect(id
{
    
save_user_levels(id);
    
    
SaveData(id)


What's the matter with them?




----------------------

Quote:

Originally Posted by Bugsy (Post 2417986)
This is because when a server does not close gracefully, client_disconnect() is not called on all clients and this is most likely where SaveData() is called from on each player.

To avoid this issue, you will need to save data as it changes for each player. It is not as efficient, but you wouldn't lose any data. My recommendation is to track down your crash issue and resolve it and not use a band-aid on all of your plugins.

I tracked the issue which causes the crash, but sometimes the VPS on which is located the server crashesh and server dies also, and I don't want to lose any data.

How I can make nVault save when the data changes?

OciXCrom 05-10-2016 06:56

Re: [HELP] nVault problem
 
It doesn't mean that the crashes are caused by that plugin or the code above has errors in it. Save the data more often by adding SaveData(id) whenever the player's data is updated. This will save the data right away and it won't really matter whether client_disconnect(id) is called, i.e. the server shuts down properly.

KaLoIaN 05-10-2016 10:26

Re: [HELP] nVault problem
 
So may I set a task with SaveData(id) ?
Will it work good?

OciXCrom 05-10-2016 10:33

Re: [HELP] nVault problem
 
Yes, you can. A better idea in some aspects is setting a repeating task that will save the data for all players every 5 minutes (for example).

KaLoIaN 05-10-2016 11:16

Re: [HELP] nVault problem
 
Quote:

Originally Posted by OciXCrom (Post 2418100)
Yes, you can. A better idea in some aspects is setting a repeating task that will save the data for all players every 5 minutes (for example).

Will that overflow the server much and cause lag? As like Bugsy said it's not efficient.

OciXCrom 05-10-2016 14:08

Re: [HELP] nVault problem
 
Not really. Yes, it's totally unfefficient, because the best way is to save them on client_disconnect(id). But, still, unefficient doesn't mean that it wouldn't work.

siriusmd99 05-11-2016 09:21

Re: [HELP] nVault problem
 
ok, client_disconnect is not called. But maybe other forwards are called , for example plugin_end?
To use get_players then save_data() on plugin_end?

Andu. 05-11-2016 11:49

Re: [HELP] nVault problem
 
You can save data when player get +exp(on deathmsg event or idk) for example and no data will be lost


All times are GMT -4. The time now is 18:42.

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