View Single Post
CoolHandLuke
New Member
Join Date: Dec 2004
Old 03-19-2006 , 04:28   Re: [HOWTO] Make a nice say-hook
Reply With Quote #32

Quote:
Originally Posted by PM
I don't know whether you guys already know this, but I found out how to make a nice, pretty mod-independent say command hook.
As you have probably noticed, doing a CON_COMMAND_F("say", FCVAR_GAMEDLL) makes the original command completly disappear. So, this is what I came up with:

Code:
// Special hook for say commands
class CSayHook : public ConCommand
{
	// This will hold the pointer original gamedll say command
	ConCommand *m_pGameDLLSayCommand;
public:
	CSayHook() : ConCommand("say", NULL, "say messages", FCVAR_GAMEDLL), m_pGameDLLSayCommand(NULL)
	{ }

	// Override Init
	void Init()
	{
		// Try to find the gamedll say command
		ConCommandBase *pPtr = g_pICvar->GetCommands();
		while (pPtr)
		{
			if (pPtr != this && pPtr->IsCommand() && strcmp(pPtr->GetName(), "say") == 0)
				break;
			// Nasty
			pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
		}
		if (!pPtr)
			OMGOMGOMG ! PRINT ERROR1!1!1!!!!

		m_pGameDLLSayCommand = pPtr;

		// Call base class' init function
		ConCommand::Init();
	}

	void Dispatch()
	{
		// Do the normal stuff, return if you want to override the say

		// Forward to gamedll
		m_pGameDLLSayCommand->Dispatch();
	}
};

// Don't forget to make an instance
CSayHook g_SayHook;
(almost copy & paste from sourcemod)


EDIT: Fixed. Forgot m_pGameDLLSayCommand = pPtr; Thanks to u/d/theqizmo for reporting this
Wow this is exactly what Iwas looking for. But the part you edited did not compile because you forgot to convert it to a ConCommand. This do the job:

m_pGameDLLSayCommand = (ConCommand *)pPtr;

Thank for posting this, very much appreciated
CoolHandLuke is offline