Raised This Month: $ Target: $400
 0% 

execute a comand on a team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rufee
Junior Member
Join Date: Aug 2008
Location: Lithuania
Old 03-02-2009 , 11:14   execute a comand on a team
Reply With Quote #1

how to execute a comand on the whole team ?
for example slaying CT
rufee is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-02-2009 , 11:17   Re: execute a comand on a team
Reply With Quote #2

Quote:
Originally Posted by rufee View Post
how to execute a comand on the whole team ?
for example slaying CT
http://www.amxmodx.org/funcwiki.php?go=func&id=174

Then use a for loop for all players

PHP Code:
new iPlayers[32];
new 
iNum;
get_playersiPlayers iNum ,"e" ,"CT" );
//get_players( iPlayers , iNum  ,"e" ,"TERRORIST" )

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

__________________

Last edited by Bugsy; 03-02-2009 at 11:20.
Bugsy is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-02-2009 , 13:13   Re: execute a comand on a team
Reply With Quote #3

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.

Last edited by SnoW; 03-03-2009 at 01:49.
SnoW is offline
Send a message via MSN to SnoW
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-02-2009 , 13:23   Re: execute a comand on a team
Reply With Quote #4

@SnoW, you forgot to check the team.
Code:
new g_MaxPlayers; // Global array which will hold the numer of max players   public plugin_init()         g_MaxPlayers = get_maxplayers(); // Get max players and store it in our array   public YourFunction() {         for (new Client = 1; Client <= g_MaxPlayers; Client++)         {                 if (!is_user_connected(Client))                         continue;                 switch (get_user_team(Client))                 {                         case 1: // Terrorist                         {                                 // Your code (note that ID is Client)                         }                         case 2: // CT                         {                                 // Your code                         }                         case 3: // Spectator                         {                                 // Your code                         }                 }         } }
__________________

Last edited by hleV; 03-03-2009 at 07:48. Reason: Fixed.
hleV is offline
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 #5

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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-02-2009 , 22:34   Re: execute a comand on a team
Reply With Quote #6

@Snow & HleV

I think you both will get runtime errors for checking the team of an empty slot.

(I always get runtime errors for checking the team of empty slots)
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-03-2009 , 00:10   Re: execute a comand on a team
Reply With Quote #7

@hlev, this is not an array and may confuse people. I'm sure you are aware and it is just a typo.

PHP Code:
new g_MaxPlayers;  // Global array which will hold the numer of max players
g_MaxPlayers get_maxplayers();  // Get max players and store it in our array 
Quote:
Originally Posted by fysiks View Post
@Snow & HleV

I think you both will get runtime errors for checking the team of an empty slot.

(I always get runtime errors for checking the team of empty slots)
In that case, an is_user_connected() will also be in order.
__________________

Last edited by Bugsy; 03-03-2009 at 00:15.
Bugsy is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-03-2009 , 01:58   Re: execute a comand on a team
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
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?
This guy is asking a way how to use a simple native or something like that. I'm just saying that for people who are starting scripting can be little hard to understand the best and optimized ways. I wouldn't start explaining them something todally advanced, if there's a lot of easier way to understand, what would work almost as good as the others. Just thought that if he gots some problems on your way, he could use the other.
Quote:
Originally Posted by fysiks View Post
@Snow & HleV

I think you both will get runtime errors for checking the team of an empty slot.

(I always get runtime errors for checking the team of empty slots)
Quote:
Originally Posted by Bugsy View Post
In that case, an is_user_connected() will also be in order.
Somehow you probably didn't see that I first checked if the player is alive, and after that the team. Ofc connected check could be little better here like for example, but he was talking about slaying, so slaying dead players wouldn't be that good.

Last edited by SnoW; 03-03-2009 at 02:01.
SnoW is offline
Send a message via MSN to SnoW
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-03-2009 , 07:05   Re: execute a comand on a team
Reply With Quote #9

@Snow: I'm assuming, in an if statement, that all conditions are evaluated before returning a result. With that assumption an empty slot would give 0 for alive and runtime error for team. I've tried asking if this is how it actually does work but I was not given a clear answer.

Also, you would require checking if they are connected if the command does not require being alive in which case you would need to use is_user_connected(). Basically, I was thinking of the general case of "an action on a team" and not just the example he happened to think of.

That's my 3 cents .
__________________
fysiks is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-03-2009 , 07:17   Re: execute a comand on a team
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
@Snow: I'm assuming, in an if statement, that all conditions are evaluated before returning a result. With that assumption an empty slot would give 0 for alive and runtime error for team. I've tried asking if this is how it actually does work but I was not given a clear answer.

Also, you would require checking if they are connected if the command does not require being alive in which case you would need to use is_user_connected(). Basically, I was thinking of the general case of "an action on a team" and not just the example he happened to think of.

That's my 3 cents .
For first one, No. If the first one is false(or any other) it won't check the rest of them. I think there's pretty good logic in that, why to check them, if it's known already that the statement is false?
For second, Already said that ye maybe the connect check would be better here cause it's an example, but I just coded it how I could code it in a plugin. Using both checks would be ridicilous and using connect check and slaying after that didn't sound good either.

Last edited by SnoW; 03-03-2009 at 07:22.
SnoW is offline
Send a message via MSN to SnoW
Reply


Thread Tools
Display Modes

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