Raised This Month: $ Target: $400
 0% 

execute a comand on a team


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-02-2009 , 21:50   Re: execute a comand on a team
Reply With Quote #4

Quote:
Originally Posted by SnoW View Post
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_playersiPlayers iNum ,"ae" ,"CT" );
//get_players( iPlayers , iNum  ,"ae" ,"TERRORIST" )

for( new 0iNum i++)
{
    
//slay iPlayers[i];

__________________

Last edited by Bugsy; 03-02-2009 at 21:59.
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode