• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] help with this pls
#1
Code:
CMD:id(playerid, params[]) {

? ? if (sscanf(params, "u", params[0])) return SendClientMessage(playerid, -1, "{D41818}[COMMAND]{AFAFAF} /id <nick>");

? ? if (!IsPlayerConnected(params[0])) return SendClientMessage(playerid, -1, "{D41818}[ERROR]{AFAFAF} Player not found");

? ? new string[128];

? ? new name[MAX_PLAYER_NAME];

? ? GetPlayerName(playerid, name, sizeof(name));

? ? format(string, sizeof(string), "%d - [ID]:%s", params[0], name);

? ? SendClientMessage(playerid, 0x969696FF, string);

? ? return 1;

}





my idea is to make a command so that when you put / id and the name of the player you can receive the ID of the player
  Reply
#2
i get the playerid, but i don't have the player name, i have my playername
  Reply
#3
as far as I know sscanf parameter ?u? stands for ID and Name as well. if you use %d with ?u? that should be working fine.
  Reply
#4
Code:
CMD:id(playerid, params[])
{
    new target_id, string[256], target_name[MAX_PLAYER_NAME  1];
    if (sscanf(params, "u", target_id)) return SendClientMessage(playerid, -1, "USAGE: /id <nick/playerid>");
    GetPlayerName(target_id, target_name, sizeof(target_name));
    format(string, sizeof(string), "%s [ID: %d]", target_name, target_id)
    SendClientMessage(playerid, -1, string);

return 1;
}
  Reply
#5
You are getting your nickname, Not the Player's nickname



So you can simply do



Code:
GetPlayerName(params[0], name, sizeof(name));



and that should work I believe.
  Reply
#6
(2021-02-24, 01:19 AM)destiezk Wrote:
Code:
CMD:id(playerid, params[])
{
new target_id, string[256], target_name[MAX_PLAYER_NAME  1];
if (sscanf(params, "u", target_id)) return SendClientMessage(playerid, -1, "USAGE: /id <nick/playerid>");
GetPlayerName(target_id, target_name, sizeof(target_name));
format(string, sizeof(string), "%s [ID: %d]", target_name, target_id)
SendClientMessage(playerid, -1, string);

return 1;
}
Except for the fact that "MAX_PLAYER_NAME 1" should be just "MAX_PLAYER_NAME" (reaching length MAX_PLAYER_NAME (24) is only possible with SetPlayerName()) and that 256 cells is useless for an array only used in SendClientMessage() (max. output is 144 characters anyway), this is the code you're looking for (ignoring the indentation).

You need a variable to store the found (or non found) playerid in. You can't do that in params.
  Reply
#7
(2021-02-25, 09:26 PM)Kwarde Wrote: Except for the fact that "MAX_PLAYER_NAME 1" should be just "MAX_PLAYER_NAME" (reaching length MAX_PLAYER_NAME (24) is only possible with SetPlayerName())

You need the for the null terminator. See?this fiddle for a visualisation with and without the .
Always keep in mind that a lot of people are active on this forum in their spare time.

They are sacrificing time they could easily spend on things they would rather do, to help you instead.

  Reply
#8
(2021-02-25, 09:26 PM)Kwarde Wrote:
(2021-02-24, 01:19 AM)destiezk Wrote:
Code:
CMD:id(playerid, params[])

{

new target_id, string[256], target_name[MAX_PLAYER_NAME  1];

if (sscanf(params, "u", target_id)) return SendClientMessage(playerid, -1, "USAGE: /id <nick/playerid>");

GetPlayerName(target_id, target_name, sizeof(target_name));

format(string, sizeof(string), "%s [ID: %d]", target_name, target_id)

SendClientMessage(playerid, -1, string);



return 1;

}

Except for the fact that "MAX_PLAYER_NAME 1" should be just "MAX_PLAYER_NAME" (reaching length MAX_PLAYER_NAME (24) is only possible with SetPlayerName()) and that 256 cells is useless for an array only used in SendClientMessage() (max. output is 144 characters anyway), this is the code you're looking for (ignoring the indentation).



You need a variable to store the found (or non found) playerid in. You can't do that in params.



What you're saying is incorrect, you need 1 for the null terminator. The guy above me linked you an example.
  Reply


Forum Jump: