/stats help
#1

Can someone please explain why is that when I do /stats it only show Total Time logged except the other first stats come?

Код:
CMD:stats(playerid,params[])
{
    SendClientMessage(playerid, whitestamp, "{FFFF00}Usage: /stats <PlayerID>");
    new id, h, m, d;
    new pName[24], pName2[24];
    GetPlayerName(playerid, pName, sizeof(pName)), GetPlayerName(id, pName2, sizeof(pName));
    sscanf(params, "u", id);
    if (isnull(params))
    {
        new seconds = gettime() - pInfo[playerid][ConnectedTime] + pInfo[playerid][TotalSecs];
        format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\n",  pName, playerid);
        format(Jstring, sizeof(Jstring), "Score: %d\n", GetPlayerScore(playerid));
        format(Jstring, sizeof(Jstring), "Money: $%d\n", GetPlayerMoney(playerid));
        format(Jstring, sizeof(Jstring), "Kills: %d\n", pInfo[playerid][Kills]);
        format(Jstring, sizeof(Jstring), "Deaths: %d\n", pInfo[playerid][Deaths]);
        format(Jstring, sizeof(Jstring), "Ratio: %0.2f\n", Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths]);
        format(Jstring, sizeof(Jstring), "Total Time Logged in: %s\n", ConvertTime(seconds,m,h,d));
        return ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",Jstring,"Close","");
    }
    else if(IsPlayerConnected(id))
    {
        new seconds = gettime() - pInfo[id][ConnectedTime] + pInfo[id][TotalSecs];
        format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d) {A9C4E4}\n\nScore: %d\nMoney: $%d\nKills: %d\nDeaths: %d\nRatio: %0.2f\nTime Logged In: %s", pName2, id, GetPlayerScore(id), GetPlayerMoney(id), pInfo[id][Kills], pInfo[id][Deaths], Float:pInfo[id][Kills]/Float:pInfo[id][Deaths], ConvertTime(seconds,m,h,d));
        return ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",Jstring,"Close","");
    }
    else return ShowPlayerDialog(playerid, DIALOG_STATS2, DIALOG_STYLE_MSGBOX,"Player Stats", "Player is not connected", "Close", "");
}
Reply
#2

Your using 7 formats when you should only be using 1 (Possibly 2 if the string is too long and you need strcat) each successive format clears the action of the last so you'll only ever end up with the last formatted string of course.

Example (You will need to complete this)

pawn Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\n \
        Score: %d\n \
        Money: $%d\n"
,
        pName, playerid,
        GetPlayerScore(playerid),
        GetPlayerMoney(playerid));
Reply
#3

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Your using 7 formats when you should only be using 1 (Possibly 2 if the string is too long and you need strcat) each successive format clears the action of the last so you'll only ever end up with the last formatted string of course.

Example (You will need to complete this)

pawn Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\n \
        Score: %d\n \
        Money: $%d\n"
,
        pName, playerid,
        GetPlayerScore(playerid),
        GetPlayerMoney(playerid));
Thanks for the code above. But how come this script work and it shows as it is without any missing lines?

Код:
dcmd_stats(playerid,params[])
{
    new str[512], pDeaths, player1, h, m, s;
    new status[2][10] = {"Disabled", "Enabled"};
    if(!strlen(params)) player1 = playerid;
    else player1 = strval(params);
    if(!IsPlayerConnected(player1)) return SendClientMessage(playerid, white, "{FF0000}>> Player not Connected");
    TotalGameTime(player1, h, m, s);
    if(AccInfo[player1][Deaths] == 0) pDeaths = 1;
    else pDeaths = AccInfo[player1][Deaths];
    format(str, sizeof(str), "{DAA520}%s (ID: %d){B0C4DE}\n\n", PlayerName2(player1), player1);
    format(str, sizeof(str), "%sSkinID: %d\n", str, GetPlayerSkin(player1));
    format(str, sizeof(str), "%sScore: %d\n", str, GetPlayerScore(player1));
    format(str, sizeof(str), "%sKills: %d\n", str, AccInfo[player1][Kills]);
    format(str, sizeof(str), "%sMoney: $%d\n", str, GetPlayerMoney(player1));
    format(str, sizeof(str), "%sRatio: %.2f\n", str, Float:AccInfo[player1][Kills]/Float:pDeaths);
    format(str, sizeof(str), "%sReputations: +%d\n\n", str, AccInfo[player1][Reps]);
    format(str, sizeof(str), "%sInterior: %d\n", str, GetPlayerInterior(player1));
    format(str, sizeof(str), "%sTime Login: %d hours %d minutes %d seconds\n", str, h, m, s);
    ShowPlayerDialog(playerid, 8435, DIALOG_STYLE_MSGBOX, "Player Statistics", str, "Close", "");
    return 1;
}
#endif
Edit: Can you please kindly arrange this?
Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\n \
        Score: %d\n \
        Money: $%d\n",
        pName, playerid,
        GetPlayerScore(playerid),
        GetPlayerMoney(playerid));
