Quote:
Originally Posted by MasonSFW
Its work !!! @Madd92
But i want
pawn Код:
stock ChangePlayerName(playerid) { new name[MAX_PLAYER_NAME], i; GetPlayerName(playerid, name, MAX_PLAYER_NAME);
while (name[i] != EOS) { if (i == 0 || name[i - 1] == '_') name[i] = toupper(name[i]); else if (name[i] != '_') name[i] = tolower(name[i]); i++; } printf("%s", name); SetPlayerName(playerid, name); // it not working :/ return 1; }
|
This is caused because SetPlayerName doesn't work when you set the same name with a different case:
Quote:
- Changing the player's name to the same name but with different character cases (e.g. "John" to "JOHN") will not work.
|
To get around this, you have to temporarily set their name to something else, and then set it back to the corrected name. You can use anything, but I guess just append an underscore after their name:
pawn Код:
stock ChangePlayerName(playerid)
{
new name[MAX_PLAYER_NAME], i;
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
while (name[i] != EOS)
{
if (i == 0 || name[i - 1] == '_')
name[i] = toupper(name[i]);
else if (name[i] != '_')
name[i] = tolower(name[i]);
i++;
}
printf("%s", name);
new tempName[MAX_PLAYER_NAME];
format(tempName, sizeof tempName, "%s_", name);
SetPlayerName(playerid, tempName);
SetPlayerName(playerid, name);
return 1;
}
This would work, but you may encounter issues when the player has a name with the maximum number of characters in it, because we'd run out of space. There are other ways to combat this (just a simple check), such as setting their name to a random string, or removing a character from their name rather than appending a character to it!
Also, take note of this from the wiki page:
Quote:
- If used in OnPlayerConnect, the new name will not be shown for the connecting player.
|
edit: actually, the maximum a player can connect with is 20 characters, and we can set their name to a maximum of 24 characters. This allows us to work in the extra underscore, so this should work fine!