PDA

View Full Version : Players in dialog (format)


FinStar
08/03/2016, 02:54 PM
Hello, I'd like your help, I need to do to show all players who are online dialogue, but only one ID is displayed in the dialogue, knows someone advice?


stock ReturnPlayerName(playerid)
{
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
return pname;
}

stock GetOnLinePlayers()
{
new OnLine;
for(new i, g = GetMaxPlayers(); i < g; i++)
{
if(IsPlayerConnected(i))
OnLine++;
}
return OnLine;
}



CMD:checkall(playerid, params[])
{
new string[200];
new string1[30];
new count=1;
format(string1,sizeof(string1),"Online ( %i )", GetOnLinePlayers());

for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Country1[30], City1[30], IP1[30];
GetPlayerCountry(playerid, Country1);
GetPlayerCity(playerid, City1);
GetPlayerIp(playerid,IP1,sizeof(IP1));
format(string,sizeof(string),"* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n\n", GetPlayerName(i), i, IP1, Country1, City1);
count++;
}
}
ShowPlayerDialog(playerid, DIALOG_LOC, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");
return 1;
}

K0P
08/03/2016, 03:20 PM
Try this:
CMD:checkall(playerid, params[])
{
new string[1000];
new string1[50];
new string2[100];
new count=1;
format(string1,sizeof(string1),"Online ( %i )", GetOnLinePlayers());

for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Country1[30], City1[30], IP1[30];
GetPlayerCountry(playerid, Country1);
GetPlayerCity(playerid, City1);
GetPlayerIp(playerid,IP1,sizeof(IP1));
format(string2,sizeof(string2),"* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n", GetPlayerName(i), i, IP1, Country1, City1);
format(string, sizeof(string), "%s", string2);
count++;
}
}
ShowPlayerDialog(playerid, DIALOG_LOC, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");
return 1;
}

FinStar
08/03/2016, 03:25 PM
Still problem :/

TheHonnor
08/03/2016, 03:30 PM
I recommend you to remake your Functions.. Your `GetOnLinePlayers` isn't good.

PlayerName function:

ReturnPlayerName(playerid)
{
new name[24]; GetPlayerName(playerid, name, 24); return name;
}

And for GetOnLinePlayers:

ConnectedPlayers()
{
new Connected;
for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) Connected++;
return Connected;
}

And try remake your command too using the functions made by me..
If you have any question you can simply PM me.

FinStar
08/03/2016, 03:36 PM
Well, I understand, I'll try and write here;)

K0P
08/03/2016, 03:39 PM
This should work:
stock GetPlayers()
{
new Players;
for(new i, i = MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i)) Players++;
}
return Players;
}

CMD:checkall(playerid, params[]0
{
new str[1000], str2[50], str3[100];
format(str2, sizeof(str2), "Online [%d]", GetPlayers());
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new pCountry[50], pCity[50], pIp[50];
GetPlayerCountry(playerid, pCountry);
GetPlayerCity(playerid, pCity);
GetPlayerIp(playerid, pIp, sizeof(pIp);
format(str3, sizeof(str3), "* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]", GetPlayerName(i), i, pIp, pCountry, pCity);
format(str, sizeof(str), "%s\n", str3);
}
}
ShowPlayerDialog(playerid, DIALOG_LOC, DIALOG_STYLE_MSGBOX, str2, str, "OK", "");
return 1;
}

ikey07
08/03/2016, 03:40 PM
Just move
ShowPlayerDialog(playerid, DIALOG_LOC, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");

inside the loop

FinStar
08/03/2016, 03:50 PM
@K0P doesn't work.

@iIkey what do you mean?

CMD:checkall(playerid, params[])
{
new string[1000];
new string1[50];
new string2[100];
new count=1;
format(string1,sizeof(string1),"Online ( %i )", ConnectedPlayers());

for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Country1[30], City1[30], IP1[30];
GetPlayerCountry(playerid, Country1);
GetPlayerCity(playerid, City1);
GetPlayerIp(playerid,IP1,sizeof(IP1));
format(string2,sizeof(string2),"* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n", GetPlayerName(i), i, IP1, Country1, City1);
format(string, sizeof(string), "%s", string2);
ShowPlayerDialog(playerid, DIALOG_LOKACE, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");
count++;
}
}
return 1;
}

