SetPlayerName

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 00:48, 22 October 2012
1337pr0 (Talk | contribs)
(Fixed some grammar to improve readability)
← Previous diff
Revision as of 04:16, 5 February 2014
Connor Mead (Talk | contribs)

Next diff →
Line 1: Line 1:
{{Scripting}} {{Scripting}}
-{{Title}} 
{{Description|Sets the name of a player.}} {{Description|Sets the name of a player.}}
Line 39: Line 38:
[[Category:Scripting Functions]] [[Category:Scripting Functions]]
- +[[fr:SetPlayerName]]
[[ru:SetPlayerName]] [[ru:SetPlayerName]]

Revision as of 04:16, 5 February 2014



Description:

Sets the name of a player.


Parameters:
(playerid, name[])
playeridThe ID of the player to set the name of
name[]The name to set


Return Values:

1 if the name was changed, 0 if the player is already using that name or -1 when the name cannot be changed (it's in use, too long or has invalid characters)


Image:32px-Circle-style-warning.png

Important
Note

If you set the player's name to the same name except different cased letters (i.e. "heLLO" to "hello"), it will not work. If used in OnPlayerConnect, the new name will not be shown for the connecting player.


// Command simply sets the player's name to to "Superman" if possible, with no error checking or messages.
if(strcmp(cmdtext, "/superman", true) == 0)
{
    SetPlayerName(playerid, "Superman");
    return 1;
}
 
// Command sets the players name to "Superman" if possible, informs the player of
// any errors using a "switch" statement.
if(strcmp(cmdtext, "/superman", true) == 0)
{
    switch(SetPlayerName(playerid, "Superman"))
    {
        case -1: SendClientMessage(playerid, 0xFF0000FF, "Unable to change your name, someone else is known as 'Superman' already.");
        case 0: SendClientMessage(playerid, 0xFF0000FF, "You are already known as 'Superman'");
        case 1: SendClientMessage(playerid, 0x00FF00FF, "You are now known as 'Superman'");
    }
    return 1;
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

In other languages