List a foreach() or while() in one line
#2

pawn Код:
CMD:admins(playerid, params[])
{
    new
        bool:any,
        namestring[24],
        adminstring[256] = "Admins: ";
    ;
    any = false;
    foreach(Character, i)
    {
        if(PlayerInfo[i][pAdmin])
        {
            if(any == true)
            {
                strins(adminstring,", ",strlen(adminstring));
            }
            GetPlayerName(i,namestring,24);
            strins(adminstring,namestring,strlen(adminstring));
            any = true;
        }
    }

    if(!any)
    {
        strins(adminstring,"none.",strlen(adminstring));
    }

    SendClientMessage(playerid,0xAFAFAFAA,adminstring);
    return 1;
}
note: this code uses <zcmd> and <foreach>

if you do not have <foreach> included in your script, replace the foreach(Character, i) line, and add another level to the statement
pawn Код:
for(new i; i < MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i))
        {
             if(PlayerInfo[i][pAdmin])
            {
                if(any == true)
                {
                    strins(adminstring,", ",strlen(adminstring));
                }
                GetPlayerName(i,namestring,24);
                strins(adminstring,namestring,strlen(adminstring));
                any = true;
            }
        }
    }
Reply


Messages In This Thread
List a foreach() or while() in one line - by hanzen - 21.12.2010, 10:06
Re: List a foreach() or while() in one line - by Rachael - 21.12.2010, 10:16
Re: List a foreach() or while() in one line - by hanzen - 21.12.2010, 10:37
Re: List a foreach() or while() in one line - by Rachael - 21.12.2010, 10:42

Forum Jump:


Users browsing this thread: 1 Guest(s)