My Method (Easy)
In this method you just add some code to the end of your existing or new plugin and you just replace all the print methods.
Step 1 : Copy the code below and add it to the last of your plugin's source.
stock client_print_color(id, type, const text[], any:...) { if(type == print_chat) { new g_iMsgidSayText; g_iMsgidSayText = get_user_msgid("SayText"); new szMsg[191], iPlayers[32], iCount = 1; vformat(szMsg, charsmax(szMsg), text, 3); replace_all(szMsg, charsmax(szMsg), "!g","^x04"); replace_all(szMsg, charsmax(szMsg), "!n","^x01"); replace_all(szMsg, charsmax(szMsg), "!t","^x03"); if(id) iPlayers[0] = id; else get_players(iPlayers, iCount, "ch"); for(new i = 0 ; i < iCount ; i++) { if(!is_user_connected(iPlayers[i])) continue; message_begin(MSG_ONE_UNRELIABLE, g_iMsgidSayText, _, iPlayers[i]); write_byte(iPlayers[i]); write_string(szMsg); message_end(); } } }
Step 2 :
After you add this code to your plugin you just have to replace all the client_print code.
I'll give an example, use your brain and do the rest with all the code.
Change this -
client_print(id,print_chat,"This is a normal chat message in your plugin")
to
client_print_color(id,print_chat,"!gThis is a !tcolored chat!n message which you edited!")
You can use these codes for color chats -
!g = Green
!n = Normal
!t = Team
These codes can also be used in the language file. No extra changes necessary.
AM Stock Include Method (Intermediate)
Step 1 :
For this method you have to download the stock colorchat.inc from here. You have to copy this file to your compiler's includes folder.
Step 2 :
Open your plugin's source and add the include code first
#include <colorchat>
Step 3 :
After this you have to look for all instances of client_print code and replace them as below
client_print(id,print_chat,"This is a normal chat message in your plugin")to
client_print_color(id,id/RED/BLUE/GREY,"^4This is a ^3colored chat^1 message in your plugin")In this code you have to change the second part to either id, Red, Blue or Grey. This is the base color which will be used when you use team color (^3).
If your plugin uses a language file, i.e it has register_dictionary and you wish to use color chat in that too then you need to change
Eg -
register_dictionary("common.txt")
to
register_dictionary_colored("common.txt")
In this method you have to use the following color codes -
If adding to source code then
^4 = Green
^3 = Team
^1 = Normal
If adding in Lang file then -
!g = Green
!t = Team
!n = Normal
This post was written in a hurry but I'm pretty sure it covered what it meant to.
Still if you face any problems implementing the code please leave a comment below and please be descriptive, don't just say its not working.
This comment has been removed by a blog administrator.
ReplyDeletei have tried the first option on statsx plugin added the code and changed the rank line to this
ReplyDelete"client_print_color"
and changed in the .txt file the language file to this:
YOUR_RANK_IS = !tYour rank is !g%d !tof !g%d !twith !g%d kill(s), %d hit(s), %0.2f%% eff. !tand !g%0.2f%% acc.
and in game when i type /rank it gives me
*SPEC* tfl.!@#$^*+= : /rank
* ML_NOTFOUND:
HELP !!!
Save the text file in "UTF-8 without BOM" encoding.
Deleteit still gives
ReplyDelete*SPEC* tfl.!@#$^*+= : /rank
* ML_NOTFOUND:
HELP :)
also i did not change this
register_dictionary
to
register_dictionary_colored
because i am using first method i does not say to do i have to ?
also i did not add !g !t !n to the
ReplyDelete"client_print_color" in the source code i only changed it in the .txt file do i have to add color codes in the "client_print_color"
and also in the txt file for it to work ?
You first need to add the stock code to the end of your plugin's source. Check that step if you have added that code to your plugin.
DeleteThen go for editing the language file or the text in the source code as per your needs.
I've tried your advanced method. Replacing it with client_print_color(id,id/RED/BLUE/GREY,"^4This is a ^3colored chat^1 message in your plugin"), you'll only display only 1 message to only 1 player, without displaying it for the rest of the players. You need to add a for loop in front e.g.
ReplyDeletefor(new i; i<iNum; i++)
{
player = iPlayers[i]
client_print_color(id,id/RED/BLUE/GREY,"^4This is a ^3colored chat^1 message in your plugin")
}
so that each player will get a chat message in his own team color.
Correct.
Deleteif you put 0 into id, then it will be shown to all
DeleteHow To Add TXT IN CODE
ReplyDeleteBhai Realy Nice Post he yeh
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete