View Single Post
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 07-25-2019 , 13:58   Re: old "SayText" in CSGO
Reply With Quote #4

If you're doing it for an SM extension then you can take advantage of the Usermessages interface. if it's for mms, then I'm afraid you'll have to go all around it yourself (you can always see how it's done in SM ofcourse), here's an example code:
HTML Code:
void UM_SayText(int *clients, int clientsCount, int author, bool addTag, const char *input)
{
	if( !input  )
	{
		return;
	}

	static int msgId = -1;

	if( msgId == -1 )
	{
		msgId = usermsgs->GetMessageIndex("SayText2");
	}

	CCSUsrMsg_SayText2 *msg = (CCSUsrMsg_SayText2 *) usermsgs->StartProtobufMessage(msgId, clients, 1, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);

	if( msg )
	{
		// Colors
		//	x01		->		default (white)
		//	x03		->		team (blue or orange)
		//	x04		->		green
		//	x05		->		olive
		//	x07%s	->		RRGGBB
		//	x08%s	->		RRGGBBAA

		static char buffer[1024];

		if( addTag )
		{
			ke::SafeSprintf(buffer, sizeof(buffer), "\x01 \x04[\x03%s\x04] \x01%s", g_pGameMod->GetTag(), input);
		}
		else
		{
			ke::SafeSprintf(buffer, sizeof(buffer), "\x01 \x01%s", input);
		}

		msg->set_ent_idx(author);
		msg->set_chat(true);
		msg->set_msg_name(buffer);

		const google::protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName("params");

		if( field )
		{
			msg->GetReflection()->AddString(msg, field, "");
			msg->GetReflection()->AddString(msg, field, "");
			msg->GetReflection()->AddString(msg, field, "");
			msg->GetReflection()->AddString(msg, field, "");
		}
	
		usermsgs->EndMessage();		
	}
}

NOTE: you'll have to link the libprotobuf.lib/a file, and you'll also need to include some additional source and header files for the linking to work, all of this can be found on the HL2SDK for CSGO, provided by the AlliedModders team. for the source files you can just need these:
Code:
public/engine/protobuf/netmessages.pb.cc 
public/game/shared/csgo/protobuf/cstrike15_usermessages.pb.cc
public/game/shared/csgo/protobuf/cstrike15_usermessage_helpers.cpp
Also, for winows you'll have to compile libprotobuf yourself.

For useful info on the matter, check this out: https://wiki.alliedmods.net/Compiling_libprotobuf

Last edited by TheDS1337; 07-25-2019 at 14:01.
TheDS1337 is offline