Raised This Month: $7 Target: $400
 1% 

[INC] Colors (1.0.5)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 07-09-2009 , 12:25   [INC] Colors (1.0.5)
Reply With Quote #1

Currently not supported but may work.
New versions -> [INC] More Colors, SMLIB




Colors
Functions for easy chat color management

About:

This include file allows developers to easy control chat coloring in different mods, use color tags, use tags in the translations and automatically replace colors in mods that don't support them (any color that isn't supported will be replaced with green color).

Functions:
  1. CPrintToChat
  2. CPrintToChatAll
  3. CPrintToChatEx
  4. CPrintToChatAllEx
  5. CRemoveTags
  6. CSkipNextClient

Regular functions:

PHP Code:
/**
 * Prints a message to a specific client in the chat area.
 * Supports color tags.
 *
 * @param client      Client index.
 * @param szMessage   Message (formatting rules).
 * @return              No return
 * 
 * On error/Errors:   If the client is not connected an error will be thrown.
 */
stock CPrintToChat(client, const String:szMessage[], any:...)

/**
 * Prints a message to all clients in the chat area.
 * Supports color tags.
 *
 * @param client      Client index.
 * @param szMessage   Message (formatting rules)
 * @return              No return
 */
stock CPrintToChatAll(const String:szMessage[], any:...) 
Tags: {default}, {green}, {lightgreen}, {red}, {blue}, {olive}.

Regular colors: default, green (yellow in L4D), olive.
Team colors: lightgreen, red, blue.

Colors table:
[IMG]http://img219.**************/img219/2408/colorstable3.png[/IMG]

Notes:
  • You can use only one team color (like lightgreen, red or blue) in the message.
  • In hl2dm colors are different for classic deathmatch and team deathmatch.
  • If some color is not supported by the mod it will be automatically replaced with green
  • You can use these functions instead of default SM function, they are support formatting (%d, %s, %t, etc.)
  • Green color is yellow in L4D and L4D2.
  • There must be at least one player in each team for proper red and blue colors working. Otherwise these tags will be replaced with green.


Team color based functions:

PHP Code:
/**
 * Prints a message to a specific client in the chat area.
 * Supports color tags and teamcolor tag.
 *
 * @param client      Client index.
 * @param author      Author index whose color will be used for teamcolor tag.
 * @param szMessage   Message (formatting rules).
 * @return              No return
 * 
 * On error/Errors:   If the client or author are not connected an error will
 *                    be thrown.
 */
stock CPrintToChatEx(clientauthor, const String:szMessage[], any:...)

/**
 * Prints a message to all clients in the chat area.
 * Supports color tags and teamcolor tag.
 *
 * @param author      Author index whose color will be used for teamcolor tag.
 * @param szMessage   Message (formatting rules).
 * @return              No return
 * 
 * On error/Errors:   If the author is not connected an error will
 *                    be thrown.
 */
stock CPrintToChatAllEx(author, const String:szMessage[], any:...) 
Tags: {default}, {green}, {olive}, {teamcolor}.

Regular colors: default, green (yellow in L4D), olive.
Team colors: based on author's team color.

Notes:
  • Author index is any client index whose team color you want to be used for {teamcolor} tag
  • Tag {teamcolor} replaces {red}, {blue} and {lightgreen} tags
  • All notes for regular functions are used for these function too.

Other:

PHP Code:
/**
 * Removes color tags from the string.
 *
 * @param szMessage   String.
 * @param maxlength   Maximum length of the string buffer.
 * @return              No return
 */
stock CRemoveTags(String:szMessage[], maxlength)

/**
 * This function should only be used right in front of
 * CPrintToChatAll or CPrintToChatAllEx and it tells
 * to those funcions to skip specified client when printing
 * message to all clients. After message is printed client will
 * no more be skipped.
 * 
 * @param client   Client index
 * @return           No return
 */
