View Single Post
qNiGHT
AlliedModders Donor
Join Date: Mar 2019
Location: Romania
Old 09-03-2019 , 14:30   Re: [HELP] Set Player's Name Color
Reply With Quote #9

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 14:31.
qNiGHT is offline