Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
|
10-13-2016
, 17:30
Re: Vault Save Problems
|
#9
|
Oh my godness.
I thought problem was solved but new problem.
It works normal and after some reconnections it's starting to set negative values or for example if I saved to nvault 135 seconds after reconnect it gets only 20 or -140 , like random values.
Is it something out of maximum possible value for nvault?
After 134 it goes to negative , like it reaches maximum limit or something. I don't understand.
This is the code:
PHP Code:
#include <amxmodx> #include <amxmisc> #include <nvault> #include <nvault_util>
#define MAX_BUFFER_LENGTH 2047 #define MOTD_ORE_NAME "Time Admins"
new const NVAULT_NAME[] = "Time_Admins"
new g_sBuffer[ MAX_BUFFER_LENGTH + 1] = "";
native get_auth_type(id);
public plugin_init() { register_plugin("Time Admins", "1.0", "siriusmd99") register_clcmd("say /time", "cmdTimeAdmins", ADMIN_RCON) register_event("HLTV", "hook_NewRound", "a", "1=0", "2=0") g_sBuffer[0] = 0; new iVault = nvault_open( NVAULT_NAME ); if ( iVault == INVALID_HANDLE ) { new fail_msg[64] formatex(fail_msg, charsmax(fail_msg), "Cannot open nVault file ^"%s^".", NVAULT_NAME) set_fail_state( fail_msg ) } else { nvault_close( iVault ) } }
public hook_NewRound() { new month[3], lastmonth[3]; new day[4], lastday[4]; get_time("%m",month,charsmax(month)) get_time("%j",day,charsmax(day)) get_vaultdata("lastMonthOre", lastmonth, charsmax(lastmonth)); if( !lastmonth[0] ) { set_vaultdata("lastMonthTime", month); set_vaultdata("lastDayTime", day); return; } new iVault = nvault_util_open( NVAULT_NAME ); if( !equal(lastmonth, month)) { set_vaultdata("lastMonthTime", month); nvault_util_close( iVault) iVault = nvault_open( NVAULT_NAME ) nvault_prune(iVault, 0, get_systime() + 1); nvault_set( iVault , month , day ); nvault_close( iVault); } else { get_vaultdata("lastDayTime", lastday, charsmax(lastday)); if( !equal(lastday, day)) { set_vaultdata("lastDayTime", day); new iKey[35]; new iDays[4] new iPos; new isecVault = nvault_open( NVAULT_NAME ) for (new i; i < nvault_util_count( iVault ); i++) { iPos = nvault_util_read( iVault , iPos , iKey , charsmax( iKey ) , iDays , charsmax( iDays ) ); iDays[0] = 0; nvault_set( isecVault , iKey , iDays); } nvault_close( isecVault); } nvault_util_close(iVault) } }
public client_disconnect(id) { if(is_user_admin(id)) { new data[35], nv_data[4]; new iAuthType = get_auth_type(id); switch(iAuthType) { case 1: get_user_name(id, data, charsmax(data)) case 2: get_user_ip(id, data, charsmax(data), 1) case 3: get_user_authid(id, data, charsmax(data)) } new iVault = nvault_open( NVAULT_NAME ); nvault_get( iVault , data, nv_data, charsmax(nv_data) ); log_amx("get %d seconds , %d seconds", nv_data[0], nv_data[1]) new tmp_time = get_user_time(id); nv_data[0] += tmp_time; nv_data[1] += tmp_time; nv_data[2] = iAuthType; nvault_set( iVault , data , nv_data ); log_amx("set %d seconds, set %d seconds", nv_data[0], nv_data[1]) nvault_close( iVault ); } }
public cmdOreAdmins(id, level, cid) { if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED format_top15(g_sBuffer) show_motd(id, g_sBuffer, MOTD_ORE_NAME) return PLUGIN_HANDLED }
format_top15(sBuffer[MAX_BUFFER_LENGTH + 1]) { new iKey[32], iSeconds[4]; new iLen = 0; new szHours[12], szmHours[12]
iLen = format( sBuffer, MAX_BUFFER_LENGTH, "<head><META http-equiv=Content-Type content='text/html ;charset=UTF-8'></head><style>body{color:#FFCC99;background-color:black;margin-top:5}.A{background-color:#310000}.B{background-color:#630000}td{font-size:14px}</style><center><b><font size=4>Admins Time</b><table width=500>" ) iLen += format( sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "<tr bgcolor=#9C0000><td>%s<td>%s<td>%s<td>%s", "#", "Admin Name", "Today", "This Month")
new iVault = nvault_util_open( NVAULT_NAME ) new iPos;
for (new i; i < (nvault_util_count( iVault )) && MAX_BUFFER_LENGTH - iLen > 0; i++) { iPos = nvault_util_read( iVault , iPos , iKey , charsmax( iKey ) , iSeconds , charsmax( iSeconds ) ); if(iSeconds[2] > 1) { new plid = find_player( iSeconds[2] == 2 ? "d" : "c", iKey) if(plid) { get_user_name(plid, iKey, charsmax(iKey)) } new tmp_curtime = get_user_time(plid) iSeconds[0] += tmp_curtime iSeconds[1] += tmp_curtime } iSeconds[0] /= 60; //Converting seconds to minutes iSeconds[1] /= 60; if(iSeconds[0] < 60) { formatex(szHours, charsmax(szHours), "%d%s", iSeconds[0], "m") } else { formatex(szHours, charsmax(szHours), "%d%s %d%s", iSeconds[0] / 60, "h", iSeconds[0] % 60, "m") } if(iSeconds[1] < 60) { formatex(szmHours, charsmax(szmHours), "%d%s", iSeconds[1], "m") } else { formatex(szmHours, charsmax(szmHours), "%d%s %d%s", iSeconds[1] / 60, "h", iSeconds[1] % 60, "m") } iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "<tr class=%s><td>%d<td>%s<td>%s<td>%s", "B", i + 1, iKey, szHours, szmHours) } nvault_util_close( iVault ) }
I put log and it shows on admin disconnect this:
Set 130 seconds and 130 seconds (daily and monthly)
After i reconnect and disconnect back it shows:
get -40 seconds and -40 seconds.
How is this possible?
I saved 130 seconds and when i get the value from nvault it's -40?
I looked and checked the code and there is nothing in code that could change value from 130 to -40 like this.
Thanks for help in advance.
|
|