open.mp forum
[Pawn] help with this pls - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] help with this pls (/showthread.php?tid=1705)



help with this pls - Nicolas_Belic - 2021-02-23

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


RE: help with this pls - Nicolas_Belic - 2021-02-23

i get the playerid, but i don't have the player name, i have my playername


RE: help with this pls - destiezk - 2021-02-24

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.


RE: help with this pls - destiezk - 2021-02-24

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;
}



RE: help with this pls - ImOver - 2021-02-25

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.


RE: help with this pls - Kwarde - 2021-02-25

(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.


RE: help with this pls - Freaksken - 2021-02-26

(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 .


RE: help with this pls - destiezk - 2021-02-26

(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.