Player info
#1

Hello i need help when i make command /player to see other player info like /player [id], to see player fps player name ping kills
Thanks
pawn Код:
if (strcmp(cmdtext, "/player", true) == 0)
{
new string[999];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    format(string,sizeof string,"Player: %s (ID:%d)",pName, playerid);
    SendClientMessage(playerid,0xE89B5BBB ,string);
    format(string,sizeof string,"> FPS: %d",FPS2[playerid]);
    SendClientMessage(playerid,-1 ,string);
    format(string,sizeof string,"> Ping: %d",GetPlayerPing(playerid));
    SendClientMessage(playerid,-1 ,string);
    format(string,sizeof string,"> Kills: %d",Kills[playerid]);
    SendClientMessage(playerid,-1 ,string);
return 1;
}
Reply
#2

anyhelp?
Reply
#3

1. Don't use strcmp for commands, search for ycmd/zcmd
2. Don't use 999 for string length when you don't even need that much (your longest string is like max 40 chars long)
3. Use sscanf to detect parameters in command

This is ugly version (and additionally if the argument is invalid, it will return stats for player 0)

pawn Код:
if (!strcmp(cmdtext, "/player", true))
{
    new
        string[45],
        pName[MAX_PLAYER_NAME+1],
        id;
   
    strdel(cmdtext, 0, 8);
    id = strval(cmdtext);
    if(IsPlayerConnected(id)) {
        GetPlayerName(id, pName, sizeof pName);
        format(string,sizeof string,"Player: %s (ID:%d)",pName, id);
        SendClientMessage(id,0xE89B5BBB ,string);
        format(string,sizeof string,"> FPS: %d",FPS2[id]);
        SendClientMessage(id,-1 ,string);
        format(string,sizeof string,"> Ping: %d",GetPlayerPing(id));
        SendClientMessage(id,-1 ,string);
        format(string,sizeof string,"> Kills: %d",Kills[id]);
        SendClientMessage(id,-1 ,string);
    }
    return 1;
}
Reply
#4

I guess this is the pretty version? You shouldn't need a string size above 64; the only time I could see you running into a problem is if a player's name is too large (what is the max size of a player name?). Aside from that, this should work pretty nicely for what you are using. If you supply an invalid argument/id then this should give you the message 'Error - Invalid Client!'. I am not able to test this at the moment so I do apologize; in theory it should work.

Good Luck and I hope this helps!

PHP код:
#incldue <zcmd>
COMMAND:player(playeridparams[])
{
    new 
iPlayer;
    if (!
sscanf(params"u"iPlayer))
    {
        if (
iPlayer != INVALID_PLAYER_ID)
        {
            new 
sMessage[64], sName[MAX_PLAYER_NAME];
            
GetPlayerName(iPlayersNamesizeof(sName));
            
format(sMessagesizoef(sMessage),"Player: %s (%d) \n->FPS: %d \n->Ping: %d \n->Kills: %d"sNameiPlayerFPS2[iPlayer], GetPlayerPing(iPlayer), Kills[iPlayer]);
            
SendClientMessage(playerid, -1,sMessage);
        }
        else 
SendClientMessage(playerid, -1"Error: Invalid Client!");
    }
    else 
SendClientMessage(playerid, -1"Usage: /player <id>");
    return 
1;

Reply
#5

24 + NUL is max name. I didn't take a look at the strings, the way with newlines is better. Maximum number is 2147483647, and is 10 characters wide, so each %d can be maximum 10 chars long. Better safe than sorry
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)