AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [HELP] Set Player's Name Color (https://forums.alliedmods.net/showthread.php?t=318080)

SpirT 08-13-2019 07:46

[HELP] Set Player's Name Color
 
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.

Mathiaas 09-02-2019 21:18

Re: [HELP] Set Player's Name Color
 
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;



Mitchell 09-03-2019 12:32

Re: [HELP] Set Player's Name Color
 
Quote:

Originally Posted by Mathiaas (Post 2665677)
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.

Dragokas 09-03-2019 13:47

Re: [HELP] Set Player's Name Color
 
Just use any chat processor wrapper

qNiGHT 09-03-2019 14:30

Re: [HELP] Set Player's Name Color
 
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;
}


Mathiaas 09-03-2019 18:09

Re: [HELP] Set Player's Name Color
 
Quote:

Originally Posted by Mitchell (Post 2665716)
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. :nono: :3 :crab:

SpirT 09-04-2019 10:51

Re: [HELP] Set Player's Name Color
 
Quote:

Originally Posted by Mitchell (Post 2665716)
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.

Mitchell 09-04-2019 21:11

Re: [HELP] Set Player's Name Color
 
Quote:

Originally Posted by SpirT (Post 2665839)
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

SpirT 09-05-2019 09:00

Re: [HELP] Set Player's Name Color
 
Quote:

Originally Posted by Mitchell (Post 2665929)
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.

Mitchell 09-05-2019 11:45

Re: [HELP] Set Player's Name Color
 
Quote:

Originally Posted by SpirT (Post 2665966)
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.


All times are GMT -4. The time now is 22:34.

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