Quote:
Originally Posted by addons_zz
Yes. Nice work.
Do not mix the min and max ids with player team. Why do you checked if the player was alive? Dead players do not have team?
If the player was not connect, he would not be selected because every time he disconnect/connect he is added/removed from the selection.
I attached the full code.
|
ty again, 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;
}
new iRandomID;
//Keep looping while there is players that haven't yet been selected.
while( g_Players != g_Selected )
{
//Get random player id
iRandomID = random_num( g_Min, g_Max );
//If player is connected and has not yet been selected
if( ( g_Players & ( 1 << iRandomID ) )
&& !( g_Selected & ( 1 << iRandomID ) ) )
{
//Set bit for this ID in g_Selected bit-field so the player will now be considered selected
g_Selected |= ( 1 << iRandomID );
if( is_user_alive( iRandomID + 1 ) && cs_get_user_team( iRandomID + 1 ) == CS_TEAM_CT )
{
return ( iRandomID + 1 );
}
else
{
return GetRandomPlayer()
}
}
}
//All players have already been selected.
/*if( g_Players == g_Selected )*/ // no need for this check the while loop will already do that for us.
return -1; // making this -1 so we now we will know when all players are selected
}
GetAliveCt()
{
new iCt, id
for (id = 1; id <= g_MaxPlayers; id++)
{
if (is_user_alive( id ) && cs_get_user_team( id ) == CS_TEAM_CT)
iCt++
}
return iCt;
}
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.
edit:
https://forums.alliedmods.net/showpo...91&postcount=7
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 ?
__________________