Timers with tasks arent correct. You can use like prethink and show message every 1 second (get gametime - start ).
PHP Code:
#include < amxmodx >
#include < engine >
#include < hamsandwich >
new g_iMsgSayText, Float:g_flStartDelay, Float:g_flStartTime[ 33 ], Trie:g_tStarts, Trie:g_tStops;
public plugin_init( ) {
register_plugin( "XJ DecimalTimer", "1.0", "xPaw" );
g_iMsgSayText = get_user_msgid( "SayText" );
g_tStarts = TrieCreate( );
g_tStops = TrieCreate( );
new szMap[ 21 ], i;
get_mapname( szMap, 20 );
if( equali( szMap, "kz_a2_bhop_corruo_ez" )
|| equali( szMap, "kz_a2_bhop_corruo_h" )
|| equali( szMap, "kz_a2_godspeed" ) ) {
RegisterHam( Ham_Touch, "func_button", "FwdHamButtonTouch" );
}
else if( equali( szMap, "kz_man_climbrace" ) ) {
RegisterHam( Ham_Think, "func_breakable", "FwdHamBreakableThink" );
RegisterHam( Ham_Touch, "trigger_multiple", "FwdHamMultipleTouch" );
} else {
if( equali( szMap, "kz_cup_storage" ) )
g_flStartDelay = 5.0;
RegisterHam( Ham_Use, "func_button", "FwdHamButtonUse" );
}
register_logevent( "LogEvent_StartRound", 2,"0=World triggered", "1=Round_Start" );
new const szStarts[ ][ ] = {
"counter_start", "clockstartbutton", "firsttimerelay", "but_start", "counter_start_button",
"multi_start", "timer_startbutton", "start_timer_emi", "gogogo"
};
new const szStops[ ][ ] = {
"counter_off", "clockstopbutton", "clockstop", "but_stop", "counter_stop_button",
"multi_stop", "stop_counter", "m_counter_end_emi"
};
for( i = 0; i < sizeof szStarts; i++ )
TrieSetCell( g_tStarts, szStarts[ i ], 1 );
for( i = 0; i < sizeof szStops; i++ )
TrieSetCell( g_tStops, szStops[ i ], 1 );
}
public plugin_end( ) {
TrieDestroy( g_tStarts );
TrieDestroy( g_tStops );
}
public client_disconnect( id )
g_flStartTime[ id ] = 0.0;
public LogEvent_StartRound( )
arrayset( _:g_flStartTime, _:0.0, 33 );
public FwdHamMultipleTouch( const iEntity, const id )
if( is_user_alive( id ) )
Timer_Stop( id );
public FwdHamBreakableThink( const iEntity ) {
new iPlayers[ 32 ], iNum;
get_players( iPlayers, iNum, "a" );
if( iNum )
for( new i; i < iNum; i++ )
Timer_Start( iPlayers[ i ] );
}
public FwdHamButtonUse( const iEntity, const id ) {
if( !is_user_alive( id ) )
return;
new szTarget[ 32 ];
entity_get_string( iEntity, EV_SZ_target, szTarget, 31 );
if( TrieKeyExists( g_tStarts, szTarget ) )
Timer_Start( id );
else if( TrieKeyExists( g_tStops, szTarget ) )
Timer_Stop( id );
}
public FwdHamButtonTouch( const iEntity, const id ) {
if( !is_user_alive( id ) )
return;
static const START[ ] = "gogogo";
static const STOP[ ] = "stop_counter";
new szTarget[ 32 ];
entity_get_string( iEntity, EV_SZ_target, szTarget, 31 );
if( equal( szTarget, START ) )
Timer_Start( id );
else if( equal( szTarget, STOP ) )
Timer_Stop( id );
}
public Timer_Start( const id ) {
if( g_flStartTime[ id ] )
return;
g_flStartTime[ id ] = get_gametime( );
SendSayText( id, "^4[XJ]^1 You have started the timer!" );
}
Timer_Stop( const id ) {
if( !g_flStartTime[ id ] )
return;
new szTime[ 15 ], szMessage[ 128 ];
ClimbtimeToString( ( get_gametime( ) - g_flStartTime[ id ] - g_flStartDelay ), szTime, 14 );
g_flStartTime[ id ] = 0.0;
formatex( szMessage, 127, "^4[XJ]^1 You finished the map in:^3 %s^1! Congratulations.", szTime );
SendSayText( id, szMessage );
new iPlayers[ 32 ], iNum;
get_players( iPlayers, iNum, "b" );
if( iNum ) {
new szNick[ 32 ], iPlayer;
get_user_name( id, szNick, 31 );
formatex( szMessage, 127, "^4[XJ]^3 %s^1 has finished the map in:^3 %s^1!", szNick, szTime );
for( new i; i < iNum; i++ ) {
iPlayer = iPlayers[ i ];
// if( ( 1 << entity_get_int( iPlayer, EV_INT_iuser1 ) ) & ( ( 1 << 1 ) | ( 1 << 2 ) | ( 1 << 4 ) ) &&
if( id == entity_get_int( iPlayer, EV_INT_iuser2 ) )
SendSayText( iPlayer, szMessage );
}
}
}
ClimbtimeToString( const Float:flClimbTime, szOutPut[ ], const iLen ) {
new iMinutes = floatround( flClimbTime / 60.0, floatround_floor );
new iSeconds = floatround( flClimbTime - iMinutes * 60, floatround_floor );
new iMiliSeconds = floatround( ( flClimbTime - ( iMinutes * 60 + iSeconds ) ) * 100, floatround_floor );
formatex( szOutPut, iLen, "%02i:%02i.%02i", iMinutes, iSeconds, iMiliSeconds );
}
SendSayText( const id, const szMessage[ ] ) {
message_begin( MSG_ONE_UNRELIABLE, g_iMsgSayText, _, id );
write_byte( id );
write_string( szMessage );
message_end( );
}