Player Name hellp
#8

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!
Reply


Messages In This Thread
Player Name hellp - by MasonSFW - 13.05.2014, 07:30
Re: Player Name hellp - by rockhopper - 13.05.2014, 08:01
Re: Player Name hellp - by rockhopper - 13.05.2014, 08:03
Re: Player Name hellp - by MasonSFW - 13.05.2014, 09:00
Re: Player Name hellp - by rockhopper - 13.05.2014, 09:24
Re: Player Name hellp - by Madd92 - 13.05.2014, 10:17
Re: Player Name hellp - by MasonSFW - 14.09.2014, 12:57
Re: Player Name hellp - by blewert - 14.09.2014, 13:45
Re: Player Name hellp - by MasonSFW - 14.09.2014, 13:54

Forum Jump:


Users browsing this thread: 1 Guest(s)