How to get a player's name?
#4

Here is an example:
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME], string[28 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "( ! ) %s has joined the server",name);
    SendClientMessageToAll(COLOR_YELLOW, string);
    return 1;
}
where the "string[28 + MAX_PLAYER_NAME]" creates a new variable with the size of 28 + the maximum length of the player's name. (28+24=52). The reason why it should be 28 is because the "( ! ) %s has joined the server" is 28 carachters long (without the %s) where %s has the size of MAX_PLAYER_NAME (thats why they have to be +'ed together).

Then the players name is read in this line: "GetPlayerName(playerid, name, sizeof(name));"
which means the variable "name" will hold the player's name, and to hold the same amount of characters as "name" (sizeof(name)) which is MAX_PLAYER_NAME (24)"

And in this line we format the string: "format(string, sizeof(string), "( ! ) %s has joined the server",name);"
to the size of "string" which is 28+MAX_PLAYER_NAME (28+24=52), where "%s" is placeholder for the variable called "name" which is holding the name of the player and has a size of 24.

At the end we add ",name" to indicate that "%s" is placeholder for the variable called "name".

Now we just need to send our formatted string as a client message to all the players on the server. We do that by:
"SendClientMessageToAll(COLOR_YELLOW, string);"

Remember that "COLOR_YELLOW" is just a define for the HEX color "0xFFFF00FF".
You can du this by adding this at the top of your script:
pawn Код:
#define COLOR_YELLOW 0xFFFF00FF
Hope this didnt confuse too much.
Good luck learning scripting.
Reply


Messages In This Thread
How to get a player's name? - by Ehab1911 - 19.06.2011, 20:07
Re: How to get a player's name? - by Vince - 19.06.2011, 20:10
Re: How to get a player's name? - by sleepysnowflake - 19.06.2011, 20:17
Re: How to get a player's name? - by sim_sima - 19.06.2011, 20:19
Re: How to get a player's name? - by sim_sima - 19.06.2011, 20:34
Re: How to get a player's name? - by Scenario - 19.06.2011, 20:35
Re: How to get a player's name? - by Ehab1911 - 19.06.2011, 20:37
Re: How to get a player's name? - by sim_sima - 19.06.2011, 20:39
Re: How to get a player's name? - by sleepysnowflake - 19.06.2011, 20:45
Re: How to get a player's name? - by Ehab1911 - 19.06.2011, 20:48

Forum Jump:


Users browsing this thread: 1 Guest(s)