SA-MP Forums Archive
loop all online names - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: loop all online names (/showthread.php?tid=232147)



loop all online names - BlackWolf120 - 27.02.2011

hi,

im just trying to script an admin function that lists all names of all players currently on the server.
This should be displayed via SendClientMessage.
But how to get all names? How to loop this?
This is what i got so far:

pawn Код:
if (strcmp("/iplist", cmdtext, true) == 0)
{
if(Spieler[playerid][AdminLevel] > 0)//checking if player is admin
{
for(new i; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {

new String[128],name[ 30 ];
GetPlayerName( i, name, 30);
format(String,sizeof(String),"Player %s",name);
SendClientMessage(playerid,0xAA3333AA,String);
}
}

}else return SendClientMessage(playerid, 0xFF0000FF, "You are not an admin!");

return 1;
}
e.g. if there are 3 players online: tom,betty,jack.
In this case it would send 3 ClientMessages to the admin that wrote this command like this.
PHP код:
Player tom
Player betty
Player jack 
regards...


Re: loop all online names - admantis - 27.02.2011

I do not understand what's wrong.


AW: loop all online names - BlackWolf120 - 27.02.2011

it only sends me one single name (my name only) and not all names of all players currently playing on the server.


Re: loop all online names - Retardedwolf - 27.02.2011

pawn Код:
COMMAND:iplist( playerid, params[ ] )
{
    if ( Spieler[ playerid ][ AdminLevel ] > 0 )
    {
        new
            string[ MAX_PLAYER_NAME + 10 ],
            name[ MAX_PLAYER_NAME ]
        ;

        SendClientMessage( playerid, 0xFFFFFFAA, "List of players :" );
        foreach(Player,i)
        {
            GetPlayerName( i, name, sizeof( name ) );
            format( string, sizeof( string ), "Player %s", name );
            SendClientMessage( playerid, 0xFFFFFFAA, string );
        }
    }
    else
        SendClientMessage( playerid, 0xFFFFFFAA, "You are not an administrator !" );
    return 1;
}

To recommend ( new ) scripters to use zcmd/ycmd + foreach. I provided the code for you. I doubt that you will use it as you're using a gf edit ( afaik ) and you won't want to convert all the commands.


AW: loop all online names - BlackWolf120 - 27.02.2011

thx for ur code.
I dont use a gf edit.
Scripting a TDM mode (i started from zero, scripting everything myself in order to learn sth)


Re: loop all online names - (SF)Noobanatior - 27.02.2011

this is how i do it
pawn Код:
if (strcmp("/iplist", cmdtext, true) == 0){
        if(Spieler[playerid][AdminLevel] == 0)return SendClientMessage(playerid, 0xFF0000FF, "You are not an admin!");
        SendClientMessage(playerid, COLOUR_GOOD, "Players Online:");
        new x;
new String[128],name[MAX_PLAYER_NAME];
        for(new i; i < MAX_PLAYERS; i++){
            if(!IsPlayerConnected(i))continue;
           
            GetPlayerName( i, name, MAX_PLAYER_NAME);
            format(String, 128, "%s%s(%d)", String,name,i);
            x++;
            if(x > 4) {
                SendClientMessage(playerid, 0xABCDEEFF, String);
                x = 0;
                format(String, 128, "");
            }
            else {
                format(String, 128, "%s, ", String);
            }

        }
        if(x <= 4 && x > 0) {
            String[strlen(String)-2] = '.';
            SendClientMessage(playerid, 0xABCDEEFF, String);
        }
        return 1;
    }
5 names per line