Raised This Month: $246 Target: $400
 61% 

Solved [REQ - TF2]Team name colored


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 08-19-2016 , 17:24   [REQ - TF2]Team name colored
Reply With Quote #1

Hello !
For a while now, I was looking for changing team name colors (I will explain what I'm looking for and what I tried).

So yes, team name colors like when a player is in the blue team, his name is blue and for example I want it in a different color like a different blue name, same case for Red Team and Spectator.

I tried some things with morecolors, without success (sad ), the only things I did is this :

PHP Code:
#include <sourcemod>
#include <morecolors>

public OnPluginStart()
{
  
AddCommandListener(ChatTriggers"say");
  
AddCommandListener(ChatTriggers"say_team");
}

public 
Action ChatTriggers(int client, const String:command[], int argc)
{
    
decl String:sMessage[255];
    
decl String:sClientName[64];

    
GetCmdArgString(sMessagesizeof(sMessage));
    
GetClientName(clientsClientNamesizeof(sClientName));
    
StripQuotes(sMessage);

    if (
CGetTeamColor(client) == COLOR_BLUE)
    {
      
CPrintToChatEx(clientclient"{steelblue}%s {default}: %s"sClientNamesMessage)
    }
    else if (
CGetTeamColor(client) == COLOR_RED)
    {
      
CPrintToChatEx(clientclient"{brown}%s {default}: %s"sClientNamesMessage)
    }
    return 
Plugin_Handled

I tried to understand simple chat processor in custom chat colors, without success (I am a real begineer) someone can help me/teach me how to do my request?

NB : Sorry if my English is bad

Last edited by Walgrim; 08-30-2016 at 08:44.
Walgrim is offline
Mayor Gamer
Senior Member
Join Date: Nov 2012
Location: GetLocationOfUser(me);
Old 08-19-2016 , 19:53   Re: [REQ - TF2]Team name colored
Reply With Quote #2

Hey there!

First, when you need to send code trough a forum post, wrap it around with the [CODE].

Code:
/** 
 * Returns the hexadecimal representation of a client's team color (will NOT initialize the trie, so if you use only this function from this include file, your plugin's memory usage will not increase) 
 * 
 * @param client        Client to get the team color for 
 * @return                Client's team color in hexadecimal, or green if unknown 
 * On error/Errors:        If the client index passed is invalid or not in game. 
 */ 
stock CGetTeamColor(client)
According to More Colors, this function returns the color in HEX code. So instead of COLOR_BLUE or COLOR_RED, it has to be TF2's team color's HEX codes, which are:

RED Team: FF4040
BLU Team: 99CCFF

So the code instead would be:

Code:
#include <sourcemod>
#include <morecolors>

public Plugin myinfo =
{
	name = "[TF2] Change Team Chat Colors",
	url = "https://forums.alliedmods.net/showthread.php?t=286558"
};

public OnPluginStart()
{
	AddCommandListener(ChatTriggers, "say");
	AddCommandListener(ChatTriggers, "say_team");
}

public Action ChatTriggers(int client, const String:command[], int argc)
{
	decl String:sMessage[255];
	decl String:sClientName[64];

	GetCmdArgString(sMessage, sizeof(sMessage));
	GetClientName(client, sClientName, sizeof(sClientName));
	StripQuotes(sMessage);

	if (CGetTeamColor(client) == 99CCFF)
	{
		CPrintToChatEx(client, client, "{steelblue}%s {default}: %s", sClientName, sMessage)
	}
	else if (CGetTeamColor(client) == FF4040)
	{
		CPrintToChatEx(client, client, "{brown}%s {default}: %s", sClientName, sMessage)
	}
}
No need to return Plugin_Handled since that would just not show the chat say (I think...)

Hope it helps! Didn't test this.
__________________
Engineering Student


| For private TF2 plugin requests, DM me in Discord: puntero#6566 |
| Steam Profile |
Mayor Gamer is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 08-20-2016 , 03:37   Re: [REQ - TF2]Team name colored
Reply With Quote #3

Ok so first, thank you for your reply !
So I tried to compile what you said and I get this :

PHP Code:
// namecolorteam.sp(25) : error 029: invalid expression, assumed zero
// namecolorteam.sp(25) : error 029: invalid expression, assumed zero
// namecolorteam.sp(25) : error 017: undefined symbol "CCFF"
// namecolorteam.sp(25) : fatal error 189: too many error messages on one line 
So I used like in morecolors to see because I like trying things, I get this :
PHP Code:
if (CGetTeamColor(client) == 0x99CCFF)
    {
        
CPrintToChatEx(clientclient"{steelblue}%s {default}: %s"sClientNamesMessage)
    }
    else if (
CGetTeamColor(client) == 0xFF4040)
    {
        
CPrintToChatEx(clientclient"{brown}%s {default}: %s"sClientNamesMessage)
    }

So the problems I get in using my code from the time I tried and now, are :
CPrintToChat just print to chat so players can't use (TEAM) canal.

I'm using custom chat colors so the problem is this :
http://puu.sh/qHMwI/42c03660c3.jpg
I tried something with the admin flag root without success (as far as I remember).

The third one is, when I'm dead it's printing like this : Walgrim : blabla
(I think there's something to do with player_death or something but i don't know how to use that).

EDIT : I used return Plugin_Handled because it's replacing the username, Plugin_Handled don't show the chat as you said but it shows the CPrintToChat, now it's printing 2 messages from me without it. (It's like in the picture).
__________________

Last edited by Walgrim; 08-20-2016 at 16:45.
Walgrim is offline
Mayor Gamer
Senior Member
Join Date: Nov 2012
Location: GetLocationOfUser(me);
Old 08-20-2016 , 10:00   Re: [REQ - TF2]Team name colored
Reply With Quote #4

Quote:
Originally Posted by Walgrim View Post
Ok so first, thank you for your reply !
So I tried to compile what you said and I get this :

Code:
// namecolorteam.sp(25) : error 029: invalid expression, assumed zero
// namecolorteam.sp(25) : error 029: invalid expression, assumed zero
// namecolorteam.sp(25) : error 017: undefined symbol "CCFF"
// namecolorteam.sp(25) : fatal error 189: too many error messages on one line
So I used like in morecolors to see because I like trying things, I get this :
Code:
if (CGetTeamColor(client) == 0x99CCFF)
	{
		CPrintToChatEx(client, client, "{steelblue}%s {default}: %s", sClientName, sMessage)
	}
	else if (CGetTeamColor(client) == 0xFF4040)
	{
		CPrintToChatEx(client, client, "{brown}%s {default}: %s", sClientName, sMessage)
	}
}
So the problems I get in using my code from the time I tried and now, are :
CPrintToChat just print to chat so players can't use (TEAM) canal.

