[HELP] /stats command
#1

Hey everyone, stats command work except name , it always says same wrong name on different players.
Anyone know how to fix it?

pawn Код:
CMD:stats(playerid,params[])
{
    new name[MAX_PLAYER_NAME];
    new id;
    GetPlayerName(id, name, sizeof(name));
    if(sscanf(params,"d",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
    if (!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected.");
    new string[128];
    new Float:ratio=floatdiv(PlayerInfo[id][pKills], PlayerInfo[id][pDeaths]);
    format(string, 128, "%d %d %.2f", PlayerInfo[id][pKills], PlayerInfo[id][pDeaths], ratio);
    format(string, sizeof(string), "Name: %s (ID:%d)\nAdmin Level :%d\nKills : %d\nDeaths : %d\nKill/Death Ratio: %.2f\nScore: %d",name, id, PlayerInfo[id][pAdmin], PlayerInfo[id][pKills], PlayerInfo[id][pDeaths], ratio,PlayerInfo[id][pScore]);
    ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",string,"Close","");
    return 1;
}
Reply
#2

Код:
if(sscanf(params,"d",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
to

Код:
if(sscanf(params,"u",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
Better you change as a message not dialog, hehe.
Reply
#3

You are supposed to get the name of "id" after the sscanf and IsPlayerConnected checks otherwise its value is by default 0 (will get the name of player with ID 0).
Reply
#4

Hey!
Here is my help
You can use /stats or /stats [ID] (it works both ways)
Replace "ID" with this
Код:
new target=playerid;
if(!isnull(params)) sscanf(params, "r", target);
so then it will look like

Код:
CMD:stats(playerid,params[])
{
	new name[MAX_PLAYER_NAME];
        new target=playerid;
        if(!isnull(params)) sscanf(params, "r", target);
 	GetPlayerName(target, name, sizeof(name));
	if(sscanf(params,"d",target)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
	if (!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected.");
	new string[128];
	new Float:ratio=floatdiv(PlayerInfo[target][pKills], PlayerInfo[target][pDeaths]);
	format(string, 128, "%d %d %.2f", PlayerInfo[target][pKills], PlayerInfo[target][pDeaths], ratio);
	format(string, sizeof(string), "Name: %s (ID:%d)\nAdmin Level :%d\nKills : %d\nDeaths : %d\nKill/Death Ratio: %.2f\nScore: %d",name, target, PlayerInfo[target][pAdmin], PlayerInfo[target][pKills], PlayerInfo[target][pDeaths], ratio,PlayerInfo[target][pScore]);
    ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",string,"Close","");
    return 1;
}
EDIT : SORRY FORGOT TO REFRESH KONSTANTINOS AND THE OTHER ONE
Reply
#5

Thanks it worked!
Reply
#6

MY code or JUSTICED'S ?
Mine is not tested =)
Reply
#7

I didnt tested your code i will tomorrow i just put GetPlayerName under sscanf as Konstantinos said

Anyway ty for help!
Reply
#8

Quote:
Originally Posted by justice96
Посмотреть сообщение
Код:
if(sscanf(params,"d",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
to

Код:
if(sscanf(params,"u",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
Better you change as a message not dialog, hehe.
Why would it be better to send a client message rather than a dialog..?
Dialogs look nicer to be honest an they aren't exactly hard to do.
Reply
#9

@ Prokill911 It is my opinion, I saw in other server always use send a client msg instead of the dialog.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)