need help /admins
#1

hi,it show it two times how to make it show one time


Код:
CMD:admins(playerid, params[])
{
    new bool:Count;
    new str[45], Admin[MAX_PLAYER_NAME], str2[128];
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if (APlayerData[i][PlayerLevel] >= 1) // replace with ur variable
        {
            GetPlayerName(i, Admin, MAX_PLAYER_NAME);
            format(str2, sizeof(str2), "Current Administrators Online");
            format(str, sizeof(str), "%s ",  Admin);
            SendClientMessage(playerid, -1, str2);
            SendClientMessage(playerid, -1, str);
            Count = true;
        }
        if(IsOnAdminDuty[i] == true)
        {
            new aname[24],astring[124];
            GetPlayerName(playerid,aname,sizeof(aname));
            format(astring,sizeof(astring),"%s %s (Duty)",aname);
            SendClientMessage(playerid,-1,astring);
         }
    }
    if(!Count) SendClientMessage(playerid, -1, "No Administrators Online!");
    return 1;
}
Reply
#2

pawn Код:
CMD:admins(playerid, params[])
{
    new Count;
    new str[45], Admin[MAX_PLAYER_NAME];
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if (APlayerData[i][PlayerLevel] >= 1) // replace with ur variable
        {
            Count++;
            GetPlayerName(i, Admin, MAX_PLAYER_NAME);
            SendClientMessage(playerid, -1, "Current Administrators Online");
            if(!IsOnAdminDuty[i]) format(str, sizeof(str), "Level %d - %s - Off Admin Duty", APlayerData[i][PlayerLevel], Admin);
            else if(IsOnAdminDuty[i]) format(str, sizeof(str), "Level %d - %s - On Admin Duty", APlayerData[i][PlayerLevel], Admin);
            SendClientMessage(playerid, -1, str);
        }
    }
    if(Count < 1) SendClientMessage(playerid, -1, "No Administrators Online!");
    return 1;
}
So many ways you could save lines. That should work for you, if all of the other variables are correct.
Reply
#3

Ty.i like it
Reply
#4

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
CMD:admins(playerid, params[])
{
    new Count;
    new str[45], Admin[MAX_PLAYER_NAME];
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if (APlayerData[i][PlayerLevel] >= 1) // replace with ur variable
        {
            Count++;
            GetPlayerName(i, Admin, MAX_PLAYER_NAME);
            SendClientMessage(playerid, -1, "Current Administrators Online");
            if(!IsOnAdminDuty[i]) format(str, sizeof(str), "Level %d - %s - Off Admin Duty", APlayerData[i][PlayerLevel], Admin);
            else if(IsOnAdminDuty[i]) format(str, sizeof(str), "Level %d - %s - On Admin Duty", APlayerData[i][PlayerLevel], Admin);
            SendClientMessage(playerid, -1, str);
        }
    }
    if(Count < 1) SendClientMessage(playerid, -1, "No Administrators Online!");
    return 1;
}
So many ways you could save lines. That should work for you, if all of the other variables are correct.
I suppose you want "Current Administrators Online" to only be sent once above the loop. Furthermore I suggest to use foreach, which is faster, instead of your loop.


Код:
CMD:admins(playerid, params[])
{
    new 
          Count,
          str[45], 
          Admin[MAX_PLAYER_NAME]
          ;
    
    SendClientMessage(playerid, -1, "Current Administrators Online:");
    foreach (new i : Player)
    {
        if (APlayerData[i][PlayerLevel] >= 1) // replace with ur variable
        {
			Count++;
            GetPlayerName(i, Admin, MAX_PLAYER_NAME);
			format(str, sizeof(str), "Level %d - %s - %s, APlayerData[i][PlayerLevel], Admin, IsOnAdminDuty[i] ? ("On Admin Duty") : ("Off Admin Duty"));
            SendClientMessage(playerid, -1, str);
        }
    }
    if(Count < 1) SendClientMessage(playerid, -1, "No Administrators Online!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)