You need to initialize a person into the vault before you can save, or get their data. Check out my code from a plugin i use nvault for.
PHP Code:
retrieveFrags(id) // gets the frags for the given clientID from vualt @RETURNS player's frags or -1 if not authorized
{
if(get_pcvar_num(frags_pcvar) == 0 || get_pcvar_num(toggle_pcvar) == 0)
{
client_print(id, print_console, "[AMX] %L", id, "DISABLED")
return PLUGIN_HANDLED
}
if(!is_user_connected(id) || is_user_bot(id))
return -1
new name[32], sz_vaultKey[34], data[5], timestamp
static frags
get_user_name(id, name, charsmax(name) ) // Used to show who we're talking about in logFile
// This makes sure the user has a valid AuthID
if( !g_playerAuth[id] )
{
g_idPending[id] = true
client_print(id, print_console, "[BKF] %L", id, "AUTH_FAIL_MSG")
gi_playerFrags[id] = 0
if(get_pcvar_num(log_pcvar) == 1)
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
if(!nvault_lookup(g_vaultHandle, sz_vaultKey, data, charsmax(data), timestamp))
{
frags = 0
nvault_set(g_vaultHandle, sz_vaultKey, "0")
if(get_pcvar_num(log_pcvar) == 1)
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
if(get_pcvar_num(log_pcvar) == 1)
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)
return frags
}
P.S. Read and understand the code. Don't just copy/paste it.
This code is run at
client_putinserver
also....don't use parse and replace all to seperate your data use
strtok, it'll save you some native calls.
Code:
strtok(vaultdata, kills, charsmax(kills), deaths, charsmax(deaths), '#', 1)
This will not remove the final #. Take it out. you don't need it, unless you have plans for it later.
__________________