SetPlayerName
From SA-MP Wiki
(Difference between revisions)
Revision as of 23:42, 26 July 2015 Kar (Talk | contribs) ← Previous diff |
Revision as of 16:41, 1 July 2018 Freaksken (Talk | contribs) (Add const keyword) Next diff → |
||
Line 3: | Line 3: | ||
{{Description|Sets the name of a player.}} | {{Description|Sets the name of a player.}} | ||
- | {{Parameters|playerid, name[]}} | + | {{Parameters|playerid, const name[]}} |
{{Param|playerid|The ID of the player to set the name of.}} | {{Param|playerid|The ID of the player to set the name of.}} | ||
- | {{Param|name[]|2=The name to set. Must be 1-24 characters long and only contain valid characters (0-9, a-z, A-Z, [], (), $ @ . _ and = only).}} | + | {{Param|const name[]|2=The name to set. Must be 1-24 characters long and only contain valid characters (0-9, a-z, A-Z, [], (), $ @ . _ and = only).}} |
{{Returns| | {{Returns| |
Revision as of 16:41, 1 July 2018
Description:
Sets the name of a player.
(playerid, const name[])
playerid | The ID of the player to set the name of. |
const name[] | The name to set. Must be 1-24 characters long and only contain valid characters (0-9, a-z, A-Z, [], (), $ @ . _ and = only). |
Return Values:
- 1 The name was changed successfully
- 0 The player already has that name
- -1 The name can not be changed (it's already in use, too long or has invalid characters)
![]() Important |
|
Example Usage:
// 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.
- GetPlayerName: Get a player's name.