Quote:
Originally Posted by JusTGo
i need the played to be alive && ct same time cause he can be in ct team and his dead so i used:
Code:
GetRandomPlayer()
{
//No players(alive && ct) or all have been selected already
if( !g_Players || !GetAliveCt()
/*|| ( g_Players == g_Selected )*/ ) // so it will not return 0 when all players selected selected.
{
return 0;
}
its working perfect now but just some small issuses like for ex:
you call radom 3 times it gives you: 7 3 1 the you call it another time it gives your 7 3 1 its rare but happens or other thing for ex you get: 7 3 1 next time you do random you get 1 7 3 so you have the number 1 selected twice in a row but i guess thats how random_num() works.
|
Nice work. And you can remove the ( g_Players == g_Selected ), because, if all are already selected, should return -1, instead of 0.
Code:
GetRandomPlayer()
{
//No players (alive && ct)
if( !g_Players
|| !GetAliveCt() ) // so it will not return 0 when there is no players to be selected.
{
return 0;
}
Quote:
Originally Posted by JusTGo
Code:
GetMaxMin( &iMin, &iMax )
{
for( new i = 0; i < g_MaxPlayers; i++ )
{
if( g_Players & ( 1 << i ) )
{
if( i < iMin )
{
iMin = i;
}
if( i > iMax )
{
iMax = i;
}
}
}
}
is this okay ?
|
Yes.
Your function GetAliveCt() do not need to count all cts, unless you need the total alive. Then it just could be:
Code:
GetAliveCt()
{
for( new id = 1; id <= g_Max; id++ )
{
if ( is_user_alive( id )
&& cs_get_user_team( id ) == CS_TEAM_CT )
{
return 1
}
}
return 0;
}
But is you need all alive CTs total and their ids, you can use a built-in function which should be faster:
Code:
new players_CT_ids[32]
new players_total_CT_number
get_players(players_CT_ids, players_total_CT_number, "ae", "CT")
Quote:
|
Originally Posted by https://www.amxmodx.org/api/amxmodx/get_players
Optional list of filtering flags:
"a" - do not include dead clients
...
"e" - match with team
|
__________________