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

C++ color for players name in console at login

Jpstafe

Well-Known Member
Joined
Aug 8, 2011
Messages
507
Reaction score
69
I'm playing with colors in c++ and i want that if a player log in to the game it's name in console would be shown in green
i've made this
Lua:
std::cout << name  << colorD(" has logged in.") << std::endl;
but can't get the color s be displayed in the player's name
 
Solution
E
To use colorD with the name variable instead of the "has logged in" message, you can modify the std::cout statement as follows:


C++:
std::cout << colorD(name + " has logged in.") << std::endl;

This will concatenate the name variable with the "has logged in" message and apply the colorD formatting to the entire string. The resulting output will display the name with the desired color format followed by the "has logged in" message.


guess who wrote this answer
I'm playing with colors in c++ and i want that if a player log in to the game it's name in console would be shown in green
i've made this
Lua:
std::cout << name  << colorD(" has logged in.") << std::endl;
but can't get the color s be displayed in the player's name
Have you tried colorD(name)?
 
Lua:
fmt::color paintD = fmt::color(0x006500);
fmt::color paintA = fmt::color(0xFABC01);
std::string colorD(const std::string text)
{
    return fmt::format(fg(paintD), text);
}
std::string colorA(const std::string text)
{
    return fmt::format(fg(paintA), text);
}

i've tried this but it send number where name char should appear
Code:
            std::cout <<ColorD << name  << colorD(" has logged in.") << std::endl;
        }

this is working but is not displayer color at the name just where it says logged in.
Code:
    std::cout << name  << colorD(" has logged in.") << std::endl;
 
To use colorD with the name variable instead of the "has logged in" message, you can modify the std::cout statement as follows:


C++:
std::cout << colorD(name + " has logged in.") << std::endl;

This will concatenate the name variable with the "has logged in" message and apply the colorD formatting to the entire string. The resulting output will display the name with the desired color format followed by the "has logged in" message.


guess who wrote this answer
 
Solution
To use colorD with the name variable instead of the "has logged in" message, you can modify the std::cout statement as follows:


C++:
std::cout << colorD(name + " has logged in.") << std::endl;

This will concatenate the name variable with the "has logged in" message and apply the colorD formatting to the entire string. The resulting output will display the name with the desired color format followed by the "has logged in" message.


guess who wrote this answer
I'm interested in putting my source.. just change this line and compile or do you have to change something else?
 
I'm interested in putting my source.. just change this line and compile or do you have to change something else?
You need to define the colors inside the file where you want the color to be displayed
Here's the example
Lua:
fmt::color paintD = fmt::color(0x006500);
fmt::color paintA = fmt::color(0xFABC01);
std::string colorD(const std::string text)
{
    return fmt::format(fg(paintD), text);
}
std::string colorA(const std::string text)
{
    return fmt::format(fg(paintA), text);
}
Then you can use what Evil pubcker posted
Lua:
std::cout << colorD(name + " has logged in.") << std::endl;
 
Last edited:
fmt::color paintD = fmt::color(0x006500); fmt::color paintA = fmt::color(0xFABC01); std::string colorD(const std::string text) { return fmt::format(fg(paintD), text); } std::string colorA(const std::string text) { return fmt::format(fg(paintA), text); }
Is this part in the source? where can i see? and the Evil Puncker who posted it. I changed and compiled and it gave an error
 
You need to define the colors inside the file where you want the color to be displayed
Here's the example
Lua:
fmt::color paintD = fmt::color(0x006500);
fmt::color paintA = fmt::color(0xFABC01);
std::string colorD(const std::string text)
{
    return fmt::format(fg(paintD), text);
}
std::string colorA(const std::string text)
{
    return fmt::format(fg(paintA), text);
}
Then you can use what Evil pubcker posted
Lua:
std::cout << colorD(name + " has logged in.") << std::endl;
This works only in linux I suppose?
 
This works only in linux I suppose?
not sure, i guess so. altought haven't it in linux
Post automatically merged:

Is this part in the source? where can i see? and the Evil Puncker who posted it. I changed and compiled and it gave an error
maybe you need to update your source im using nekiro's up to date version till 2023
 
Thats outdated you have to cherry picks commits from TFS till it to be up dated
ok then, i will update everything at once by the committs thanks
I dont think so, maybe u need add that before using the function colorA or colorD
I have to update the TFS first, then test this function, then I'll come back and give feedback
 
fmt::color paintD = fmt::color(0x006500); fmt::color paintA = fmt::color(0xFABC01); std::string colorD(const std::string text) { return fmt::format(fg(paintD), text); } std::string colorA(const std::string text) { return fmt::format(fg(paintA), text); }@
@Evil Puncker Where can I find these lines?
 
Back
Top