SA-MP Forums Archive
/playerlist Only one players shows up ;/ - 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: /playerlist Only one players shows up ;/ (/showthread.php?tid=266919)



/playerlist Only one players shows up ;/ - Moron - 06.07.2011

I was making a command to show players for a specific group and i wanted to test it on NPC's, but only one of 4 NPC's show up ;/

Код:
    if(!strcmp(cmdtext, "/testing", true))
	{
	new name[MAX_PLAYER_NAME];
	for(new i = 0; i <MAX_PLAYERS; i++){
	if(IsPlayerNPC(i)){
	new lol[256] = "* ";

	GetPlayerName(i,name,MAX_PLAYER_NAME);
	format(lol,256,"{FFFFFF}%s {64B500}%s,",lol,name);
	ShowPlayerDialog(playerid,100,DIALOG_STYLE_MSGBOX,"{64B500}Online:",lol,"OK","Exit");
	}
	}
	return 1;
	}



Re: /playerlist Only one players shows up ;/ - Moron - 06.07.2011

Oh yes if i change the GUI with
Код:
SendClientMessage(playerid,COLOR_BLUE,lol);
it works fine, but i still need GUI ;/ HELP


Re: /playerlist Only one players shows up ;/ - Shadoww5 - 06.07.2011

What is this ? o.O

PHP код:
new lol[256] = "* "



Re: /playerlist Only one players shows up ;/ - Donya - 06.07.2011

pawn Код:
if(!strcmp(cmdtext, "/testing", true))
{
    new name[MAX_PLAYER_NAME], lol[256] = "* ";
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if(IsPlayerNPC(i)) continue;
        GetPlayerName(i,name,MAX_PLAYER_NAME);
        format(lol, 256, "{FFFFFF}%s {64B500}%s,", lol, name);
    }
    ShowPlayerDialog(playerid,100,DIALOG_STYLE_MSGBOX,"{64B500}Online:",lol,"OK","Exit");
    return 1;
}



Re: /playerlist Only one players shows up ;/ - Shadoww5 - 06.07.2011

