Returning your name
#1

OK, so I'm not really sure how to explain this. I'm a bit crap at scripting but I'm trying to learn, and it feels like I'm getting better everyday.

But, I'm trying to script something which returns your name.

It's hard to explain what I'm trying to do so I'll say it in a very simple example.
Say your username you connected with is "Bob".

I type, for example /myname and it would return "Your name is Bob". How would I go about coding this?
Reply
#2

Try, GetPlayerName
Reply
#3

pawn Code:
CMD:myname(playerid, arg[])
{
    new myname[MAX_PLAYER_NAME];
    new line[64];
    GetPlayerName(playerid, myname, MAX_PLAYER_NAME);
    format(line, sizeof(line), "Your name is %s", myname);
    SendClientMessage(playerid, 0xFF00FFFF, line);
    return 1;
}
Reply
#4

Quote:
Originally Posted by Luis-
View Post
Try, GetPlayerName
I'm stupid. I forgot about that function, thanks.

Quote:
Originally Posted by [uL]Pottus
View Post
pawn Code:
CMD:myname(playerid, arg[])
{
    new myname[MAX_PLAYER_NAME];
    new line[64];
    GetPlayerName(playerid, myname, MAX_PLAYER_NAME);
    format(line, sizeof(line), "Your name is %s", myname);
    SendClientMessage(playerid, 0xFF00FFFF, line);
    return 1;
}
Cheers!
Reply
#5

^ Like luis said.
Example:
pawn Code:
new pName[MAX_PLAYER_NAME],szString[64]; // Defining pName and String
GetPlayerName(playerid,pName,sizeof(pName)); // Getting player name
format(szString,sizeof(szString),"* %s", pName); // formatting the message
SendClientMessage(playerid,-1,szString); // and here we are sending the message to player with the string we formatted
EDIT: late.
Reply
#6

pawn Code:
#include <zcmd>

ZCMD:myname(playerid, params[])
{
    str[38];
    format(str, sizeof(str), "Your name is %s.", GetName(playerid));
    SendClientMessage(playerid, -1,str);
    return 1;
}

stock GetName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
EDIT: too late... anyways the stock I gave you will prevent you from creating vars everytime when checking someone's name so just use GetName(playerid).
Reply
#7

Your Array size is too small Rayan it should be 38 :P
Reply
#8

Quote:
Originally Posted by [uL]Pottus
View Post
Your Array size is too small Rayan it should be 38 :P
Wasn't maximum name size 20? anyways my bad I'll make edited.
Reply
#9

It's 24 + the length of these characters "Your name is "
Reply
#10

Pottus' code worked fine and he will receive a +1.

Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)