Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] help with this pls

 
  • 0 Vote(s) - 0 Average
Pawn help with this pls
Nicolas_Belic
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: Feb 2021
Reputation: 0
Location: Argentina
#1
2021-02-23, 11:29 PM
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
Nicolas_Belic
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: Feb 2021
Reputation: 0
Location: Argentina
#2
2021-02-23, 11:55 PM
i get the playerid, but i don't have the player name, i have my playername
destiezk
Offline

Burgershot Member
Posts: 41
Threads: 1
Joined: Feb 2021
Reputation: 3
Location: Hungary
#3
2021-02-24, 01:13 AM
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.
destiezk
Offline

Burgershot Member
Posts: 41
Threads: 1
Joined: Feb 2021
Reputation: 3
Location: Hungary
#4
2021-02-24, 01:19 AM (This post was last modified: 2021-02-26, 12:33 PM by destiezk.)
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;
}
ImOver
Offline

Burgershot Member
Posts: 10
Threads: 0
Joined: Feb 2021
Reputation: 2
#5
2021-02-25, 06:37 PM
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.
Kwarde
Offline

Burgershot Member
Posts: 99
Threads: 2
Joined: Sep 2020
Reputation: 8
Location: The Netherlands
#6
2021-02-25, 09:26 PM (This post was last modified: 2021-02-25, 09:26 PM by Kwarde.)
(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.
Freaksken
Offline

open.mp Developer

Posts: 80
Threads: 4
Joined: Feb 2019
Reputation: 6
Location: Belgium
#7
2021-02-26, 11:30 AM (This post was last modified: 2021-02-26, 11:36 AM by Freaksken.)
(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 +1 for the null terminator. See this fiddle for a visualisation with and without the +1.
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.
destiezk
Offline

Burgershot Member
Posts: 41
Threads: 1
Joined: Feb 2021
Reputation: 3
Location: Hungary
#8
2021-02-26, 12:31 PM
(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.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode