Page 1 of 1

[SNIPPET/CODE] How to properly check Team score

Posted: Sun Oct 04, 2026 2:08 pm
by Archive-Poster
Using the next code example i'm going to show you a good way to get team scores, based on my tests, this is working even if is planting bomb/ hostage save, etc ...

First, create 2 new global variables, inside of them will store the actual score of teams:

Code: Select all

new TeroScore;
new CtScore;
Register these events in the plugin_init:

Code: Select all

public plugin_init( )
{

    // Events when Terrorists and Counter-terrorists win ( hostage saved, bomb exploded, all are already included in these ... )            
    register_event("TeamScore", "Event_TeroWin", "a", "1=TERRORIST")
    register_event("TeamScore", "Event_CTWin", "a", "1=CT")

    // This event is called when Round is restarted, we need to reset TeroScore and CtScore variables when the game are restarted.
    register_event("TextMsg", "fwEvGameWillRestart", "a", "2=#Game_will_restart_in")

    // We register a 'test' command to see if is completly work and show the good score:
    register_clcmd( "say /test", "test" );
} 
In Game restart public:

Code: Select all

public fwEvGameWillRestart( )
{
          // We reset the variables at server restart:
          TeroScore = 0;
          CtScore = 0;
} 
We get the real score inside of the events:

Code: Select all

public Event_CTWin( ) CtScore = read_data( 2 );
public Event_TeroWin( ) TeroScore = read_data( 2 );
An example inside of 'test' public:

Code: Select all

public test( id )
{
    client_print( id, print_chat, "Tero score: %i, Ct score: %i", TeroScore, CtScore );
} 
The whole code without comments:

Code: Select all

#include <amxmodx>
            
new TeroScore;
new CtScore;

public plugin_init( )
{
        
    register_event("TeamScore", "Event_TeroWin", "a", "1=TERRORIST")
    register_event("TeamScore", "Event_CTWin", "a", "1=CT")

    register_event("TextMsg", "fwEvGameWillRestart", "a", "2=#Game_will_restart_in")
    
    register_clcmd( "say /test", "test" );
}

public fwEvGameWillRestart( )
{
    TeroScore = 0;
    CtScore = 0;
}

    
public Event_CTWin( ) CtScore = read_data( 2 );
public Event_TeroWin( ) TeroScore = read_data( 2 );


public test( id )
{
    client_print( id, print_chat, "Tero score: %i, Ct score: %i", TeroScore, CtScore );
}