Raised This Month: $ Target: $400
 0% 

How to replace color in chat?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gameplayonline
Member
Join Date: Jun 2017
Old 07-02-2017 , 23:58   How to replace color in chat?
Reply With Quote #1

Im trying to find tutorial how to replace color of messages what player say but i cant find it have somebody?
gameplayonline is offline
gameplayonline
Member
Join Date: Jun 2017
Old 07-03-2017 , 01:39   Re: How to replace color in chat?
Reply With Quote #2

I have it if it will help somebody:
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <cstrike>

#define PLUGIN "Prefix"
#define VERSION "1.0"
#define AUTHOR "gameplayonline"

new  prefix[][] = 
{
	"^1(^3Unassigned^1) [^4Affliate VIP^1]", 			//0
	"^1(^3Spectator^1) [^4Affliate VIP^1]",				//1
	"^1*DEAD* (^3Counter-Terrorist^1) [^4Affliate VIP^1]",	//2
	"^1*DEAD* (^3Terrorist^1) [^4Affliate VIP^1]",		//3
	"^1[^4Affliate VIP^1]",						//4
	"^1*DEAD* [^4Affliate VIP^1]"				//5
}


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("say", "VIP_Prefix") 
	register_clcmd("say_team", "VIP_Prefix_Team")  
}

public VIP_Prefix(id) 
{ 
	new Message[192] 
	new Name[33] 
	get_user_name(id, Name, charsmax(Name)) 
	
	read_args(Message, charsmax(Message)) 
	remove_quotes(Message) 
	
	if(is_user_alive(id)) 
	{ 
		if(get_user_team(id) == 0) 
		{ 
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message) 
		}
		else if(get_user_team(id) == 1) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message)
		}
		else if(get_user_team(id) == 2) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message) 
		}
		else if(get_user_team(id) == 3) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message) 
		} 
		else
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message) 
		}
	} 
	else
	{ 
		if(get_user_team(id) == 0) 
		{ 
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message) 
		}
		else if(get_user_team(id) == 1) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[3], Name, Message)
		}
		else if(get_user_team(id) == 2) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[2], Name, Message) 
		}
		else if(get_user_team(id) == 3) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message) 
		} 
		else
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message) 
		}
		
	} 
	return PLUGIN_HANDLED 
} 

public VIP_Prefix_Team(id) 
{ 
	new Message[192] 
	new Name[33] 
	get_user_name(id, Name, charsmax(Name)) 
	
	read_args(Message, charsmax(Message)) 
	remove_quotes(Message) 
	
	if(is_user_alive(id)) 
	{ 
		if(get_user_team(id) == 0) 
		{ 
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message) 
		}
		else if(get_user_team(id) == 1) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message)
		}
		else if(get_user_team(id) == 2) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[4], Name, Message) 
		}
		else if(get_user_team(id) == 3) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message) 
		} 
		else
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message) 
		}
	} 
	else  
	{ 
		if(get_user_team(id) == 0) 
		{ 
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[0], Name, Message) 
		}
		else if(get_user_team(id) == 1) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[3], Name, Message)
		}
		else if(get_user_team(id) == 2) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[2], Name, Message) 
		}
		else if(get_user_team(id) == 3) 
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[1], Name, Message) 
		} 
		else
		{
			ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message) 
		}
		
	} 
	return PLUGIN_HANDLED
}
gameplayonline is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-03-2017 , 03:28   Re: How to replace color in chat?
Reply With Quote #3

You should use a switch instead of an if else if structure for the user's team. Calling get_user_team() that many times is inefficient.
__________________
fysiks is online now
gameplayonline
Member
Join Date: Jun 2017
Old 07-04-2017 , 04:26   Re: How to replace color in chat?
Reply With Quote #4

i read somewhere function if is faster than switch and when i use switch it doesnt show messages what i type when i change team and it kill myself with if is it working normal. Is it true?
I dont know how to do else in switch

Last edited by gameplayonline; 07-04-2017 at 04:26.
gameplayonline is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 07-04-2017 , 05:07   Re: How to replace color in chat?
Reply With Quote #5

PHP Code:
new CsTeams:teamteam cs_get_user_teamid 
    
switch( 
team )
{
    case 
CS_TEAM_T:
    {                    
        
//your code
    
}
    case 
CS_TEAM_CT:
    {
        
//your code
    
}


__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-04-2017 , 13:09   Re: How to replace color in chat?
Reply With Quote #6

https://wiki.alliedmods.net/Optimizi..._Optimizations
__________________
fysiks is online now
gameplayonline
Member
Join Date: Jun 2017
Old 07-08-2017 , 18:40   Re: How to replace color in chat?
Reply With Quote #7

after testing when i do
Code:
ColorChat(id, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
Only myself see sented message when i try
Code:
ColorChat(0, TEAM_COLOR, "%s ^3%s : ^4%s",prefix[5], Name, Message)
everyone see it but with color of his own team. Chat with prefix Dead too see all players how can i fix it please?
gameplayonline is offline
gameplayonline
Member
Join Date: Jun 2017
Old 07-08-2017 , 19:34   Re: How to replace color in chat?
Reply With Quote #8

In API
Code:
client_print_color

Syntax

native client_print_color(index, sender, const message[], any:...);
Usage

index	
Client index, use 0 to display to all clients
sender	
Client index used as the message sender
fmt	
Formatting rules
...	
Variable number of formatting parameters
IS client index usable like Team? I think 0 is all 1 is terrorist 2 is CT 3 is spectator or no?
gameplayonline is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-09-2017 , 00:33   Re: How to replace color in chat?
Reply With Quote #9

You can't choose red or blue, only team color. I know that there exists a function that tricks the game into thinking you are on the other team to force a color but I don't know if it actually works or is reliable.

index is the specific player which is often called "id" in most plugins/functions and is the player's entity index.
__________________

Last edited by fysiks; 07-09-2017 at 00:33.
fysiks is online now
gameplayonline
Member
Join Date: Jun 2017
Old 07-09-2017 , 11:19   Re: How to replace color in chat?
Reply With Quote #10

And is any other way how to do colored chat with prefixes where Terrorist will see name of Counter-Terrorist in blue color?
gameplayonline 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 23:10.


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