Quote:
Originally Posted by SnoW
Won't say this is better, just easier to understand.
Code:
new max_players = get_maxplayers();
for(new id = 1; id < max_players; id++)
{
if(is_user_alive(id) && get_user_team(id) == 1) //1 T, 2 CT
//slay the noob.
}
Edit: Code updated, somehow forgot what this thread was about, lol. Thanks, hleV.
|
From an 'easier to read' standpoint, sure. That code clearly says loop from 1 to max players, if player alive and is on team X, do this.
However, you are looping through more times than needed (1->maxplayers) and checking get_user_team and is_user_alive with each iteration. My method is more proper and efficient, why not get newer coders started using the correct methods?
Check only specific team and player must be alive:
PHP Code:
new iPlayers[32];
new iNum;
//"a" - Don't return dead players
//"e" - Match with passed team
get_players( iPlayers , iNum ,"ae" ,"CT" );
//get_players( iPlayers , iNum ,"ae" ,"TERRORIST" )
for( new i = 0; i < iNum ; i++)
{
//slay iPlayers[i];
}
__________________