Listing certain players
#1

Hey, need help with listing players in a class, example, every player in the police class can be listed by doing /policelist or something like that, if someone can help me with that, thanks
Reply
#2

you didn't provide any code what so ever!!
what variable do the police use
pawn Код:
new AStr[MAX_PLAYER_NAME + 4],FStr[240];
for(new i=0; i < MAX_PLAYERS; i++)
     {
          if(IsPlayerConnected(i) && gTeam[i] == POLICE)
               {
                    new name[MAX_PLAYER_NAME];
                    GetPlayerName(i, name, sizeof(name));
                    format(AStr, sizeof(AStr), "%s(%d)\n",name,i);
                    strcat(FStr, AStr, sizeof(FStr));
               }
     }
ShowPlayerDialog(playerid, 4684, DIALOG_STYLE_MSGBOX, "PoliceList", FStr, "Close", "");
Reply
#3

pawn Код:
for(new i ; i < MAX_PLAYERS ; i++ )
{
   if(IsPlayerConnected( i ))
   {
         if( My_Enum[ i ][ pTeamOrClass ] == TEAM_POLICE )
         {
             printf("%d", i);
         }
    }
}
Something like that, where you change the condition of the players to be included to your own.
Reply
#4

how can i make it into a command, and the define for police is police, so gTeam[playerid] == POLICE
Reply
#5

just copy the exact code inside a CMD!
Reply
#6

Here's a command.
pawn Код:
#define POLICE_CLASS 1 //Change the classid to yours.
new pTeam[MAX_PLAYERS];

public OnPlayerRequestClass(playerid, classid)
{
 if(classid == POLICE_CLASS)
 {
  pTeam[playerid] = POLICE_CLASS;
 }
 return 1;
}

CMD:policelist(playerid, params[])
{
 new str[30], Lname[MAX_PLAYER_NAME], str2[128];
 SendClientMessage(playerid, 0xFF0000FF, "__________________________________________");
 SendClientMessage(playerid, 0xFF0000FF, "                     Online Cops");
 SendClientMessage(playerid, -1, "");
 for(new i; i< GetMaxPlayers(); i++)
 {
  if(!IsPlayerConnected(i)) continue;
  if(pTeam[i] == POLICE_CLASS)
  {
   GetPlayerName(i, Lname, sizeof(Lname));
   format(str, sizeof(str), "%s (ID:%d)\n", Lname, i);
   strcat(str2, str, sizeof(str2));
  }
 }
 SendClientMessage(playerid, 0xFF0000, str2);
 SendClientMessage(playerid, 0xFF0000FF, "_________________________________________");
 return 1;
}
Not tested!
Reply
#7

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
just copy the exact code inside a CMD!
Thanks man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)