stock CSkipNextClient(client
Changelog:
  • 1.0.5
    • Added support for olive color in HL2:DM
  • 1.0.4
    • Added support for olive color in CS:S
  • 1.0.3
    • Added protection from double inclusion (credits to Greyscale and naris)
    • Added CSkipNextClient function
    • Small optimization in CPrintToChatAll and CPrintToChatAllEx functions
  • 1.0.2
    • Left 4 Dead 2 support
    • Removed {yellow} tag. Use {green} in L4D for yellow color.
  • 1.0.1
    • Fixed incorrect formatting in CPrintToChatEx function
Attached Files
File Type: inc colors.inc (11.9 KB, 46178 views)
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 05-02-2013 at 17:56.
exvel is offline
Send a message via ICQ to exvel
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 07-09-2009 , 12:26   Re: [INC] Colors
Reply With Quote #2

FAQ


1. How can I use color tags?

Just place color tag in the text where you want your color to start from.
PHP Code:
CPrintToChat(client"This text is {green}green{default} and this is {red}red"); 
Output: [IMG]http://img694.**************/img694/6613/dedust20008p.jpg[/IMG]


2. Is it possible to use red, blue or lightgreen colors in one string?

No. You can only have one team color in a string.


3. How do formatting rules work for these functions?

They work in exactly same way as for default SM functions (like PrintToChat).
PHP Code:
CPrintToChatAll("This number {green}%d{default} is green"5); 
Output: [IMG]http://img199.**************/img199/8122/dedust20009j.jpg[/IMG]


4. Can I use color tags inside of translations files?

Yes, you can.
Translation file:
Code:
"Phrases"
{
	"My phrase"
	{
		"en"			"My {green}phrase"
		"ru"			"Моя {green}фраза"
	}
}
In the code:
PHP Code:
CPrintToChatAll("%t""My phrase"); 
Output for english clients: [IMG]http://img46.**************/img46/5854/dedust20010c.jpg[/IMG]
Output for russian clients: [IMG]http://img14.**************/img14/9972/dedust20011e.jpg[/IMG]


5. How to install it?

Put colors.inc into sourcemod/scripting/include folder.
Add this into the code:
PHP Code:
#include <colors> 

6. Is it possible to use grey color?

Yes, it is. But there is no grey tag because it requires at least one player in spectators team. This situation happens not often. But you can use grey in team color based functions.
PHP Code:
CPrintToChatEx(clientauthor"{teamcolor}Hello, this is author's team color"); 
Output when author is spectator: [IMG]http://img199.**************/img199/7830/dedust20013dt.jpg[/IMG]
Output when author is Red/T/Infected/Rebel: [IMG]http://img694.**************/img694/5869/dedust20012.jpg[/IMG]
Output when author is Blue/CT/Survivor/Combine: [IMG]http://img145.**************/img145/5875/dedust20014.jpg[/IMG]


7. Why red/blue colors sometimes show as green?

There must be at least one player in each team for proper red and blue colors working. Otherwise these tags will be replaced with green.


8. What does CSkipNextClient function do?

It tells to CPrintToChatAll and CPrintToChatAllEx to skip client when printing message to all clients. Should be always called right in front of those functions if you want to skip someone.
For example, you want to print message to all clients when client attacked someone and you don't want attacker and victim to see this message. Then you can use this code:
PHP Code:
CSkipNextClient(attacker);
CSkipNextClient(victim);
CPrintToChatAll("%N attacked %N"attackervictim); 
In next call of CPrintToChatAll or CPrintToChatAllEx function those clients will no longer be skipped and if you want to skip someone again then you need to call CSkipNextClient again.
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 04-29-2010 at 06:29.
exvel is offline
Send a message via ICQ to exvel
Dragonshadow
BANNED
Join Date: Jun 2008
Old 07-09-2009 , 18:07   Re: [INC] Colors
Reply With Quote #3

Ty
Dragonshadow is offline
Chris-_-
SourceMod Donor
Join Date: Oct 2008
Old 07-10-2009 , 03:19   Re: [INC] Colors
Reply With Quote #4

Pretty neat
Chris-_- is offline
DontWannaName
Veteran Member
Join Date: Jun 2007
Location: VALVe Land, WA
Old 07-10-2009 , 04:24   Re: [INC] Colors
Reply With Quote #5

TF2 supports gray chat, its the team color when you are in spectator. I dont know if you can get it to work for this though.
__________________

DontWannaName is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 07-10-2009 , 05:00   Re: [INC] Colors
Reply With Quote #6

Quote:
Originally Posted by DontWannaName View Post
TF2 supports gray chat, its the team color when you are in spectator. I dont know if you can get it to work for this though.
Yeap, you are right, all games with team colors support grey but it's only available when somebody is in spectators team, this is why I didn't add grey tag. BUT. You always can use gray in team color based function. For example:
PHP Code:
CPrintToChatEx(clientclient"{teamcolor}This is grey text if client is spectator"); 
In this example author = client.
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 07-10-2009 at 05:56.
exvel is offline
Send a message via ICQ to exvel
Dragonshadow
BANNED
Join Date: Jun 2008
Old 07-10-2009 , 07:14   Re: [INC] Colors
Reply With Quote #7

You know, you should be able to "fake" a client on that team so you can use those colors regardless.
If only it were that simple
Dragonshadow is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 07-10-2009 , 07:23   Re: [INC] Colors
Reply With Quote #8

Quote:
Originally Posted by Dragonshadow View Post
You know, you should be able to "fake" a client on that team so you can use those colors regardless.
If only it were that simple
I had this idea too but faking clients in this case causes server and other plugins to work in unexpexted way. Anyway this is not a big problem because there are almost always at least one player in each team when you are sending a message to chat.
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 07-10-2009 at 07:30.
exvel is offline
Send a message via ICQ to exvel
altex
Veteran Member
Join Date: May 2009
Location: Russia
Old 07-10-2009 , 07:31   Re: [INC] Colors
Reply With Quote #9

Nice work!
__________________
altex is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 07-11-2009 , 11:26   Re: [INC] Colors (1.0.1)
Reply With Quote #10

Update: 1.0.1
  • Fixed incorrect formatting in CPrintToChatEx function
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
Reply


Thread Tools
Display Modes

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 07:27.


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