AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   how can i hook void ClientCommand (https://forums.alliedmods.net/showthread.php?t=261816)

thresh 04-21-2015 04:43

how can i hook void ClientCommand
 
Hello,
I try
void ClientCommand(edict_t *pEntity)
{
SERVER_PRINT("HALLO");
}
but it doesnt work. How can i hook all send to client commands on metamod plugin ?

Bos93 04-21-2015 07:36

Re: how can i hook void ClientCommand
 
How do you register it?

thresh 04-21-2015 10:19

Re: how can i hook void ClientCommand
 
I did not registered anything.

I'am trying catch all commands on server.
Sry,i'am newbie on metamod/c++.

I just want catch all amxmodx client_cmd, console_cmd function argvs.
Like ;
If some plugin send to player client_cmd(id,"say i'am n00b"); i catch it.
sry for my english
thanks

Bos93 04-21-2015 14:41

Re: how can i hook void ClientCommand
 
You need hook function from engine, PF_stuffcmd_I.

claudiuhks 04-21-2015 19:06

Re: how can i hook void ClientCommand
 
PHP Code:

// VOID = void
// PENTITY = edict_t *
// CPCHAR = const char *
// MAX_ARGS = 1024
// SIZE_T = size_t
// #include <string> // std::string
// ISPLR = #define ISPLR(PlrId) (PlrId >= 1 && PlrId <= gpGlobals->maxClients)
// g_pMetaGlobalVars->Result = Result; = RETURN_META(Result);

// CLIENT SENDS COMMAND
//
VOID onClientCommand(PENTITY pEntity)
{
    
// ARGUMENTS HANDLE
    //
    
static CPCHAR pArgs[MAX_ARGS];

    
// GETS CLIENT ID
    //
    
SIZE_T entityId g_engFuncs.pfnIndexOfEdict(pEntity);

    
// METAMOD RESULT
    //
    
METARESULT Result MRES_IGNORED;

    
// ARGUMENTS STRING (NO COMMAND)
    //
    
std::string argStr "";

    
// VALID PLAYER
    //
    
if (ISPLR(entityId))
    {
        
// ARGUMENTS COUNT
        //
        
SIZE_T argsCount g_engFuncs.pfnCmdArgc();

        
// ARGUMENTS HAVE PASSED
        
if (argsCount 0)
        {
            
// ITERATES BETWEEN ARGUMENTS
            //
            
for (SIZE_T Iterator 0Iterator argsCountIterator++)
            {
                
// FILLS UP pArgs
                
pArgs[Iterator] = g_engFuncs.pfnCmdArgv(Iterator);

                
// NO MORE VALIDITY CHECKS
                // IT'S KNOWN HOW MANY ARGUMENTS HAVE PASSED
                // SKIPS COMMAND NAME AS WELL
                //
                
if (Iterator 0)
                {
                    
// APPEND ARGUMENT TO STRING
                    //
                    
argStr += pArgs[Iterator];

                    
// ADDS SPACE IF NEEDED (UNTIL THE LAST ARGUMENT IS REACHED)
                    //
                    
if (Iterator != argsCount 1)
                        
argStr += " ";
                };
            };

            
// ITERATES BETWEEN COMMANDS
            //
            
for (SIZE_T Iterator 0Iterator g_cmdsMan.Size(); Iterator++)
            {
                
// CASE INSENSITIVE
                //
                
if (stricmp(g_cmdsMan.m_Cmds.at(Iterator).m_Name.c_str(), pArgs[0]) == 0)
                {
                    
// EXECUTES
                    //
                    
g_cmdsMan.Exec(IteratorpEntityentityIdargsCountpArgsargStr);

                    
// SUPERCEDES
                    //
                    
g_pMetaGlobalVars->Result MRES_SUPERCEDE;
                    return;
                };
            };

            
// MENUS
            //
            
if (stricmp(pArgs[0], "MenuSelect") == && pArgs[1] && g_Plr[entityId].menuId != INVALID_NUMBER)
            {
                
// GETS ITEM ID
                
SIZE_T ItemID atoi(pArgs[1]) - 1;

                
// CHECKS IF MENU HAS THAT ITEM
                //
                
if (g_menusMan.m_Menus.at(g_Plr[entityId].menuId).m_Keys & (<< ItemID))
                {
                    
// EXECUTES
                    //
                    
g_menusMan.Exec(entityIdg_Plr[entityId].menuIdItemID);

                    
// PLAYER HAS NO LONGER MENU
                    //
                    
g_Plr[entityId].menuId INVALID_NUMBER;
                };
            };

            
// SAY COMMAND
            //
            
if (stricmp(pArgs[0], "Say") == 0)
            {
                
// VALID ARGUMENT
                //
                
if (pArgs[1])
                {

                };
            };
        };
    };

    
// SETS RESULT AND QUIT
    //
    
g_pMetaGlobalVars->Result Result;
}; 

Also consider Bos93's post.
And don't forget about moduleconfig.h, uncomment (remove '//') from the front of ClientCommand...

hzqst 04-21-2015 19:38

Re: how can i hook void ClientCommand
 
Some commands don't go through ClientCommand, like "slot1~10", "screenshot", "quit", "connect","retry"
they are handled client-side,


see claudiuhks's reply.

thresh 04-22-2015 01:46

Re: how can i hook void ClientCommand
 
Thank you guys i will try it


All times are GMT -4. The time now is 04:17.

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