SA-MP Forums Archive
Returning your name - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Returning your name (/showthread.php?tid=438909)



Returning your name - ConnorP - 22.05.2013

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?


Re: Returning your name - Luis- - 22.05.2013

Try, GetPlayerName


Re: Returning your name - Pottus - 22.05.2013

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



Re: Returning your name - ConnorP - 22.05.2013

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!


Re: Returning your name - Littlehelper - 22.05.2013

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


Re: Returning your name - Rayan_black - 22.05.2013

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


Re: Returning your name - Pottus - 22.05.2013

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


Re: Returning your name - Rayan_black - 22.05.2013

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.


Re: Returning your name - Pottus - 22.05.2013

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


Re: Returning your name - ConnorP - 22.05.2013

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

Thanks guys.