PHP код:
if(!strcmp(cmdtext"/testing"true))
{
    new 
name[MAX_PLAYER_NAME], lol[256], string[80];
    for(new 
0<MAX_PLAYERSi++)
    {
        if(!
IsPlayerNPC(i)) continue;
        
GetPlayerName(inameMAX_PLAYER_NAME);
        
format(stringsizeof string,"{FFFFFF}%d {64B500}%s,"iname);
        
strcat(lol,string);
    }
    
ShowPlayerDialog(playerid,100,DIALOG_STYLE_MSGBOX,"{64B500}Online:",lol,"OK","Exit");
    return 
1;




Re: /playerlist Only one players shows up ;/ - Donya - 06.07.2011

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
PHP код:
if(!strcmp(cmdtext"/testing"true))
{
    new 
name[MAX_PLAYER_NAME], lol[256];
    for(new 
0<MAX_PLAYERSi++)
    {
        if(!
IsPlayerNPC(i)) continue;
        
GetPlayerName(i,name,MAX_PLAYER_NAME);
        
strcat(lol,"{FFFFFF}%s {64B500}%s,",i,name);
    }
    
ShowPlayerDialog(playerid,100,DIALOG_STYLE_MSGBOX,"{64B500}Online:",lol,"OK","Exit");
    return 
1;

you cant do strcat(lol,"{FFFFFF}%s {64B500}%s,",i,name);

so either way, mine would be the working one and the fastest.. cus if u do format then strcat = slower..


Re: /playerlist Only one players shows up ;/ - Shadoww5 - 06.07.2011

Oh sorry !

Now it's correct:

PHP код:
if(!strcmp(cmdtext"/testing"true))
{
    new 
name[MAX_PLAYER_NAME], lol[256], string[80];
    for(new 
0<MAX_PLAYERSi++)
    {
        if(!
IsPlayerNPC(i)) continue;
        
GetPlayerName(inameMAX_PLAYER_NAME);
        
format(stringsizeof string"{FFFFFF}%d {64B500}%s,"iname);
        
strcat(lol,string);
    }
    
ShowPlayerDialog(playerid,100,DIALOG_STYLE_MSGBOX,"{64B500}Online:",lol,"OK","Exit");
    return 
1;




Re: /playerlist Only one players shows up ;/ - Ricop522 - 06.07.2011

Test this..
PHP код:
    if(strcmp(cmd"/testing"true) == 0//by Ricop522
    
{
        new 
playersonline[500], playersonline2[504];
        new 
plName[MAX_PLAYER_NAME], Ricop522  0;
        for( ; 
Ricop522 MAX_PLAYERS; ++Ricop522)
        {
            if(
IsPlayerConnected(i)) {
                
GetPlayerName(iplNamesizeof(plName));
                
format(playersonlinesizeof(playersonline), "{FFFFFF}%i {64B500}%s\n"Ricop522plName);
                
strcat(playersonline2,playersonline);
            }
        }
        
ShowPlayerDialog(playerid,100,DIALOG_STYLE_LIST,"Players On",playersonline2,"Exit","");
        return 
0x01;
    } 



Re: /playerlist Only one players shows up ;/ - Donya - 06.07.2011

omg.. did u people not read my post.. and why are you people using the php code tag..


Re: /playerlist Only one players shows up ;/ - TheGarfield - 06.07.2011

Quote:
Originally Posted by Ricop522
Посмотреть сообщение
Test this..
PHP код:
    if(strcmp(cmd"/testing"true) == 0//by Ricop522
    
{
        new 
playersonline[500], playersonline2[504];
        static 
plName[MAX_PLAYER_NAME], Ricop522  0;
        for( ; 
Ricop522 MAX_PLAYERS; ++Ricop522)
        {
            if(
IsPlayerConnected(i)) {
                
GetPlayerName(iplNamesizeof(plName));
                
format(playersonlinesizeof(playersonline), "{FFFFFF}%i {64B500}%s\n"Ricop522plName);
                
strcat(playersonline2,playersonline);
            }
        }
        
ShowPlayerDialog(playerid,100,DIALOG_STYLE_LIST,"Players On",playersonline2,"Exit","");
        return 
0x01;
    } 
you can't use variables statics in loops and appers error: Undefined Symbol "i"

pawn Код:
if(strcmp(cmd, "/testing", true) == 0) //by Garfield
    {
        new playersonline[500], playersonline2[MAX_PLAYERS*2];
        new plName[MAX_PLAYER_NAME];
        for(new i ; i < MAX_PLAYERS; ++i)
        {
            if(IsPlayerConnected(i ))
            {
                GetPlayerName(i, plName, sizeof(plName));
                format(playersonline, sizeof(playersonline), "{FFFFFF}%i {64B500}%s\n", i, plName);
                strcat(playersonline2,playersonline);
            }
        }
        ShowPlayerDialog(playerid,100,DIALOG_STYLE_LIST,"Players On",playersonline2,"Exit","");
        return 1;
    }
[...]


Re: /playerlist Only one players shows up ;/ - Ricop522 - 06.07.2011

I say:
"I think this works."

I retired this from my gamemode, the /list of the cars .
You just copy my code and remove a little things.


Att, Ricop522.


Re: /playerlist Only one players shows up ;/ - Donya - 06.07.2011

Quote:
Originally Posted by Ricop522
Посмотреть сообщение
I say:
"I think this works."

I retired this from my gamemode, the /list of the cars .
You just copy my code and remove a little things.


Att, Ricop522.
he fixed it. your code would've actually returned an error.

Quote:
Originally Posted by Donya
Посмотреть сообщение
pawn Код:
if(!strcmp(cmdtext, "/testing", true))
{
    new name[MAX_PLAYER_NAME], lol[256] = "* ";
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if(IsPlayerNPC(i)) continue;
        GetPlayerName(i,name,MAX_PLAYER_NAME);
        format(lol, 256, "{FFFFFF}%s {64B500}%s,", lol, name);
    }
    ShowPlayerDialog(playerid,100,DIALOG_STYLE_MSGBOX,"{64B500}Online:",lol,"OK","Exit");
    return 1;
}



Re: /playerlist Only one players shows up ;/ - BigETI - 06.07.2011

I gonna clear up these things:
pawn Код:
if(!strcmp(cmdtext, "/testing", true))
{
    new bool:check = false, lol[1024] = "* ";
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && IsPlayerNPC(i)) //You can add here another checks later.
        {
            new name[MAX_PLAYER_NAME];
            GetPlayerName(i, name, sizeof(name));
            if(!check)
            {
                format(lol, sizeof(lol), "{FFFFFF}%s {64B500}%s", lol, name);
                state = true;
            }
            else format(lol, sizeof(lol),"%s, %s", lol, name);
        }
    }
    if(check) ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "{64B500}Online:", lol, "OK", "Exit");
    else ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "{64B500}Online:", "{FF0000}Nobody", "OK", "Exit");
    return 1;
}



Re: /playerlist Only one players shows up ;/ - Shadoww5 - 06.07.2011

Quote:
Originally Posted by BigETI
Посмотреть сообщение
I gonna clear up these things:
pawn Код:
if(!strcmp(cmdtext, "/testing", true))
{
    new bool:check = false, lol[1024] = "* ";
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && IsPlayerNPC(i)) //You can add here another checks later.
        {
            new name[MAX_PLAYER_NAME];
            GetPlayerName(i, name, sizeof(name));
            if(!check)
            {
                format(lol, sizeof(lol), "{FFFFFF}%s {64B500}%s", lol, name);
                state = true;
            }
            else format(lol, sizeof(lol),"%s, %s", lol, name);
        }
    }
    if(check) ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "{64B500}Online:", lol, "OK", "Exit");
    else ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "{64B500}Online:", "{FF0000}Nobody", "OK", "Exit");
    return 1;
}
No need to do all this.