View Single Post
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-19-2010 , 01:57   Re: [KZ] Simple Timer
Reply With Quote #6

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_iMsgSayTextFloat:g_flStartDelayFloat:g_flStartTime33 ], Trie:g_tStartsTrie: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 
szMap21 ], i;
    
get_mapnameszMap20 );
    
    if( 
equaliszMap"kz_a2_bhop_corruo_ez" )
    ||  
equaliszMap"kz_a2_bhop_corruo_h" )
    ||  
equaliszMap"kz_a2_godspeed" ) ) {
        
RegisterHamHam_Touch"func_button""FwdHamButtonTouch" ); 
    }
    else if( 
equaliszMap"kz_man_climbrace" ) ) {
        
RegisterHamHam_Think"func_breakable""FwdHamBreakableThink" );
        
RegisterHamHam_Touch"trigger_multiple""FwdHamMultipleTouch" );
    } else {
        if( 
equaliszMap"kz_cup_storage" ) )
            
g_flStartDelay 5.0;
        
        
RegisterHamHam_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( 
0sizeof szStartsi++ )
        
TrieSetCellg_tStartsszStarts], );
    
    for( 
0sizeof szStopsi++ )
        
TrieSetCellg_tStopsszStops], );
}

public 
plugin_end( ) {
    
TrieDestroyg_tStarts );
    
TrieDestroyg_tStops );
}

public 
client_disconnectid )
    
g_flStartTimeid ] = 0.0;

public 
LogEvent_StartRound( )
    
arrayset_:g_flStartTime_:0.033 );

public 
FwdHamMultipleTouch( const iEntity, const id )
    if( 
is_user_aliveid ) )
        
Timer_Stopid );

public 
FwdHamBreakableThink( const iEntity ) {
    new 
iPlayers32 ], iNum;
    
get_playersiPlayersiNum"a" );
    
    if( 
iNum )
        for( new 
iiNumi++ )
            
Timer_StartiPlayers] );
}

public 
FwdHamButtonUse( const iEntity, const id ) {
    if( !
is_user_aliveid ) )
        return;
    
    new 
szTarget32 ];
    
entity_get_stringiEntityEV_SZ_targetszTarget31 );
    
    if( 
TrieKeyExistsg_tStartsszTarget ) )
        
Timer_Startid );
    else if( 
TrieKeyExistsg_tStopsszTarget ) )
        
Timer_Stopid );
}

public 
FwdHamButtonTouch( const iEntity, const id ) {
    if( !
is_user_aliveid ) )
        return;
    
    static const 
START[ ] = "gogogo";
    static const 
STOP[ ]  = "stop_counter";
    
    new 
szTarget32 ];
    
entity_get_stringiEntityEV_SZ_targetszTarget31 );
    
    if( 
equalszTargetSTART ) )
        
Timer_Startid );
    else if( 
equalszTargetSTOP ) )
        
Timer_Stopid );
}

public 
Timer_Start( const id ) {
    if( 
g_flStartTimeid ] )
        return;
    
    
g_flStartTimeid ] = get_gametime( );
    
    
SendSayTextid"^4[XJ]^1 You have started the timer!" );
}

Timer_Stop( const id ) {
    if( !
g_flStartTimeid ] )
        return;
    
    new 
szTime15 ], szMessage128 ];
    
ClimbtimeToString( ( get_gametime( ) - g_flStartTimeid ] - g_flStartDelay ), szTime14 );
    
    
g_flStartTimeid ] = 0.0;
    
    
formatexszMessage127"^4[XJ]^1 You finished the map in:^3 %s^1! Congratulations."szTime );
    
    
SendSayTextidszMessage );
    
    new 
iPlayers32 ], iNum;
    
get_playersiPlayersiNum"b" );
    
    if( 
iNum ) {
        new 
szNick32 ], iPlayer;
        
get_user_nameidszNick31 );
        
        
formatexszMessage127"^4[XJ]^3 %s^1 has finished the map in:^3 %s^1!"szNickszTime );
        
        for( new 
iiNumi++ ) {
            
iPlayer iPlayers];
            
        
//    if( ( 1 << entity_get_int( iPlayer, EV_INT_iuser1 ) ) & ( ( 1 << 1 ) | ( 1 << 2 ) | ( 1 << 4 ) ) &&
            
if( id == entity_get_intiPlayerEV_INT_iuser2 ) )
                
SendSayTextiPlayerszMessage );
        }
    }
}

ClimbtimeToString( const Float:flClimbTimeszOutPut[ ], const iLen ) {
    new 
iMinutes floatroundflClimbTime 60.0floatround_floor );
    new 
iSeconds floatroundflClimbTime iMinutes 60floatround_floor );
    new 
iMiliSeconds floatround( ( flClimbTime - ( iMinutes 60 iSeconds ) ) * 100floatround_floor );
    
    
formatexszOutPutiLen"%02i:%02i.%02i"iMinutesiSecondsiMiliSeconds );
}

SendSayText( const id, const szMessage[ ] ) {
    
message_beginMSG_ONE_UNRELIABLEg_iMsgSayText_id );
    
write_byteid );
    
write_stringszMessage );
    
message_end( );

__________________
xPaw is offline