SA-MP Forums Archive
Listing certain players - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Listing certain players (/showthread.php?tid=436666)



Listing certain players - BossZk - 12.05.2013

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


Re: Listing certain players - park4bmx - 12.05.2013

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", "");



Re: Listing certain players - RajatPawar - 12.05.2013

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.


Re: Listing certain players - BossZk - 12.05.2013

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


Re: Listing certain players - park4bmx - 12.05.2013

just copy the exact code inside a CMD!


Re: Listing certain players - Lordzy - 12.05.2013

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!


Re: Listing certain players - BossZk - 12.05.2013

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