Raised This Month: $151 Target: $400
 37% 

[HELP] Set Player's Name Color


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Member
Join Date: Sep 2018
Location: CreateMyGF(int patience)
Old 08-13-2019 , 08:46   [HELP] Set Player's Name Color
Reply With Quote #1

Hey,

Today I tried to do by myself a plugin that changes, player's name color on chat.

I tried this but does not work:

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <colors>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[SpirT] Name Color",
    
author PLUGIN_AUTHOR,
    
description "This plugin allows any player to have permission to change his name in chat!",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_nc"Command_NameColor);
}

public 
Action Command_NameColor(int clientint args)
{
    if(
args 1)
    {
        
ReplyToCommand(client"[SM] Use: sm_nc <color> (examples: {red} {blue} {green} ...)");
    }
    
    
char arg[64];
    
GetCmdArg(1argsizeof(arg));
    
    
char file[512];
    
BuildPath(Path_SMfilesizeof(file), "nc.cfg");
    
KeyValues kv = new KeyValues("NC");
    
kv.ImportFromFile(file);
    
    
char sID[64];
    
GetClientAuthId(clientAuthId_Steam2sIDsizeof(sID));
    
    if(
KvJumpToKey(kvsIDtrue))
    {
        
char name[MAX_NAME_LENGTH];
        
char cor[64];
        
GetClientName(clientnamesizeof(name));
        
        
KvGetString(kv"nome"namesizeof(name));
        
KvGetString(kv"cor"corsizeof(cor));
        
        if(!
StrEqual(argcor))
        {
            
KvSetString(kv"cor"arg);
        }
        
        
ReplyToCommand(client"[SM] Sorry, but the color you choosed is already you name's color. Please choose another");
    }
    
    
delete kv;
    return 
Plugin_Handled;
}

