For some reason, no matter what I try, I cannot get the nvault to store/recall the data properly. I dont know what it is after three code re-writes, thus I am asking for help.
I know theres a lot of room for optimization, however for now I just want to get it to work properly..
The problem occurs when I say /credits after a disconnect. When I reconnect, the credits are reset to zero, thus making it kinda obsolete. Im pretty sure its either:
Problem with the nvault_get
Problem with the nvault_set
Mis-used variable to the nvault
Help would be greatly appreciated.
Update:
I just found the nvault viewer and apparently its not writing or getting. Making me so confused.
Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <cstrike>
#include <fun>
#include <nvault>
#define PLUGIN "nAcHo's Special Weapon Mod"
#define VERSION "0.02"
#define AUTHOR "nAcHo cHeEsE"
new last_playtime_check[33]
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /credits", "credits_say")
register_clcmd("say_team /credits", "credits_say")
register_clcmd("say credits", "credits_say")
register_clcmd("say creds", "credits_say")
}
public client_putinserver(id) {
new authid[32]
get_user_authid(id, authid, 34)
//get the time spent playing
new time_playing
time_playing = (get_user_time(id) - last_playtime_check[id])
last_playtime_check[id] = get_user_time(id)
//NVAULT
//vault_set = the previous vault value
new nvault = nvault_open("CreditsMod23")
new vault_set[32], prev_vault_set
nvault_get(nvault, authid, vault_set[id])
prev_vault_set = str_to_num(vault_set[id])
vault_set[id] = prev_vault_set + time_playing
num_to_str(vault_set[id], vault_set[id], 34)
nvault_set(nvault, authid, vault_set[id])
//END NVAULT
}
public credits_say(id) {
//get the authid
new authid[32]
get_user_authid(id, authid, 34)
//get the time spent playing
new time_playing
time_playing = (get_user_time(id) - last_playtime_check[id])
last_playtime_check[id] = get_user_time(id)
new nvault = nvault_open("CreditsMod23")
new vault_set[32], prev_vault_set
nvault_get(nvault, authid, vault_set[id], 34)
prev_vault_set = str_to_num(vault_set[id])
vault_set[id] = prev_vault_set + time_playing
num_to_str(vault_set[id], vault_set[id], 34)
nvault_set(nvault, authid, vault_set[id])
nvault_get(nvault, authid, vault_set[id], 34)
new credits
credits = str_to_num(vault_set[id])
client_print(id, print_chat, "You have %i Credits", credits)
}
public client_disconnect(id) {
//get the authid
new authid[32]
get_user_authid(id, authid, 34)
//get the time spent playing
last_playtime_check[id] = 0
new time_playing
time_playing = (get_user_time(id) - last_playtime_check[id])
new nvault = nvault_open("CreditsMod23")
new vault_set[32], prev_vault_set
nvault_get(nvault, authid, vault_set[id], 34)
prev_vault_set = str_to_num(vault_set[id])
vault_set[id] = prev_vault_set + time_playing
num_to_str(vault_set[id], vault_set[id], 34)
nvault_set(nvault, authid, vault_set[id])
}