I'm using custom chat colors so the problem is this :
http://puu.sh/qHMwI/42c03660c3.jpg
I tried something with the admin flag root without success (as far as I remember).

The third one is, when I'm dead it's printing like this : Walgrim : blabla
(I think there's something to do with player_death or something but i don't know how to use that).

EDIT : I used return Plugin_Handled because it's replacing the username, Plugin_Handled don't show the chat as you said but it shows the CPrintToChat, now it's printing 2 messages from me without it. (It's like in the picture).
Use the return Plugin_Handled at the end of the command listener callback so it doesn't print the original chat command and prints the custom message with colors. That should work, if the colors are applying correctly as you planned you should be free to go.
__________________
Engineering Student


| For private TF2 plugin requests, DM me in Discord: puntero#6566 |
| Steam Profile |
Mayor Gamer is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 08-20-2016 , 10:08   Re: [REQ - TF2]Team name colored
Reply With Quote #5

Quote:
Use the return Plugin_Handled at the end of the command listener callback so it doesn't print the original chat command and prints the custom message with colors. That should work, if the colors are applying correctly as you planned you should be free to go.
Ok and how can I do something like, when a player is dead CPrintToChatEx(client, client, "*DEAD*{darkgrey}%s{default} : %s", sClientName, sMessage) ?
And do something like CPrintToChat can use the chat team without showing a message to all?
__________________

Last edited by Walgrim; 08-20-2016 at 11:49.
Walgrim is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 08-20-2016 , 15:44   Re: [REQ - TF2]Team name colored
Reply With Quote #6

Ok so I did it for dead players and spectators ones.
Still don't know how I can change names color in the team chat area, someone can help?

EDIT : Problem with admin commands, everyone can see the "/"

I actually did this for the moment :
PHP Code:
#include <sourcemod>
#include <morecolors>

public Plugin myinfo =
{
    
name "[TF2] Change Team Chat Colors",
    
url "https://forums.alliedmods.net/showthread.php?t=286558"
};

public 
OnPluginStart()
{
    
AddCommandListener(ChatTriggers"say");
    
AddCommandListener(ChatTriggers"say_team");
}

public 
Action ChatTriggers(int client, const String:command[], int argc)
{
    
decl String:sMessage[255];
    
decl String:sClientName[64];

    
GetCmdArgString(sMessagesizeof(sMessage));
    
GetClientName(clientsClientNamesizeof(sClientName));
    
StripQuotes(sMessage);

    if (
IsPlayerAlive(client) && CGetTeamColor(client) == 0x99CCFF)
    {
        
CPrintToChatAll("{steelblue}%s {default}: %s"sClientNamesMessage);
    }
    else if (
CGetTeamColor(client) == 0x99CCFF)
    {
        
CPrintToChatAll("*DEAD* {steelblue}%s {default}: %s"sClientNamesMessage);
    }
    if (
IsPlayerAlive(client) && CGetTeamColor(client) == 0xFF4040)
    {
        
CPrintToChatAll("{corrupted}%s {default}: %s"sClientNamesMessage);
    }
    else if (
CGetTeamColor(client) == 0xFF4040)
    {
        
CPrintToChatAll("*DEAD* {corrupted}%s {default}: %s"sClientNamesMessage);
    }
    else if (
CGetTeamColor(client) == 0xCCCCCC)
    {
        
CPrintToChatAll("*SPEC* {dimgray}%s {default}: %s"sClientNamesMessage);
    }
    return 
Plugin_Handled

__________________

Last edited by Walgrim; 08-20-2016 at 16:46.
Walgrim is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 08-21-2016 , 17:47   Re: [REQ - TF2]Team name colored
Reply With Quote #7

Anyone can help me to understand how I can use simple chat processor and how have the colors I want? (I want to replace "(Voice) Walgrim : MEDIC!" color team too)
__________________
Walgrim is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 08-30-2016 , 08:44   Re: [REQ - TF2]Team name colored
Reply With Quote #8

Solved, I did it ;P
__________________
Walgrim is offline
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 21:18.


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