public 
Action OnChatMessage(intauthorHandle recipientschar[] namechar[] message)
{
    
char file[512];
    
BuildPath(Path_SMfilesizeof(file), "nc.cfg");
    
    
KeyValues kv = new KeyValues("NC");
    
kv.ImportFromFile(file);
    
    
char sid[64];
    
GetClientAuthId(authorAuthId_Steam2sidsizeof(sid));
    if(
KvJumpToKey(kvsid))
    {
        
char color[64];
        
KvGetString(kv"cor"colorsizeof(color));
        
Format(nameMAX_NAME_LENGTH"%s%s"colorname);
    }

Where is the problem?

Best Regards,

SpirT.
__________________

Last edited by SpirT; 08-15-2019 at 10:53.
SpirT is offline
Mathiaas
Senior Member
Join Date: Aug 2014
Location: Sweden ♥
Old 09-02-2019 , 22:18   Re: [HELP] Set Player's Name Color
Reply With Quote #2

Quickly reading through your code, it's not like your OnChatMessage callback does anything? Sure you format the "name" string but that's not what's being sent out to the clients as the message.

You will probably have to stop your message from going out and send your own, customized one. It's 03 in the morning and tired af, but try this one:

PHP Code:
public Action OnChatMessage(intauthorHandle recipientschar[] namechar[] message)
{
    
char file[512];
    
char msg[200];
    
BuildPath(Path_SMfilesizeof(file), "nc.cfg");
    
    
KeyValues kv = new KeyValues("NC");
    
kv.ImportFromFile(file);
    
    
char sid[64];
    
GetClientAuthId(authorAuthId_Steam2sidsizeof(sid));
    if(
KvJumpToKey(kvsid))
    {
        
char color[64];
        
KvGetString(kv"cor"colorsizeof(color));
        
Format(msgsizeof(msg), "%s%s: %s"colornamemessage);
        
PrintToChatAll(msg); // Change this into "SayText2" if you want the teamcolors in case you want teamchat etc. https://forums.alliedmods.net/showthread.php?t=206539
        
return Plugin_Handled;
    }
    return 
Plugin_Continue;

Mathiaas is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-03-2019 , 13:32   Re: [HELP] Set Player's Name Color
Reply With Quote #3

Quote:
Originally Posted by Mathiaas View Post
Quickly reading through your code, it's not like your OnChatMessage callback does anything? Sure you format the "name" string but that's not what's being sent out to the clients as the message.

You will probably have to stop your message from going out and send your own, customized one. It's 03 in the morning and tired af, but try this one:

PHP Code:
public Action OnChatMessage(intauthorHandle recipientschar[] namechar[] message)
{
    
char file[512];
    
char msg[200];
    
BuildPath(Path_SMfilesizeof(file), "nc.cfg");
    
    
KeyValues kv = new KeyValues("NC");
    
kv.ImportFromFile(file);
    
    
char sid[64];
    
GetClientAuthId(authorAuthId_Steam2sidsizeof(sid));
    if(
KvJumpToKey(kvsid))
    {
        
char color[64];
        
KvGetString(kv"cor"colorsizeof(color));
        
Format(msgsizeof(msg), "%s%s: %s"colornamemessage);
        
PrintToChatAll(msg); // Change this into "SayText2" if you want the teamcolors in case you want teamchat etc. https://forums.alliedmods.net/showthread.php?t=206539
        
return Plugin_Handled;
    }
    return 
Plugin_Continue;

OnChatMessage comes from the scp include or a similar chat-processor.
There are several things wrong with this code, especially the reading the keyvalue from file everytime some one types in chat.
There are a ton of custom chat color plugins already out there try using those as examples and write your code off of that.
__________________
Mitchell is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 09-03-2019 , 14:47   Re: [HELP] Set Player's Name Color
Reply With Quote #4

Just use any chat processor wrapper
__________________
Expert of CMD/VBS/VB6. Malware analyst.
[My plugins] [My tools] [GitHub]
Dragokas is offline
qNiGHT
Junior Member
Join Date: Mar 2019
Old 09-03-2019 , 15:30   Re: [HELP] Set Player's Name Color
Reply With Quote #5

https://forums.alliedmods.net/showthread.php?t=286913
Try this
Code:
#pragma semicolon 1 

#define DEBUG 

#define PLUGIN_AUTHOR "SpirT" 
#define PLUGIN_VERSION "1.0" 

#include <sourcemod> 
#include <sdktools> 
#include <chat-processor>
#include <colors> 

#pragma newdecls required 

public Plugin myinfo = 
{
	name = "[SpirT] Name Color", 
	author = PLUGIN_AUTHOR, 
	description = "This plugin allows any player to have permission to change his name in chat!", 
	version = PLUGIN_VERSION, 
	url = ""
};

public void OnPluginStart()
{
	RegConsoleCmd("sm_nc", Command_NameColor);
}

public Action Command_NameColor(int client, int args)
{
	if (args < 1)
	{
		ReplyToCommand(client, "[SM] Use: sm_nc <color> (examples: {red} {blue} {green} ...)");
	}
	
	char arg[64];
	GetCmdArg(1, arg, sizeof(arg));
	
	char file[512];
	BuildPath(Path_SM, file, sizeof(file), "nc.cfg");
	KeyValues kv = new KeyValues("NC");
	kv.ImportFromFile(file);
	
	char sID[64];
	GetClientAuthId(client, AuthId_Steam2, sID, sizeof(sID));
	
	if (KvJumpToKey(kv, sID, true))
	{
		char name[MAX_NAME_LENGTH];
		char cor[64];
		GetClientName(client, name, sizeof(name));
		
		KvGetString(kv, "nome", name, sizeof(name));
		KvGetString(kv, "cor", cor, sizeof(cor));
		
		if (!StrEqual(arg, cor))
		{
			KvSetString(kv, "cor", arg);
		}
		
		ReplyToCommand(client, "[SM] Sorry, but the color you choosed is already you name's color. Please choose another");
	}
	
	delete kv;
	return Plugin_Handled;
}

public Action OnChatMessage(int & author, Handle recipients, char[] name, char[] message)
{
	char file[512];
	BuildPath(Path_SM, file, sizeof(file), "nc.cfg");
	
	KeyValues kv = new KeyValues("NC");
	kv.ImportFromFile(file);
	
	char sid[64];
	GetClientAuthId(author, AuthId_Steam2, sid, sizeof(sid));
	if (KvJumpToKey(kv, sid))
	{
		char color[64];
		KvGetString(kv, "cor", color, sizeof(color));
		Format(name, MAXLENGTH_NAME, "%s%s", color, name);
		return Plugin_Changed;
	}
	return Plugin_Handled;
}

Last edited by qNiGHT; 09-03-2019 at 15:31.
qNiGHT is offline
Mathiaas
Senior Member
Join Date: Aug 2014
Location: Sweden ♥
Old 09-03-2019 , 19:09   Re: [HELP] Set Player's Name Color
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
OnChatMessage comes from the scp include or a similar chat-processor.
There are several things wrong with this code, especially the reading the keyvalue from file everytime some one types in chat.
There are a ton of custom chat color plugins already out there try using those as examples and write your code off of that.
I simply changed the output part, didn't really look at anything else.
Mathiaas is offline
SpirT
Member
Join Date: Sep 2018
Location: CreateMyGF(int patience)
Old 09-04-2019 , 11:51   Re: [HELP] Set Player's Name Color
Reply With Quote #7

Quote:
Originally Posted by Mitchell View Post
OnChatMessage comes from the scp include or a similar chat-processor.
There are several things wrong with this code, especially the reading the keyvalue from file everytime some one types in chat.
There are a ton of custom chat color plugins already out there try using those as examples and write your code off of that.
So "There are several things wrong with this code, especially the reading the keyvalue from file everytime some one types in chat.", what is wrong with it? I have a simple chat processor include. I don't want to publish this plugin, but is there any way to get player message (OnChatMessage) without any chat processor?

Besr regards,

SpirT.
__________________
SpirT is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-04-2019 , 22:11   Re: [HELP] Set Player's Name Color
Reply With Quote #8

Quote:
Originally Posted by SpirT View Post
So "There are several things wrong with this code, especially the reading the keyvalue from file everytime some one types in chat.", what is wrong with it? I have a simple chat processor include. I don't want to publish this plugin, but is there any way to get player message (OnChatMessage) without any chat processor?

Besr regards,

SpirT.
Reading from a file everytime some one chats is not a good idea. Cache it internally like custom chat colors does. Loading from file implies the file will be changed by another plugin consistently. I'm not sure on the other issues and could be told wrong but file reading can hault the process causing a delay.

My comment on the chat processor had nothing to do with what was wrong, I was just pointing out that it's a forward from another plugin and you dont have which chat processor your using as an #include
__________________

Last edited by Mitchell; 09-04-2019 at 22:12.
Mitchell is offline
SpirT
Member
Join Date: Sep 2018
Location: CreateMyGF(int patience)
Old 09-05-2019 , 10:00   Re: [HELP] Set Player's Name Color
Reply With Quote #9

Quote:
Originally Posted by Mitchell View Post
Reading from a file everytime some one chats is not a good idea. Cache it internally like custom chat colors does. Loading from file implies the file will be changed by another plugin consistently. I'm not sure on the other issues and could be told wrong but file reading can hault the process causing a delay.

My comment on the chat processor had nothing to do with what was wrong, I was just pointing out that it's a forward from another plugin and you dont have which chat processor your using as an #include
Hey, thanks again for your help. Now about the chat processor, OnChatMessage comes from scp include
Asking in a better way again, is there any way to get client message WITHOUT ANY Chat Processor include?

Regards,

SpirT.
__________________
SpirT is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-05-2019 , 12:45   Re: [HELP] Set Player's Name Color
Reply With Quote #10

Quote:
Originally Posted by SpirT View Post
Hey, thanks again for your help. Now about the chat processor, OnChatMessage comes from scp include
Asking in a better way again, is there any way to get client message WITHOUT ANY Chat Processor include?

Regards,

SpirT.
There's a few ways but you would just be replicating what the chat processor already does? You would need to essentially recreate the processor and it's work-around fixes included that help developers create plugins that change chat messages.

I have a light weight Chat processor here: https://github.com/MitchDizzle/Cider...atProcessor.sp
It's essentially a rip off of Chat-Processor by Drixevel, however doesn't try to be too fancy with the color includes so it uses less memory and relies more on the chat color plugin to decide the hex colors and unicodes etc. My version also removes some of the convars and other nice features and sticks to what I needed which was dead/team chat etc. Also has its own way of using the template to replace the message and name to construct the message.
https://forums.alliedmods.net/showthread.php?p=2448733

Friendly reminded to run only one chat processor at a time.
__________________
Mitchell 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 10:08.


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