AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   nVault not save -solved- (https://forums.alliedmods.net/showthread.php?t=187578)

Liverwiz 06-15-2012 04:50

nVault not save -solved-
 
So....i'm using nVault, and when the server is restarted, it doesn't keep the data. Anyone know why this is? Or does nVault just not do that....

Because you guys love reading code so much....this is how i initialize it etc etc
Code:
// global new g_vaultHandle // plugin_init if(get_pcvar_num(frags_pcvar) == 1 && get_pcvar_num(toggle_pcvar) == 1)     {         new mapName[32]; get_mapname(mapName, charsmax(mapName) )         g_vaultHandle = nvault_open("brass_frags") //VaultName)         if(g_vaultHandle == -1)         {             log_amx("[BKF] nVault failed to open. Frags will not be persistent. VaultID: %d. Map: %s", g_vaultHandle, mapName)             log_to_file(nVaultLogFile, "[BKF] nVault failed to open. VaultID: %d. Map: %s", g_vaultHandle, mapName)             set_pcvar_num(frags_pcvar, 0)   // turn off frags             set_pcvar_num(sc_pcvar, 0)  // turn off supercharged mode         }         else             log_to_file(nVaultLogFile, "[BKF] nVault Session Opened and active. VaultID: %d. Map: %s", g_vaultHandle, mapName)     } public plugin_end()    // I have similar code in client_disconnect(id) ->only difference is the for-loop {     if(get_pcvar_num(toggle_pcvar) == 0 || get_pcvar_num(frags_pcvar) == 0)         return         // do a clean up and save of all clients     new players[32], num     new sz_key[34], sz_data[16], name[32]     get_players(players, num, "ch")     for(new i=0, id; i<num; i++)     {         id = players[i]         if(g_idPending[id]) // no point in doing anything if the client isn't authorized             continue                     get_user_authid(id, sz_key, charsmax(sz_key) )         formatex(sz_data, charsmax(sz_data), "%d", gi_playerFrags[id])         get_user_name(id, name, charsmax(name) )                 nvault_set(g_vaultHandle, sz_key, sz_data)         log_to_file(nVaultLogFile, "[BKF] User %s (%s) has been saved to the vault with %s frags.", name, sz_key, sz_data)     }     nvault_close(g_vaultHandle) } // loading data.... new name[32], sz_vaultKey[34], data[5], timestamp     static flag, frags         get_user_name(id, name, charsmax(name) )        // Used to show who we're talking about in logFile         if( !g_playerAuth[id] )     {         g_idPending[id] = true         client_print(id, print_console, "[BKF] %L", id, "AUTH_FAIL_MSG")         gi_playerFrags[id] = 0         log_to_file(nVaultLogFile, "[BKF] User %s has not been authorized. No vault data created.", name)         return -1     }         get_user_authid(id, sz_vaultKey, charsmax(sz_vaultKey))  // we are usest the steamID as vault key     flag = nvault_lookup(g_vaultHandle, sz_vaultKey, data, charsmax(data), timestamp)         if(!flag)     {         frags = 0         nvault_set(g_vaultHandle, sz_vaultKey, "0")         log_to_file(nVaultLogFile, "[BKF] User %s (%s) is a new client and has been added to the vault.", name, sz_vaultKey)     }     else         frags = nvault_get(g_vaultHandle, sz_vaultKey)             gi_playerFrags[id] = frags     g_idPending[id] = false     log_to_file(nVaultLogFile, "[BKF] User %s (%s) has been authorized and loaded with %d frags.", name, sz_vaultKey, frags)     client_print_color(id, DontChange, "[BKF] %L", id, "WELCOME_MSG", frags) public client_disconnect(id) {     g_playerAuth[id] = false    // Clean up the authorization array; no residuals     new name[32]; get_user_name(id, name, charsmax(name) )     if(g_idPending[id])     {         if(get_pcvar_num(log_pcvar) == 1)             log_to_file(nVaultLogFile, "[BKF] User %s has disconnected, but was never authorized. Their frags were never saved.", name)         return     }         new sz_vaultKey[32], data[10]     get_user_authid(id, sz_vaultKey, charsmax(sz_vaultKey) )     formatex(data, charsmax(data), "%d", gi_playerFrags[id])         nvault_set(g_vaultHandle, sz_vaultKey, data)     if(get_pcvar_num(log_pcvar) == 1)         log_to_file(nVaultLogFile, "[BKF] User %s (%s) has been saved to the vault with %s frags.", name, sz_vaultKey, data) }

Those log messages you see are shown as such:
Quote:

L 06/14/2012 - 21:31:34: [BKF] nVault Session Opened and active. VaultID: 0. Map: de_dust
They save between maps and when users disconnect and connect again. But not after restart. Why?

hornet 06-15-2012 08:28

Re: nVault not save
 
You haven't shown us how your saving or loading your data?

Also nVault should be closed on plugin_end()

Liverwiz 06-15-2012 12:15

Re: nVault not save
 
Quote:

Originally Posted by hornet (Post 1729185)
You haven't shown us how your saving or loading your data?

Also nVault should be closed on plugin_end()

I didn't think you'd need it because it works between maps and connects. But i updated the above code.

hornet 06-16-2012 07:10

Re: nVault not save
 
Sorry I didn't see you say that. When you say restart, I'll assume you mean restart from server control panel - Doing so will not tell your plugin to close, its the same as a crash. You need to save your data earlier.

Liverwiz 06-16-2012 11:28

Re: nVault not save
 
Quote:

Originally Posted by hornet (Post 1729705)
Sorry I didn't see you say that. When you say restart, I'll assume you mean restart from server control panel - Doing so will not tell your plugin to close, its the same as a crash. You need to save your data earlier.

Wouldn't that mean that i just loose the data from the last session? Not all of the data in the vault?

hornet 06-16-2012 19:50

Re: nVault not save
 
No, it shouldn't lose the data. Save your player's data individually on client_disconnect() and that should solve your problem.

Liverwiz 06-17-2012 23:06

Re: nVault not save
 
Quote:

Originally Posted by Liverwiz (Post 1729101)
Code:
public plugin_end()    // I have similar code in client_disconnect(id) ->only difference is the for-loop

Quote:

Originally Posted by hornet (Post 1730137)
No, it shouldn't lose the data. Save your player's data individually on client_disconnect() and that should solve your problem.


hornet 06-18-2012 00:26

Re: nVault not save
 
I tested your exact code after removing the cvar checks and saved data on disconnect and had no issues with it.

Liverwiz 06-18-2012 00:37

Re: nVault not save
 
It looses data after restart. THAT is my problem. Between maps and connections isn't an issue.

hornet 06-18-2012 20:45

Re: nVault not save
 
Actually, come to think of it, it makes sense with the way nVault uses it's journal file. You'll just have to not restart your server during play. The alternative is to make a command to close your nVault before you restart your server. You could also close and re-open your nVault each time you save, however I'm not sure how efficient that'd be.


All times are GMT -4. The time now is 06:09.

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