PHP Code:
#include <amxmodx>
#include <engine>
#define DELAY 0.5
#define HUD_STAY DELAY + 0.1
#define TASK_HUD 239472384723
#define TASK_GETNUM 238479923748
enum _:CVARS {
RED,
GREEN,
BLUE,
LOCATION
};
enum _:TEAMS {
TE,
CT
};
new g_pCvars[ CVARS ];
new const Float:g_flCoords[ ][ 2 ] = {
{ 0.02, -1.0 },
{ 0.10, 0.40 },
{ 0.28, 0.00 },
{ 0.57, 0.00 },
{ 0.57, 0.45 },
{ 0.57, 0.78 },
{ 0.27, 0.78 },
{ 0.01, 0.78 },
{ 0.31, 0.36 }
}
public plugin_init( ) {
register_plugin( "Players Remaining", "1.0", "xPaw" );
g_pCvars[ RED ] = register_cvar( "amx_pr_red", "0" );
g_pCvars[ GREEN ] = register_cvar( "amx_pr_green", "127" );
g_pCvars[ BLUE ] = register_cvar( "amx_pr_blue", "255" );
g_pCvars[ LOCATION ] = register_cvar( "amx_pr_location", "5" );
register_event( "HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0" );
register_logevent("logevent_round_end", 2, "1=Round_End");
}
public Event_HLTV_New_Round( )
{
set_task(150.0, "ShowHUD", TASK_HUD)
}
public ShowHUD()
{
new iEntity = create_entity( "info_target" );
if( is_valid_ent( iEntity ) ) {
entity_set_string( iEntity, EV_SZ_classname, "PlayersRemainThinker" );
entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + DELAY );
register_think( "PlayersRemainThinker", "FwdThink" );
} else
set_task( DELAY, "GetNum", TASK_GETNUM, _, _, "b" );
}
public FwdThink(iEntity)
{
GetNum( );
entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + DELAY );
}
public logevent_round_end()
{
new ent = -1
while((ent = find_ent_by_class(ent, "PlayersRemainThinker")))
{
remove_entity(ent)
}
if(task_exists(TASK_GETNUM)) remove_task(TASK_GETNUM);
if(task_exists(TASK_HUD)) remove_task(TASK_HUD);
}
public GetNum( ) {
new iPlayers[ 32 ], iNum[ TEAMS ];
get_players( iPlayers, iNum[ TE ], "ae", "TERRORIST" );
get_players( iPlayers, iNum[ CT ], "ae", "CT" );
if( iNum[ TE ] > 0 || iNum[ CT ] > 0 ) {
new iCvars[ CVARS ];
iCvars[ RED ] = get_pcvar_num( g_pCvars[ RED ] );
iCvars[ GREEN ] = get_pcvar_num( g_pCvars[ GREEN ] );
iCvars[ BLUE ] = get_pcvar_num( g_pCvars[ BLUE ] );
iCvars[ LOCATION ] = get_pcvar_num( g_pCvars[ LOCATION ] );
if( iCvars[ LOCATION ] > sizeof( g_flCoords ) - 1 ) {
set_pcvar_num( g_pCvars[ LOCATION ], 1 );
iCvars[ LOCATION ] = 1;
}
set_hudmessage( iCvars[ RED ], iCvars[ GREEN ], iCvars[ BLUE ],
g_flCoords[ iCvars[ LOCATION ] ][ 0 ], g_flCoords[ iCvars[ LOCATION ] ][ 1 ], 0, HUD_STAY, HUD_STAY, 0.0, 0.0, 3 );
show_hudmessage( 0, "Players Remaining^nTE: %i^nCT: %i", iNum[ TE ], iNum[ CT ] );
}
}
BTW, the nature of the problem is that you guys have no idea how to use set_task. Atleast look at the description on wiki/api page and example in exiting plugins.