You can do this (copied from CS:S DM for hooking say)
Code:
//more hax - hook say cmd
ConCommandBase *pCmd = m_ICvar->GetCommands();
while (pCmd)
{
if (pCmd->IsCommand()
&& (strcmp(pCmd->GetName(), "say") == 0))
break;
pCmd = const_cast<ConCommandBase *>(pCmd->GetNext());
}
if (pCmd)
{
pSayCmd = (ConCommand *)pCmd;
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pSayCmd, Say_handler, false);
} else {
pSayCmd = NULL;
}
Just make sure to SH_DECL_HOOK0_void the Dispatch from ConCommand. Also! Don't forget you need to hook SetCommandClient, which sends the last id to use a server command.
So in your handler, you'd do like:
Code:
void BuyDispatch_handler()
{
//srcds gives index - 1 for some reason
int index = OmgMyPlugin.GetCommandClient() + 1;
}
BEHOLD, the power of SourceHook!
__________________