Mam plugin, który zlicza liczbę wizyt na serwerze i pokazuje je na życzenie. Problem w tym, że po wejściu na serwer komunikat pokazuje poprawną liczbę, np. "To Twoja 3 wizyta" - i to się zgadza. Natomiast po wpisaniu "/visits" pokazuje liczbę wizyt, która niestety wynosi 49 lub 50 (zależnie od gracza), i nie ulega ona zmianie. Próbowałem usuwać cały plik "visitcounter_db" z nvault, ale wtedy znowu zlicza w pierwszym komunikacie poprawnie od pierwszej wizyty, a po użyciu komendy bez zmian - 49/50. Pewnie drobnostka, proszę o zerknięcie ![]()
Oto kod:
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <colorchat>
#define PLUGIN "VisitCounter"
#define VERSION "1.1"
#define AUTHOR "Sebxx"
new c_tmp1, c_tmp2, c_tmp3, c_str1, c_str2, g_vault, visits, last_visit
new stamp[11], prefix[33], web_addr[33], szSteam[35], temp[19], tmp[7]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_vault = nvault_open("visitcounter_db")
register_clcmd("say /visits", "show_visits") // komenda do sprawdzania liczby wizyt
c_str1 = register_cvar("visitcounter_prefix", "[CIACH]") // prefix przed komunikatami
c_str2 = register_cvar("visitcounter_webaddr", "www.CIACH.pl") // adres sieci w komunikacie
c_tmp1 = register_cvar("visitcounter_adson", "0") // wlacz komunikat z liczba wizyt
c_tmp2 = register_cvar("visitcounter_adstime", "0.0") // co ile sekund wyswietlac komunikat?
c_tmp3 = register_cvar("visitcounter_interval", "1800") // po jakim czasie naliczyc nowe wejscie?
}
public client_authorized( id, const authid[] )
{
if( !is_user_bot( id ) && !is_user_hltv( id ) )
{
set_task(10.0, "counter", id, _, _, "a", 1)
if ( get_pcvar_num(c_tmp1) == 1 )
{
set_task(get_pcvar_float(c_tmp2), "show_visits", id, _, _, "b")
}
}
}
public counter(id)
{
if ( is_user_connected( id ) )
{
get_user_authid( id, szSteam, charsmax( szSteam ) )
get_pcvar_string( c_str1, prefix, charsmax(prefix) )
get_pcvar_string( c_str2, web_addr, charsmax(web_addr) )
if ( nvault_get( g_vault , szSteam , temp , charsmax( temp ) ) )
{
strtok(temp, tmp, charsmax( tmp ), stamp, charsmax( stamp ), ';');
last_visit = str_to_num( stamp )
if ( last_visit + get_pcvar_num( c_tmp3 ) <= get_systime() )
{
visits = str_to_num( tmp ) + 1
ColorChat( id, TEAM_COLOR, "%s^x01 To Twoja %d wizyta na naszym serwerze.", prefix, visits )
ColorChat( id, TEAM_COLOR, "%s^x01 Zarejestruj sie na ^x03%s^x01!", prefix, web_addr )
}
else
{
return PLUGIN_CONTINUE
}
}
else
{
visits = 1
ColorChat( id, TEAM_COLOR, "%s^x01 To Twoja pierwsza wizyta na naszym serwerze!", prefix )
ColorChat( id, TEAM_COLOR, "%s^x01 Zarejestruj sie na ^x03%s^x01!", prefix, web_addr )
}
num_to_str( visits, tmp, charsmax(tmp) )
num_to_str( get_systime(), stamp, charsmax(stamp) )
new iLen = 0, iMax = sizeof( temp ) - 1;
iLen += formatex( temp[iLen], iMax - iLen, tmp )
iLen += formatex( temp[iLen], iMax - iLen, ";" )
iLen += formatex( temp[iLen], iMax - iLen, stamp )
nvault_set( g_vault, szSteam, temp )
}
return PLUGIN_CONTINUE
}
public show_visits(id)
{
if ( is_user_connected( id ) )
{
get_user_authid( id, szSteam, charsmax( szSteam ) )
get_pcvar_string( c_str1, prefix, charsmax(prefix) )
get_pcvar_string( c_str2, web_addr, charsmax(web_addr) )
nvault_get( g_vault , szSteam , temp , charsmax( temp ) )
strtok(temp, tmp, charsmax( tmp ), stamp, charsmax( stamp ), ';');
ColorChat( id, TEAM_COLOR, "%s^x01 To Twoja %d wizyta na naszym serwerze.", prefix, tmp )
ColorChat( id, TEAM_COLOR, "%s^x01 Zarejestruj sie na ^x03%s^x01!", prefix, web_addr )
}
}
public client_disconnected(id)
{
if( task_exists(id) )
{
remove_task(id)
}
}
public plugin_end()
{
if( g_vault != INVALID_HANDLE )
{
nvault_close(g_vault)
}
}


Dodatki SourceMod




Temat jest zamknięty









