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

[HOWTO] Make a nice say-hook


Post New Thread Reply   
 
Thread Tools Display Modes
[CCC]Taz-Devil
Junior Member
Join Date: Apr 2004
Old 05-26-2005 , 10:46  
Reply With Quote #31

Quote:
Originally Posted by Ruckus
I'd really like to incorporate a say hook for the plugin I'm working on, but I'm having a hard time. I'm obviously doing something wrong but I don't know what. Here's what I've been trying (on a Linux system):

-Put PM's say hook code in a header file, sayhook.h
-Declare g_pICvar as an extern
-Include sayhook.h in my plugin's cpp file
-Declare an object of type CSayHook

From here I do a make and everything compiles fine. But, when I try to load my plugin the server console just says "Unable to load plugin". If I comment out the line where I declare the CSayHook object and recompile, the plugin loads fine.

I must be overlooking something obvious but I'm at a loss. Any suggestions?
Hi, i'm having the same trouble with my plugin, when i tried to hook convar. everything compiles fine (i have convar.o) but the same error "Unable to load plugin", somebody have a solution..

i used XAD's code .. (run correctly with windows )
http://forums.alliedmods.net/showthread.php?t=37181

thanks
[CCC]Taz-Devil is offline
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
jimihendrix
Member
Join Date: May 2007
Old 02-20-2008 , 12:44   Re: [HOWTO] Make a nice say-hook
Reply With Quote #33

hi ,

thanks for share this code

i tried hook say in my plugin, this code works but when use m_Engine in Dispatch server crash

this code works with engine calls?

i need for get some command in chat
Code:
    void Dispatch()
    {
//this line crash server
        int argcount = m_Engine->Cmd_Argc();

        // Forward to gamedll
        m_pGameDLLSayCommand->Dispatch();
        
    }
i need for do code like this...

Last edited by jimihendrix; 02-20-2008 at 21:09. Reason: FIX: the problem its on declaration m_Engine, now works perfect :)
jimihendrix is offline
jimihendrix
Member
Join Date: May 2007
Old 03-19-2008 , 16:51   Re: [HOWTO] Make a nice say-hook
Reply With Quote #34

i tried load my plugin with load in console and works perfect but
when i try put in metaplugin.ini and start dedicated server,
console prints

OMGOMGOMG ! PRINT ERROR1!1!1!!!!

and not works the hook, i put all code in my plugin .cpp and works fine with load..
i need declare CSayHook g_SayHook; in another site?

thanks
jimihendrix 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 05:58.


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