下面是引用 T0un5G 于 2013-10-05 17:19 发表的 :
来人帮帮我吧>< 我很需要
给你作为参考
复制程式
#include <amxmodx>
#include <nvault>
#define MAXPLAYERS 32
#define GetPlayedTime(%0) (get_user_time(%0, 1) + g_PlayedTime[%0])
new g_PlayedTime[ MAXPLAYERS+1 ];
public plugin_init()
{
register_clcmd( "say /test", "ClCmd_Test" );
}
public ClCmd_Test( id )
{
new time = GetPlayedTime( id ) / 60;
client_print( id, print_chat, "在时时间: %i天 %i小时 %i分", time / 1440, time / 60 % 24, time % 60 );
}
public client_putinserver( id )
{
LoadData( id );
}
public client_disconnect( id )
{
SaveData( id );
}
LoadData( id )
{
new vault = nvault_open( "myvault" );
if( vault == INVALID_HANDLE )
{
set_fail_state( "Failed to open nVault." );
return;
}
static vaultKey[ 37 ];
get_user_ip( id, vaultKey, charsmax(vaultKey), 1 );
add( vaultKey, charsmax(vaultKey), "TIME" );
g_PlayedTime[ id ] = nvault_get( vault, vaultKey );
nvault_close( vault );
}
SaveData( id )
{
new vault = nvault_open( "myvault" );
if( vault == INVALID_HANDLE )
{
set_fail_state( "Failed to open nVault." );
return;
}
static vaultKey[ 37 ], vaultData[ 11 ];
get_user_ip( id, vaultKey, charsmax(vaultKey), 1 );
add( vaultKey, charsmax(vaultKey), "TIME" );
num_to_str( GetPlayedTime( id ), vaultData, charsmax(vaultData) );
nvault_set( vault, vaultKey, vaultData );
nvault_close( vault );
}