[Help] Stats Dialog
#1

I'm having a problem with creating a stats dialog. Of course, I don't have any errors, or warnings, but I understand the way why it appears in-game like that, when I use /stats, it doesn't show the all info, but only "helper".

Picture:




Code looks like:

Код:
CMD:stats(playerid,params[])
{
     new id, string[1028];
	 sscanf(params, "u", id);
	 if (isnull(params))
	 {
		format(string, sizeof(string), "_Statistics for '%s'_",PlayerName(playerid));
		SendClientMessage(playerid, green, string);
		format(string, sizeof(string), "Score: %d\n", GetPlayerScore(playerid), string);
		format(string, sizeof(string), "Money: $%d\n", GetPlayerMoney(playerid), string);
		format(string, sizeof(string), "Kills: %d\n", PlayerInfo[playerid][pKills], string);
		format(string, sizeof(string), "Deaths: %d\n", PlayerInfo[playerid][pDeaths], string);
		format(string, sizeof(string), "Ratio: %0.2f\n", GetTeamName(playerid), string);
		format(string, sizeof(string), "Team: %s\n", GetTeamName(playerid), string);
		format(string, sizeof(string), "Rank: %s\n", GetRankName(playerid), string);
		format(string, sizeof(string), "Class: %s\n", GetClassName(playerid), string);
		format(string, sizeof(string), "Admin Level: %d\n", PlayerInfo[playerid][pAdmin], string);
		format(string, sizeof(string), "Helper: %d\n", PlayerInfo[playerid][pHelper], string);
		ShowPlayerDialog(playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "{FF6666}Player Stats", string, "Okay","");
     }
	 else if(IsPlayerConnected(id))
	 {
		format(string, sizeof(string), "_Statistics for '%s'_",PlayerName(playerid));
		SendClientMessage(playerid, green, string);
		format(string, sizeof(string), "Score: %d\n", GetPlayerScore(playerid), string);
		format(string, sizeof(string), "Money: $%d\n", GetPlayerMoney(playerid), string);
		format(string, sizeof(string), "Kills: %d\n", PlayerInfo[playerid][pKills], string);
		format(string, sizeof(string), "Deaths: %d\n", PlayerInfo[playerid][pDeaths], string);
		format(string, sizeof(string), "Ratio: %0.2f\n", GetTeamName(playerid), string);
		format(string, sizeof(string), "Team: %s\n", GetTeamName(playerid), string);
		format(string, sizeof(string), "Rank: %s\n", GetRankName(playerid), string);
		format(string, sizeof(string), "Class: %s\n", GetClassName(playerid), string);
		format(string, sizeof(string), "Admin Level: %d\n", PlayerInfo[playerid][pAdmin], string);
		format(string, sizeof(string), "Helper: %d\n", PlayerInfo[playerid][pHelper], string);
		ShowPlayerDialog(playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "{FF6666}Player Stats", string, "Okay","");
     }
	 else SendClientMessage(playerid,RED,"[ERROR]: Player is not connected");
	 return 1;
}
And yeah, I want it to appear verticaly down with the all info. Please help!
Reply
#2

With the string, every time you format it, it clears the last one

Just like a PC Harddrive, when you format it, everything is lost.
Reply
#3

You can use strcat to join more than one string together. You need to format each "line" (Score, Money etc.) then add it to "string" using strcat.

pawn Код:
new id, tmp[50], string[1028];
     sscanf(params, "u", id);
     if (isnull(params))
     {
        format(string, sizeof(string), "_Statistics for '%s'_",PlayerName(playerid));
        SendClientMessage(playerid, green, string);
        format(tmp, sizeof(tmp), "Score: %d\n", GetPlayerScore(playerid));
        strcat(string, tmp);
        format(tmp, sizeof(tmp), "Money: $%d\n", GetPlayerMoney(playerid));
        strcat(string, tmp);
... and so on for everything else.

You can read more here: https://sampwiki.blast.hk/wiki/Strcat
Reply
#4

Quote:
Originally Posted by Nimrod
Посмотреть сообщение
You can use strcat to join more than one string together. You need to format each "line" (Score, Money etc.) then add it to "string" using strcat.

pawn Код:
new id, tmp[50], string[1028];
     sscanf(params, "u", id);
     if (isnull(params))
     {
        format(string, sizeof(string), "_Statistics for '%s'_",PlayerName(playerid));
        SendClientMessage(playerid, green, string);
        format(tmp, sizeof(tmp), "Score: %d\n", GetPlayerScore(playerid));
        strcat(string, tmp);
        format(tmp, sizeof(tmp), "Money: $%d\n", GetPlayerMoney(playerid));
        strcat(string, tmp);
... and so on for everything else.

You can read more here: https://sampwiki.blast.hk/wiki/Strcat
Thanks alot! I fixed it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)