Get player name from ID
#1

When I type /id [id of player], a message will show name of that player!
Example, when I type: /id 239 , a message will show: ID239: xyz !
How can I do? Please help me. Thanks!
Reply
#2

pawn Код:
CMD:id(playerid,params[])
{
    new target,string[85],name[MAX_PLAYER_NAME],Float:x,Float:y,Float:z;
    if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"/id [playerid/partofname]"); // U stands for player name or ID
    if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"Player isn't connected.");
    GetPlayerName(target,name,sizeof(name));
    GetPlayerPos(playerid,x,y,z);
    format(string,sizeof(string),"%s(%d) : %f %f %f",name,target,x,y,z);
    SendClientMessage(playerid,-1,string);
    return 1;
}
Compiles fine for me but didn't test yet.

This will show you the player's name, ID, then the coordinates.
Reply
#3

ZCMD:


pawn Код:
CMD:id(playerid, params[])
{
    new string[128], giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [playerid]");

    if(IsPlayerConnected(giveplayerid))
    {
        format(string, sizeof(string), "(ID: %d) - (Name: %s) ", giveplayerid, GetPlayerNameEx(giveplayerid));
        SendClientMessageEx(playerid, string);
    }
    else
    {
        SendClientMessageEx(playerid, "Invalid player specified.");
    }
    return 1;
}
Try this, you can always add colors to the clientmessages. And don't forget to include the ZCMD and a_samp

(Works fine in my script)
Reply
#4

I can put it where?
Reply
#5

Anywhere in your script as it's using ZCMD.

in top of your script type:
pawn Код:
#include <zcmd>
Reply
#6

Quote:
Originally Posted by bradleyofniet
Посмотреть сообщение
ZCMD:


pawn Код:
CMD:id(playerid, params[])
{
    new string[128], giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [playerid]");

    if(IsPlayerConnected(giveplayerid))
    {
        format(string, sizeof(string), "(ID: %d) - (Name: %s) ", giveplayerid, GetPlayerNameEx(giveplayerid));
        SendClientMessageEx(playerid, string);
    }
    else
    {
        SendClientMessageEx(playerid, "Invalid player specified.");
    }
    return 1;
}
Try this, you can always add colors to the clientmessages. And don't forget to include the ZCMD and a_samp

(Works fine in my script)
I have some problems

Код:
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(54) : error 017: undefined symbol "SendClientMessageEx"
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(58) : error 017: undefined symbol "GetPlayerNameEx"
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(59) : error 017: undefined symbol "SendClientMessageEx"
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(63) : error 017: undefined symbol "SendClientMessageEx"
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(100) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#7

Try this:
pawn Код:
CMD:id(playerid, params[])
{
    new string[128], giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /id [playerid]");

    if(IsPlayerConnected(giveplayerid))
    {
        format(string, sizeof(string), "(ID: %d) - (Name: %s) ", giveplayerid, GetPlayerName(giveplayerid));
        SendClientMessage(playerid, string);
    }
    else
    {
        SendClientMessage(playerid, "Invalid player specified.");
    }
    return 1;
}
My bad :P, I use other includes I guess
Reply
#8

Quote:
Originally Posted by bradleyofniet
Посмотреть сообщение
Try this:
pawn Код:
CMD:id(playerid, params[])
{
    new string[128], giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /id [playerid]");

    if(IsPlayerConnected(giveplayerid))
    {
        format(string, sizeof(string), "(ID: %d) - (Name: %s) ", giveplayerid, GetPlayerName(giveplayerid));
        SendClientMessage(playerid, string);
    }
    else
    {
        SendClientMessage(playerid, "Invalid player specified.");
    }
    return 1;
}
My bad :P, I use other includes I guess
Hey, some problems:

Код:
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(40) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(53) : error 017: undefined symbol "COLOR_WHITE"
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(57) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(57) : warning 202: number of arguments does not match definition
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(58) : error 035: argument type mismatch (argument 2)
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(62) : error 035: argument type mismatch (argument 2)
G:\samp03z_svr_R1_win32\gamemodes\a.pwn(95) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Reply
#9

Can you post on which lines those are?
Reply
#10

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
pawn Код:
CMD:id(playerid,params[])
{
    new target,string[85],name[MAX_PLAYER_NAME],Float:x,Float:y,Float:z;
    if(sscanf(params,"u",target)) return SendClientMessage(playerid,-1,"/id [playerid/partofname]"); // U stands for player name or ID
    if(!IsPlayerConnected(target)) return SendClientMessage(playerid,-1,"Player isn't connected.");
    GetPlayerName(target,name,sizeof(name));
    GetPlayerPos(playerid,x,y,z);
    format(string,sizeof(string),"%s(%d) : %f %f %f",name,target,x,y,z);
    SendClientMessage(playerid,-1,string);
    return 1;
}
Compiles fine for me but didn't test yet.

This will show you the player's name, ID, then the coordinates.
Try this one above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)