[Help] GetTeamMembers
#1

Hello , recently i was watching tutorials and i saw someone who posted on how to CountTeamPlayers and here is its code.
PHP код:
stock CountTeamPlayers(team)
{
    new 
count;
    for(new 
iMAX_PLAYERSi++)
    {
        if( 
IsPlayerConnected(i)//if player is connected
            
&& GetPlayerTeam(i) == team)//if team id matches
        
{
            
count++;//add one to the count
        
}
    }
    return 
count;

I want to make a code that when player type /team he gets his team members in dialog . how to do it?
Reply
#2

if (strcmp(cmd, "/teamlist", true) == 0)
{
Код:
if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][team] == 1 || PlayerInfo[playerid][pLeader] == 1)
	        {
				SendClientMessage(playerid, COLOR_GRAD1, "PD officers online:");
				for(new i = 0; i < MAX_PLAYERS; i++)
				{
					if(IsPlayerConnected(i))
					{
				    	if(PlayerInfo[i][team] == 1 )
				    	{
				    	    GetPlayerName(i, sendername, sizeof(sendername));
				    	        format(string, 256, "** Member ** %s", sendername);
					SendClientMessage(playerid, COLOR_GRAD2, string);
					}

					}
				}
			}
		return 1;
	}
Reply
#3

Untested //

pawn Код:
CMD:team(playerid, params[])
{
   new count = 0, String[128];

   for(new i = 0; i < MAX_PLAYERS; i ++)
   {
      if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid))
      {
          new yname[MAX_PLAYER_NAME];
          GetPlayerName(i, yname, sizeof(yname));
          format(String, sizeof(String), "%s (%d)\n",yname,i);
          count++; //optional
      }
   }
   ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX,"team player names",String ,"Ok","");
   return 1;
}
Reply
#4

@Ryz...that will only show the teamplayer with the highest playerID...

pawn Код:
CMD:team(playerid, params[])
{
   new String[256], yname[MAX_PLAYER_NAME];
   for(new i = 0; i < MAX_PLAYERS; i ++)
   {
      if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid))
      {          
          GetPlayerName(i, yname, sizeof(yname));
          format(String, sizeof(String), "%s%s (%d)\n", String, yname, i);
      }
   }
   ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX,"Your Team:",String ,"Ok","");
   return 1;
}
Reply
#5

Quote:
Originally Posted by Schneider
Посмотреть сообщение
@Ryz...that will only show the teamplayer with the highest playerID...

pawn Код:
CMD:team(playerid, params[])
{
   new String[256], yname[MAX_PLAYER_NAME];
   for(new i = 0; i < MAX_PLAYERS; i ++)
   {
      if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid))
      {          
          GetPlayerName(i, yname, sizeof(yname));
          format(String, sizeof(String), "%s%s (%d)\n", String, yname, i);
      }
   }
   ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX,"Your Team:",String ,"Ok","");
   return 1;
}
ohh my bad..
Reply
#6

and how to make a function to get another gang members like the gang no 2 . Just give me the code which will check only team 1 or team 2 members (or any specific team.).
Reply
#7

Not tested. With this command you can use /team [number] or if you don't add a number it will show your own team.
Also, change the value this line "if((team < 0) || (team > 4))" to the highest team-id. ( i just took 4 as an example = 5 teams (0, 1, 2, 3, 4)

pawn Код:
CMD:team(playerid, params[])
{
    new String[256] = " ", yname[MAX_PLAYER_NAME], team;
    if(sscanf(params, "i", team)) team = GetPlayerTeam(playerid);
    if((team < 0) || (team > 4))  return SendClientMessage(playerid, -1, "Error: Invalid team-ID");  // change his to highest team ID.
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == team)
        {          
            GetPlayerName(i, yname, sizeof(yname));
            format(String, sizeof(String), "%s%s (%d)\n", String, yname, i);
        }
    }
    ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX,"Team:",String ,"Ok","");
    return 1;
}
Reply
#8

Actually i want a function like if player type /gang1 so he get list of the members of first gang .(GePlayerTeam(i) == 1) if i use this no dialog appears.
There won't be any choice to type the gang number . Player can only check gang no.1 members by /gang1.
Reply
#9

why would you make 4(?) different commands /gang1, /gang2, /gang3, /gang4 when you can do it with 1 command? /gang [number] ?
Reply
#10

because i just want to set this option to specific gang not for all . So please post the code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)