K0P
08/03/2016, 03:51 PM
Just move
ShowPlayerDialog(playerid, DIALOG_LOC, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");

inside the loop

Lol no,it will cause lag + we need to show it only 1 time.

TheHonnor
08/03/2016, 03:58 PM
Make more functions witch can be used in formats. Example?

format(string, sizeof(string), Text[], "%s %d %x", ReturnCity(playerid), ReturnPlayerName(playerid) etc....

FinStar
08/03/2016, 04:08 PM
I do not understand what you mean ?

TheHonnor
08/03/2016, 04:16 PM
Well , the ReturnPlayerName function you inserted it into string format. Try to make more functions as ReturnPlayerCity, ReturnPlayerCountry etc.. and to make the command smaller to can edit it very easy.

FinStar
08/03/2016, 04:19 PM
These functions GetPlayerCity, GetPlayerCountry, etc. I got it from the site http://forum.sa-mp.com/showthread.php?t=296171

FinStar
08/03/2016, 05:00 PM
I tried to test foreach but an ongoing problem, it only shows the first player with ID Player ID 0 and more players with ID's simply not displayed


CMD:players(playerid, params[])
{
new dialoginfo[200];
foreach(Player, i)
{
format(dialoginfo, sizeof(dialoginfo), "Name: %s ID: %i\n",ReturnPlayerName(playerid),i);
}
ShowPlayerDialog(playerid, DIALOG_LOKACE, DIALOG_STYLE_MSGBOX ,"asd", dialoginfo, "Cancel", "");
return 1;
}

FinStar
08/03/2016, 05:21 PM
http://prntscr.com/acremn


CMD:checkall(playerid, params[])
{
new string[200];
new string1[30];
format(string1,sizeof(string1),"Online ( %i )", ConnectedPlayers());

for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Country1[30], City1[30], IP1[30];
GetPlayerCountry(i, Country1);
GetPlayerCity(i, City1);
GetPlayerIp(i,IP1,sizeof(IP1));
format(string,sizeof(string),"* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n",ReturnPlayerName(i) , i, IP1, Country1, City1);
ShowPlayerDialog(playerid, DIALOG_LOKACE, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");
SendClientMessage(playerid,-1, string);
}
}
return 1;
}


I'm losted.

zPain
08/03/2016, 05:44 PM
CMD:checkall(playerid)
{
new
title[32],
output[MAX_PLAYERS * 128];

format(title, sizeof title, "Online (%i)", ConnectedPlayers());

new
country[32],
city[32],
ip[32];

for(new i = 0, j = GetPlayerPoolSize(); i <= j; ++i) {
if(IsPlayerConnected(i)) {
GetPlayerCountry(i, country);
GetPlayerCity(i, city);
GetPlayerIp(i, ip, sizeof ip);

format(output, sizeof output, "%s* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n",
output,
ReturnPlayerName(i),
i,
ip,
country,
city
);
}
}

ShowPlayerDialog(playerid, DIALOG_LOKACE, DIALOG_STYLE_MSGBOX, title, output, "Cancel", "");
return 1;
}


I'm not sure if such a big message will fit inside the dialog box. In fact, I recommend you develop a page system. Imagine the size of the output if your server reaches 100 players.

FinStar
10/03/2016, 03:08 PM
CMD:checkall(playerid)
{
new
title[32],
output[MAX_PLAYERS * 128];

format(title, sizeof title, "Online (%i)", ConnectedPlayers());

new
country[32],
city[32],
ip[32];

for(new i = 0, j = GetPlayerPoolSize(); i <= j; ++i) {
if(IsPlayerConnected(i)) {
GetPlayerCountry(i, country);
GetPlayerCity(i, city);
GetPlayerIp(i, ip, sizeof ip);

format(output, sizeof output, "%s* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n",
output,
ReturnPlayerName(i),
i,
ip,
country,
city
);
}
}

ShowPlayerDialog(playerid, DIALOG_LOKACE, DIALOG_STYLE_MSGBOX, title, output, "Cancel", "");
return 1;
}


I'm not sure if such a big message will fit inside the dialog box. In fact, I recommend you develop a page system. Imagine the size of the output if your server reaches 100 players.

Doesnt work, unknown command

J0sh...
10/03/2016, 03:19 PM
You need to format then use strcat eg:

// outside the loop
new dialog[50];

//loop
strcat(dialog, output)

FinStar
10/03/2016, 03:53 PM
where do I move strcat? ("exactly")

J0sh...
10/03/2016, 03:56 PM
where do I move strcat? ("exactly")

Under the format(output, ...)

xTURBOx
10/03/2016, 04:05 PM
Edit: didn't see the second page

AlbaniaMafiaRP
11/03/2016, 12:52 AM
CMD:checkall(playerid, params[])
{
new string[1000];
new string1[50];
new string2[100];
new count=1;
format(string1,sizeof(string1),"Online ( %i )\n", ConnectedPlayers());

for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Country1[30], City1[30], IP1[30];
GetPlayerCountry(playerid, Country1);
GetPlayerCity(playerid, City1);
GetPlayerIp(playerid,IP1,sizeof(IP1));
format(string2,sizeof(string2),"* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n", GetPlayerName(i), i, IP1, Country1, City1);
format(string, sizeof(string), "%s\n", string2);
count++;
}
}
ShowPlayerDialog(playerid, DIALOG_LOKACE, DIALOG_STYLE_MSGBOX , string1, string, "Cancel", "");
return 1;
}

try this..

FinStar
11/03/2016, 07:47 PM
try this..



nope, server crashed then i used this command..

J0sh...
12/03/2016, 01:20 PM
GetPlayerIp(playerid,IP1,sizeof(IP1));
format(string2,sizeof(string2),"* %s ( ID %i ) [ IP: %s | State: %s | City: %s ]\n", GetPlayerName(i), i, IP1, Country1, City1);
format(string, sizeof(string), "%s\n", string2); // This makes no sense!
The thing is when people are using format thinking it will display every person - but they're overwriting the string and displaying the last user's info.