I might be blind, but what's the mistake here? when i reconnect to the server it starts counting again from 0, not from the old value, so it doesn't save the time.
Code:
#include < amxmodx > #include < fvault > // - - - - - - - - new const gs_SayCommand[ ] = "say /timpjucat";
// - - - - - - - - new const gs_VaultName[ ] = "PlayedTime";
new gi_Time[ 33 ], gi_pTime[ 33 ] = { 0, ... };
public plugin_init ( ) { register_clcmd ( gs_SayCommand, "display_time" );
} public client_putinserver ( e_Index ) LoadTime ( e_Index );
public client_disconnect ( e_Index ) SaveTime ( e_Index );
public LoadTime ( e_Index ) { new s_Name[ 32 ], i_Value[ 16 ];
get_user_name ( e_Index, s_Name, 31 );
gi_Time[ e_Index ] =
( fvault_get_data ( gs_VaultName, s_Name, i_Value, charsmax ( i_Value ) ) ) ? str_to_num ( i_Value ) : 0;
} public SaveTime ( e_Index ) { new s_Name[ 32 ], i_Value[ 16 ];
get_user_name ( e_Index, s_Name, 31 );
num_to_str ( gi_Time[ e_Index ], i_Value, charsmax ( i_Value ) );
fvault_set_data ( gs_VaultName, s_Name, i_Value );
} public display_time ( e_Index ) { new i_Time = get_user_time ( e_Index, 1 );
gi_Time[ e_Index ] += ( i_Time - gi_pTime[ e_Index ] );
gi_pTime[ e_Index ] = i_Time;
SaveTime ( e_Index );
LoadTime ( e_Index );
new s_Buffer[ 128 ], i_Minutes, i_Hours;
if ( gi_Time[ e_Index ] < 60 ) formatex ( s_Buffer, charsmax ( s_Buffer ), "%d secunde", gi_Time[ e_Index ] );
else { if ( gi_Time[ e_Index ] >= 3600 ) { i_Hours = gi_Time[ e_Index ] / 3600;
i_Minutes = gi_Time[ e_Index ] % 3600;
} else i_Minutes = gi_Time[ e_Index ] / 60;
if ( i_Hours ) formatex ( s_Buffer, charsmax ( s_Buffer ), "%d ore", i_Hours );
if ( i_Minutes ) { ( s_Buffer[ 0 ] ) ? format ( s_Buffer, charsmax ( s_Buffer ), "%s si %d minut%s", s_Buffer, i_Minutes, ( i_Minutes == 1 ) ? "" : "e" ) : formatex ( s_Buffer, charsmax ( s_Buffer ), "%d minut%s", i_Minutes, ( i_Minutes == 1 ) ? "" : "e" );
} } new s_Buffer2[ 128 ];
if ( i_Time < 60 ) formatex ( s_Buffer2, charsmax ( s_Buffer2 ), "%d secund%s", i_Time, ( i_Time == 1 ) ? "a" : "e" );
else { i_Time /= 60;
formatex ( s_Buffer2, charsmax ( s_Buffer2 ), "%d minut%s", i_Time, ( i_Time == 1 ) ? "" : "e" );
} client_print ( e_Index, print_chat, "Esti pe server de %s", s_Buffer2 );
client_print ( e_Index, print_chat, "Timp total pe server: %s", s_Buffer );
return 0;
}
__________________
Last edited by anakin_cstrike; 07-12-2009 at 08:53.
|