Raised This Month: $51 Target: $400
 12% 

Solved A little(?) problem with colors in chat.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Virsenas
New Member
Join Date: May 2018
Old 05-21-2018 , 06:03   A little(?) problem with colors in chat.
Reply With Quote #1

Just starting out with SourcePawn. Trying to learn how to make commands and playing around with chat colors. Copied some code from the wiki to test out how it works. The lines that were copied from the wiki, explaining how the color codes work - those lines work and the color changes, but when I try to make my own lines with some text and change the color, the text shows, but the color does not change.

This is the code:

Code:
public void OnPluginStart()
{
	RegConsoleCmd("sm_test", Command_Test);
	PrintToServer("Server: Main server file sucesfully started!");
}

public Action Command_Test(int client, int args)
{
	PrintToChatAll("\x011\x022\x033\x044\x055\x066\x077\x088\x099\x0AA\x0BB\x0CC\x0DD\x0EE\x0FF"); // Color changes
	PrintToChatAll("\x01 1 .. \x02 2 .. \x03 3 .. \x04 4 .. \x05 5 .. \x06 6 .. \x07 7 .. \x08 8"); // Color changes
	PrintToChatAll("\x02Command works!1"); // Color does not change (Line I added)
	PrintToChatAll("\x04Command works!2"); // Color does not change (Line I added)
	//return Plugin_Handled;
}
Have no idea why the color does not change where I have written my own text.

Last edited by Virsenas; 05-21-2018 at 07:11.
Virsenas is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-21-2018 , 06:05   Re: A little(?) problem with colors in chat.
Reply With Quote #2

You have to start the print text with \x01 I believe.
__________________
Neuro Toxin is offline
Virsenas
New Member
Join Date: May 2018
Old 05-21-2018 , 06:16   Re: A little(?) problem with colors in chat.
Reply With Quote #3

Quote:
Originally Posted by Neuro Toxin View Post
You have to start the print text with \x01 I believe.
Wait..., I'm a little confused...

Isn't \x01 the color code? The default one? So first I need to use \x01 and then lets say \x04 for red? Like this:

Code:
PrintToChatAll("\x01\x04Command works!1");
?
Virsenas is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-21-2018 , 06:25   Re: A little(?) problem with colors in chat.
Reply With Quote #4

Depending on the game, yes. SM isn't handling the colors, so you're at the mercy of what the server wants.
Fyren is offline
Virsenas
New Member
Join Date: May 2018
Old 05-21-2018 , 06:31   Re: A little(?) problem with colors in chat.
Reply With Quote #5

Quote:
Originally Posted by Fyren View Post
Depending on the game, yes. SM isn't handling the colors, so you're at the mercy of what the server wants.
So then that means it's not possible to change the text color? The game changes the color only for numbers and other symbols?
Virsenas is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-21-2018 , 06:36   Re: A little(?) problem with colors in chat.
Reply With Quote #6

Quote:
Originally Posted by Virsenas View Post
Wait..., I'm a little confused...

Isn't \x01 the color code? The default one? So first I need to use \x01 and then lets say \x04 for red? Like this:

Code:
PrintToChatAll("\x01\x04Command works!1");
?
Correct. (talking CSGO)

It leaves an annoying whitespace if you start a print with \x01. I generally either avoid printing the first char colored or use another format like ">\x01\x04Some text here."
__________________

Last edited by Neuro Toxin; 05-21-2018 at 06:41.
Neuro Toxin is offline
Virsenas
New Member
Join Date: May 2018
Old 05-21-2018 , 06:57   Re: A little(?) problem with colors in chat.
Reply With Quote #7

Quote:
Originally Posted by Neuro Toxin View Post
Correct. (talking CSGO)

It leaves an annoying whitespace if you start a print with \x01. I generally either avoid printing the first char colored or use another format like ">\x01\x04Some text here."
I see. Now it works. Parts of the game works in a pre-defined way and you have to make workarounds. Thank you.

P.S. Yes, sorry I didn't mention the game.
Virsenas is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode