Raised This Month: $12 Target: $400
 3% 

Chattags Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 04-16-2017 , 16:23   Chattags Plugin
Reply With Quote #1

I made this plugin to read info from a textfile to have chattags for clients based upon their Admin Flag. I tested it by adding this to the text file "Admin_Root owner red". My chat goes through the same as normally and there aren't any errors in the server console. Any ideas where I went wrong? Thanks for your help.

Some Useful Info: cTags is supposed to hold the information for each client. tags is just the information read from the text file. For example cTags[4][2] should represent the color that is intended of the tag for the client at index 4. cTags[4][0] is the admin flag and cTags[4][1] is the actual tag word.

Code:

#include <sourcemod>
#include <sdktools>
#include <colors_codes>
#include <admin>

char cTags[64][3][128];
char tags[20][3][128];

public Plugin myinfo = 
{
	name = "", 
	author = "AfricanSpaceJesus", 
	description = "", 
	version = "0.5", 
	url = "http://steamcommunity.com/id/swagattack835/"
};

public void OnPluginStart()
{
	HookEvent("player_chat", onChat);
	readFile();
}

public OnClientPostAdminCheck(int client)
{
	setTag(client);
}

public Action onChat(Event event, const char[] name, bool dontBroadcast)
{
	int user = GetEventInt(event, "userid");
	int client = GetClientOfUserId(user);
	char text[128];
	GetEventString(event, "text", text, sizeof(text));
	char name[128];
	char tag[128];
	char temp[128];
	char final[128];
	GetClientName(client, name, sizeof(name));
	Format(tag, sizeof(tag), "{%s}[%s]", cTags[client][2], cTags[client][1]);
	Format(temp, sizeof(temp), "{default} %s: %s", name, text);
	Format(final, sizeof(final), "%s %s", tag, temp);
	CPrintToChatAll("%s", final);
	
	return Plugin_Handled;
}

public void setTag(int client)
{
	for (int i = 0; i < sizeof(tags); i++)
	{
		int flag = ReadFlagString(tags[i][0]);
		if (GetUserFlagBits(client) & flag == flag)
		{
			cTags[i][0] = tags[i][0];
			cTags[i][1] = tags[i][1];
			cTags[i][2] = tags[i][2];
		}
	}
}

public void readFile()
{
	char path[128];
	BuildPath(Path_SM, path, sizeof(path), "/configs/ChatTags.txt");
	Handle file = OpenFile(path, "r", false);
	char line[128];
	char array[3][128];
	int i = 0;
	
	while (!IsEndOfFile(file) && ReadFileLine(file, line, sizeof(line)))
	{
		ExplodeString(line, " ", array, sizeof(array), sizeof(array[]));
		tags[i][0] = array[0];
		tags[i][1] = array[1];
		tags[i][2] = array[2];
		i++;
	}
	
}

EDIT: I realized I forgot to add the name of the client to the message, fixing right now
EDIT2: Fixed name
__________________
Taking paid plugin requests

Last edited by africanspacejesus; 04-16-2017 at 16:27.
africanspacejesus is offline
sdz
Senior Member
Join Date: Feb 2012
Old 04-16-2017 , 17:02   Re: Chattags Plugin
Reply With Quote #2

I'd use some definition macros to help make your code readable if you intend on releasing this. You know,
Code:
#define TAG_COLOR   0 
cTags[client][TAG_COLOR] = xxx;
Also, what game is this for? I know most cases that i've EVER modified chat I've done it in a method of adding say in a command listener, or recently using OnClientSayCommand

Last edited by sdz; 04-16-2017 at 17:02.
sdz is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 04-16-2017 , 17:16   Re: Chattags Plugin
Reply With Quote #3

Quote:
Originally Posted by EasSidezz View Post
I'd use some definition macros to help make your code readable if you intend on releasing this. You know,
Code:
#define TAG_COLOR   0 
cTags[client][TAG_COLOR] = xxx;
Also, what game is this for? I know most cases that i've EVER modified chat I've done it in a method of adding say in a command listener, or recently using OnClientSayCommand
For a CSGO server and it is being custom made for the owner.
__________________
Taking paid plugin requests
africanspacejesus is offline
sdz
Senior Member
Join Date: Feb 2012
Old 04-16-2017 , 17:18   Re: Chattags Plugin
Reply With Quote #4

Quote:
Originally Posted by africanspacejesus View Post
For a CSGO server and it is being custom made for the owner.
Yeah try sending all that through OnClientSayCommand. If you wanted some non spaghetti to steal, you could jack some stuff from my chatrooms plugin.
sdz is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 04-16-2017 , 17:28   Re: Chattags Plugin
Reply With Quote #5

Quote:
Originally Posted by EasSidezz View Post
OnClientSayCommand
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 04-16-2017 , 17:58   Re: Chattags Plugin
Reply With Quote #6

Quote:
Originally Posted by EasSidezz View Post
Yeah try sending all that through OnClientSayCommand. If you wanted some non spaghetti to steal, you could jack some stuff from my chatrooms plugin.
Thanks, I'll try this out, if it doesn't work I'll take a look at your plugin

Code:
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
	if (StrEqual("say", command))
	{
		char name[128];
		char tag[128];
		char temp[128];
		char final[128];
		GetClientName(client, name, sizeof(name));
		Format(tag, sizeof(tag), "{%s}[%s]", cTags[client][2], cTags[client][1]);
		Format(temp, sizeof(temp), "{default} %s: %s", name, text);
		Format(final, sizeof(final), "%s %s", tag, temp);
		CPrintToChatAll("%s", final);
	}
	
	return Plugin_Handled;
}
EDIT: Now shows this, maybe its not reading the file correctly but at least it is redisplaying the name and other info

__________________
Taking paid plugin requests

Last edited by africanspacejesus; 04-16-2017 at 18:11.
africanspacejesus is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 04-17-2017 , 09:58   Re: Chattags Plugin
Reply With Quote #7

If you want to modify the chat you should stick to a standard that other plugins use aka Simple Chat Processor or Chat Processor. Use the forwards in one of those plugins

Last edited by blaacky; 04-17-2017 at 09:58.
blaacky is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 04-17-2017 , 15:57   Re: Chattags Plugin
Reply With Quote #8

Quote:
Originally Posted by blaacky View Post
If you want to modify the chat you should stick to a standard that other plugins use aka Simple Chat Processor or Chat Processor. Use the forwards in one of those plugins
So I would need to include the "chat-processor.inc" file and use the "public Action CP_OnChatMessage(int& author, ArrayList recipients, char[] flagstring, char[] name, char[] message, bool& processcolors, bool& removecolors)" forward? I'll modify my code to use that and edit how its done and repost the code and its effect when I am done. Thanks

EDIT: Heres the code will test in a minute

Code:
public Action CP_OnChatMessage(int & author, ArrayList recipients, char[] flagstring, char[] name, char[] message, bool & processcolors, bool & removecolors)
{
	if (IsFakeClient(author))
		return Plugin_Handled;
	Format(name, sizeof(name), "{%s}[%s] %s", cTags[author][2], cTags[author][1], name);
	Format(message, sizeof(message), "{default} %s", message);
	return Plugin_Changed;
}
Result: Chatting is normal like without any plugins
__________________
Taking paid plugin requests

Last edited by africanspacejesus; 04-17-2017 at 16:38.
africanspacejesus is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 04-17-2017 , 17:21   Re: Chattags Plugin
Reply With Quote #9

The code you posted wouldn't even compile.. since the size of "name" and "message" are not determined, you will get a compile error and have to use MAXLENGTH_NAME/MAXLENGTH_MESSAGE.
Are you sure the plugin actually compiles and loads?
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 04-17-2017 , 17:24   Re: Chattags Plugin
Reply With Quote #10

Quote:
Originally Posted by pcmaster View Post
The code you posted wouldn't even compile.. since the size of "name" and "message" are not determined, you will get a compile error and have to use MAXLENGTH_NAME/MAXLENGTH_MESSAGE.
Are you sure the plugin actually compiles and loads?
My bad I forgot to edit it that I changed the size of those and it did compile. I also added the chat proceesor plugin to the server
__________________
Taking paid plugin requests
africanspacejesus 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 11:00.


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