[INC] CromChat - a better ColorChat!

OciXCrom

Скриптер
Пользователь
Регистрация
20 Мар 2020
Сообщения
21
Симпатии
27



---------- [ Description ] ----------

NOTE: as of March 2021 (version 3.0), CromChat is longer Counter-Strike dependant! You can use it it any mod, but the colors will be active only in CS.

Since every colorchat include that I used so far had something that I don't like, I decided to make one my self and fix the things that annoy me. For example, I didn't like using RED/BLUE/TEAM_COLOR as a parameter in the ColorChat include, another include displayed an error when sending a message in an empty server, and so on. So, here's my version.


---------- [ Color Codes ] ----------

Beside the default symbols - ^x04, ^x03 & ^x01, you can also use these ones:

&x07 = red
&x06 = blue
&x05 = white
&x04 = green
&x03 = team color
&x01 = normal
&x00 = removes message prefix (only if put in the beginning of the message)


You can use only one of the following in a single message: &x07, &x06, &x05, &x03. If you use more than one in a message, it will automatically select the color that is first in the list and will replace all other colors with that one. Combining more than one team color is not possible in CS 1.6!!!

You can choose from multiple color code groups by adding a single line in the .sma file. You can see all the different groups on the image below. By default, the CROMCHAT group is used.



To activate a different color group, simply add #define CC_COLORS_TYPE CC_COLORS_<group name> before #include <cromchat>. Example: if you want to activate the group SHORT, the code needs to look like this:

PHP:
#define CC_COLORS_TYPE CC_COLORS_SHORT
#include <cromchat>
Bear in mind that the codes from the group STANDARD cannot be used lang, .ini and other files. They are only available in the .sma file, so don't use this group if the plugin uses multiple files.

You can also make your own custom set of codes, by using the group CUSTOM like this:

PHP:
#define CC_SYM_CHAT_NORMAL "&x01"
#define CC_SYM_CHAT_TEAM   "&x03"
#define CC_SYM_CHAT_GREEN  "&x04"
#define CC_SYM_CHAT_WHITE  "&x05"
#define CC_SYM_CHAT_BLUE   "&x06"
#define CC_SYM_CHAT_RED    "&x07"
#define CC_SYM_CHAT_NOPREF "&x00"
#include <cromchat>
In the code you replace the &x0 with whatever you want.


---------- [ Sending Messages ] ----------

Messages are sent using the function CC_SendMessage or CromChat:

PHP:
CC_SendMessage(id, szMessage[], any:...)
With the function CC_LogMessage you can send a chat message and log it at the same time:

PHP:
// This will send a message to "id" and log it in the default log file.
CC_LogMessage(id, _, "&x04green &x01is not &x07red")

// This will send a message to all players and log it in the file "test.txt".
CC_LogMessage(0, "test.txt", "&x03Cooool story bro!")
You can use CC_SendMatched to send a message that obeys the targeted player's team color. You can also use ColorChat or client_print_color:

PHP:
CC_SendMatched(const id, const iPlayer, const szInput[], any:...)
Where iPlayer is the player that will be used as a target for the team color. Instead of a player, you can also add one of the following color codes: CC_COLOR_TEAM, CC_COLOR_GREY, CC_COLOR_BLUE, CC_COLOR_RED.

PHP:
CC_SendMatched(id, iTarget, "message")
CC_SendMatched(0, CC_COLOR_GREY, "message")
It is also possible to send a message to a specific group of players by using the same flags as the get_players function. To do this, use the function CC_GroupMessage. The example below shows how to send a message to all alive terrorists.

PHP:
CC_GroupMessage("ae", "TERRORIST", "message")
The library also contains a function to send a message to all players who have specified admin flags. This is the function CC_SendAdminMessage.

PHP:
CC_SendAdminMessage("abcei", true, "message")
If the second argument is set to true, the message will be sent to all players who have ALL of the specified admin flags, otherwise, if it's set to false, it will be sent to players who have ANY of the specified admin flags.

You can also change the color for any other CC_* function by using CC_SetColor.
This will force the next CC_* call to use that color.

PHP:
CC_SetColor(CC_COLOR_GREY)
CC_GroupMessage("a", _, "message")
Bear in mind that if the message contains custom color symbols, it will switch to that color instead.
You can prevent this by setting the second parameter to true:

PHP:
CC_SetColor(CC_COLOR_GREY, true)
CromChat also has functions that can replace the show_activity functions that are used within the default AMXX plugins. By default, when you write #include <cromchat> in your plugin, all "activity" functions automatically get replaced with the corresponding functions from cromchat, which allows you to easily replace the messages from the default AMXX plugins with colored ones. If you want to disable the automatic transformation of these functions, simply add #define CC_DONT_OVERWRITE_ACTIVITY before #include <cromchat>.


---------- [ Adding A Prefix ] ----------

With the function CC_SetPrefix you can specify a global prefix that will automatically be added in the beginning of each message. This is much more easier than having to add a prefix manually on each line of code. The function needs to be added in plugin_init() (or some other forward if necessary).

PHP:
public plugin_init()
    CC_SetPrefix("&x04[X-Servers]")
If you want to remove the prefix, you can use the function CC_RemovePrefix.


---------- [ Removing Colors ] ----------

To remove the color codes from a message:

PHP:
CC_RemoveColors(szMessage[], iLen, bool:bChat = true, bool:bMenu = false)
If bChat = true, it will remove the codes for chat colors.
If bMenu = true, it will remove the codes for menu colors.

There is also a function for removing chat exploits, e.g. chat color codes and the % sign.

PHP:
CC_RemoveExploits(message, len)
---------- [ View the API ] ----------

---------- [ Download ] ----------
 
Последнее редактирование:

OciXCrom

Скриптер
Пользователь
Регистрация
20 Мар 2020
Сообщения
21
Симпатии
27
Update v3.1 @ 08.03.2021
  • Fixed a server crash when sending a message that's too long.
  • Added a new function CC_RemoveExploits that allows you to remove chat color exploits and replace the '%' symbol with a safe version. I strongly advise you to use this when hooking "say" or "say_team".
  • Made the library use "replace_string" instead of "replace_all" if it is available.
 

OciXCrom

Скриптер
Пользователь
Регистрация
20 Мар 2020
Сообщения
21
Симпатии
27
Update v3.2 @ 09.03.2021
  • Fixed a bug with manual color changes caused by a behavior change in AMXX 1.9/1.10. More information here.
 
Сверху Снизу