Raised This Month: $ Target: $400
 0% 

[HOWTO] Make a nice say-hook


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 01-05-2005 , 15:09   [HOWTO] Make a nice say-hook
Reply With Quote #1

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
__________________
hello, i am pm
PM is offline
 


Thread Tools
Display Modes

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 07:19.


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