Player Name hellp -
MasonSFW - 13.05.2014
Hi i need fs to auto correct player name look like below
if player connect with this name: test change to Test
meak change to Meak
NNAKS_SOSO change to Nnak_Soso
nsns_soodl change to Nsns_Soodl
and etc.
Thank for help me
Re: Player Name hellp -
rockhopper - 13.05.2014
But y u wanna do it i guess you cant and players can connect with what names they want
Re: Player Name hellp -
rockhopper - 13.05.2014
then too here
https://sampforum.blast.hk/showthread.php?tid=380823
Re: Player Name hellp -
MasonSFW - 13.05.2014
LOL that is AutoCorrect Word
Re: Player Name hellp -
rockhopper - 13.05.2014
well there's nothing like what you want
Re: Player Name hellp -
Madd92 - 13.05.2014
I just messed around a little bit and the result was the following function:
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);
return 1;
}
toupper and
tolower are two defines originally
posted by ******:
pawn Код:
#define toupper(%0) \
(((%0) >= 'a' && (%0) <= 'z') ? ((%0) & ~0x20) : (%0))
#define tolower(%0) \
(((%0) >= 'A' && (%0) <= 'Z') ? ((%0) | 0x20) : (%0))
I don't check for the name being a roleplay name and such without numbers or symbols. But I guess you already do that beforehand. Also I don't guarantee for anything but it worked for me when I tested it.
I hope it helps.
Re: Player Name hellp -
MasonSFW - 14.09.2014
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;
}
Re: Player Name hellp -
blewert - 14.09.2014
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!
Re: Player Name hellp -
MasonSFW - 14.09.2014
Thank you so much @blewert i will rep+ you later because i gave more rep
<3 <3 <3