Reply
#4

You wrote legit code it will compile but it doesn't do what your expecting. I could write it but then you wouldn't learn anything at least give it a shot and if you have problems post your code and I'll tell you what you did wrong.

One quick thing...

pawn Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\n \
        Score: %d\n \
        Money: $%d\n"
,
Basically means

pawn Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\nScore: %d\nMoney: $%d\n",
The " \ " alone means the next line continues the line your on it's simply a way to organize your code.

You might use this when defining a macro function

example

pawn Код:
#define IsValidID(%0) \
    if(%0 >= 0 && %0 <= 100) return 1; \
    else return 0;
Reply
#5

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
You wrote legit code it will compile but it doesn't do what your expecting. I could write it but then you wouldn't learn anything at least give it a shot and if you have problems post your code and I'll tell you what you did wrong.

One quick thing...

pawn Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\n \
        Score: %d\n \
        Money: $%d\n"
,
Basically means

pawn Код:
format(Jstring, sizeof(Jstring), "{ffd700}%s (ID:%d)\n\nScore: %d\nMoney: $%d\n",
The " \ " alone means the next line continues the line your on it's simply a way to organize your code.
I tried to make stcrat but it show warnings...

Код:
        new seconds = gettime() - pInfo[playerid][ConnectedTime] + pInfo[playerid][TotalSecs];
  		new str1[512];
		strcat(str1, "{ffd700}%s (ID:%d)\n\n",  pName, playerid); <<-----error 035: argument type mismatch (argument 3)
		strcat(str1, "%sScore: %d\n", GetPlayerScore(playerid));
		strcat(str1, "%sMoney: $%d\n", GetPlayerMoney(playerid));
		strcat(str1, "%sKills: %d\n", pInfo[playerid][Kills]);
		strcat(str1, "%sDeaths: %d\n", pInfo[playerid][Deaths]);
		strcat(str1, "%sRatio: %0.2f\n", Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths]); <<------warning 213: tag mismatch
  		strcat(str1, "%sTotal Time Logged in: %s\n", ConvertTime(seconds,m,h,d)); <<------error 035: argument type mismatch (argument 3)
        return ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",Jstring,"Close","");
    }
Edit: Do you think if I made it right. It will show the whole format of stats? or it will show time logged in again?
Reply
#6

You wouldn't use strcat like that you would format the two halfs and then combine but you probably don't need that here just a single format() should work if you follow my example.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
You wouldn't use strcat like that you would format the two halfs and then combine but you probably don't need that here just a single format() should work if you follow my example.
Thanks man I fully understand now. But it was really confusing if you are using 1 or 2 lines for all the formats. It's like a matching type when you are trying to add or change another one. But when you do strcat or the one that I posted. It's easy line by line.
Reply
#8

I got this warning
Код:
input line too long (after substitutions)
from this line

Код HTML:
    {
        new seconds = gettime() - pInfo[playerid][ConnectedTime] + pInfo[playerid][TotalSecs];
        format(JLstring, sizeof(JLstring), "{ffd700}%s (ID:%d){A9C4E4}\n\nGeneral:\nTime Login: %s \nPing: %d \n\nScores:\nDM Score: %d \nK/D Ratio: %0.2f \nMoney: $%d \n\nGame: \nVirtual World: %d \nWanted Level: %d \nSkin: %d", pName, playerid, ConvertTime(seconds,m,h,d), GetPlayerPing(playerid), pInfo[playerid][Kills], Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths], GetPlayerMoney(playerid), GetPlayerVirtualWorld(playerid), GetPlayerWantedLevel(playerid),GetPlayerSkin(playerid));
        return ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",JLstring,"Close","");
    }
    else
I know this is because I exceeded the limit. And I search the forum and I found to use strcat. But how? can anyone please make sample for the code above given?
Reply
#9

pawn Код:
new str[512];     // Change the size if the not all the text shows.
format(JLstring, sizeof(JLstring), "Your stats text 1", bla, bla1);
strcat(str, JLstring);
format(JLstring, sizeof(JLstring), "Your stats text 2", bla3, bla4);
strcat(str, JLstring);
ShowPlayerDialog(playerid, 1234, DIALOG_STYLE_MSGBOX, "Statistics", str, "Close", "");
Sorry for the bla bla's, I am on my phone and can'd write all the rest.
Reply
#10

Quote:
Originally Posted by Dragonsaurus
Посмотреть сообщение
pawn Код:
new str[512];     // Change the size if the not all the text shows.
format(JLstring, sizeof(JLstring), "Your stats text 1", bla, bla1);
strcat(str, JLstring);
format(JLstring, sizeof(JLstring), "Your stats text 2", bla3, bla4);
strcat(str, JLstring);
ShowPlayerDialog(playerid, 1234, DIALOG_STYLE_MSGBOX, "Statistics", str, "Close", "");
Sorry for the bla bla's, I am on my phone and can'd write all the rest.
Thanks man. Im on my phone also thats why I cant tell if this will work or not. But I can see its going to work +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)