• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

AAC MyAAC 1.8.8 - Character name capitalize first letter in each word

Gover

Well-Known Member
Joined
Sep 3, 2009
Messages
129
Reaction score
67
Hello,
Another question about MyAAC in latest version.
I saw that creating a character from admin account is working properly. I can easly create character with name for example: "Knight of Nothing".
But with normal account - system automatically capitalize first letter and convert my name "Knight of Nothing" to "Knight Of Nothing".
Maybe it is configurable somwhere? if not I will try to find it and change.
Regards,
Matt
 
Build software better, together (https://github.com/search?q=repo%3Aslawkens%2Fmyaac%20ucwords&type=code)

As you can see, there are quite a few instances where the PHP ucwords functions is used, not just on character creation, but in change character name too. Just remove this wherever you need. Or, in my opinion, change it to ucfirst so it will still capitalise the first character.

PHP: ucwords - Manual (https://www.php.net/manual/en/function.ucwords.php)
PHP: ucfirst - Manual (https://www.php.net/manual/en/function.ucfirst.php)
 
Thanks a lot - it really clear things up :)

I tried to change:

if (!admin() && !empty($character_name)) {
$character_name = ucwords(strtolower($character_name));
}

to

if (!admin() && !empty($character_name)) {
$character_name = ucfirst(strtolower($character_name));
}

And now nickname "Warrior of Nothing" is converted to "Warrior of nothing" so it lowers the last word :P

I also tried to change $character_name = ucwords(strtolower($character_name)); to $character_name = strtolower($character_name); but then nickname "Warrior of Nothing" is converted to "warrior of nothing" so it looks worst :)

Maybe there is some others uc which allows the player to create nickname of their choice.

Anyway - thanks for help, now I have something to work with.
 
Thanks a lot - it really clear things up :)

I tried to change:

if (!admin() && !empty($character_name)) {
$character_name = ucwords(strtolower($character_name));
}

to

if (!admin() && !empty($character_name)) {
$character_name = ucfirst(strtolower($character_name));
}

And now nickname "Warrior of Nothing" is converted to "Warrior of nothing" so it lowers the last word :P

I also tried to change $character_name = ucwords(strtolower($character_name)); to $character_name = strtolower($character_name); but then nickname "Warrior of Nothing" is converted to "warrior of nothing" so it looks worst :)

Maybe there is some others uc which allows the player to create nickname of their choice.

Anyway - thanks for help, now I have something to work with.
Yeah, the functions that exist either capitalise a) the first letter of the whole string or b) the first letter of every word (any set of characters separated by a space). You won't find a default library function that will cater to your needs, you will need a programmatical approach.

There are multiple ways you could do it, but if you want to prevent the capitalisation of a specific word, such as "of", you can do something like the following:
PHP:
if(!admin() && !empty($character_name)){
    $loweredWords = ['of', 'the', 'in']; //all words in this array will be lowered
   
    $characterNameWords = explode(' ', strtolower($character_name));
    foreach($characterNameWords as $i => $word){
        if(!in_array($word, $loweredWords)){
            $characterNameWords[$i] = ucfirst($word);
        }
    }
   
    $character_name = implode(' ', $characterNameWords);
}
It's not great, but it does what you intend to do. My time is limited but maybe someone else here has a better approach/idea.
 
Last edited:
Back
Top