AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_cmd vs console_cmd (https://forums.alliedmods.net/showthread.php?t=241026)

vamppa 05-26-2014 07:40

client_cmd vs console_cmd
 
When the situation fits to use console_cmd am I right in saying it is a little more efficient to use apposed to client_cmd?

PHP Code:

static cell AMX_NATIVE_CALL console_cmd(AMX *amxcell *params/* 2 param */
{
    
int index params[1];
    
g_langMngr.SetDefLang(index);
    
int len;
    
charcmd format_amxstring(amxparams2len);
    
    
cmd[len++] = '\n';
    
cmd[len] = 0;

    if (
index || index gpGlobals->maxClients)
    {
        
SERVER_COMMAND(cmd);
    } else {
        
CPlayerpPlayer GET_PLAYER_POINTER_I(index);
        
        if (!
pPlayer->bot && pPlayer->initialized)
            
CLIENT_COMMAND(pPlayer->pEdict"%s"cmd);
    }

    return 
len;


PHP Code:

static cell AMX_NATIVE_CALL client_cmd(AMX *amxcell *params/* 2 param */
{
    
int len;
    
charcmd format_amxstring(amxparams2len);
    
cmd[len++] = '\n';
    
cmd[len] = 0;

    if (
params[1] == 0)
    {
        for (
int i 1<= gpGlobals->maxClients; ++i)
        {
            
CPlayerpPlayer GET_PLAYER_POINTER_I(i);
            if (!
pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/)
                
CLIENT_COMMAND(pPlayer->pEdict"%s"cmd);
        }
    } else {
        
int index params[1];
        
        if (
index || index gpGlobals->maxClients)
        {
            
LogError(amxAMX_ERR_NATIVE"Invalid player id %d"index);
            return 
0;
        }
        
        
CPlayerpPlayer GET_PLAYER_POINTER_I(index);
        
        if (!
pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/)
            
CLIENT_COMMAND(pPlayer->pEdict"%s"cmd);
    }
    
    return 
len;



YamiKaitou 05-26-2014 09:52

Re: client_cmd vs console_cmd
 
The only difference between them is that console_cmd sends it to the server if Index is 0, where client_cmd sends it to all connected users

fysiks 05-26-2014 14:34

Re: client_cmd vs console_cmd
 
Also, IIRC, commands registered with register_clcmd() will not be hooked if they are used in the server's console. So, you use register_clcmd() when you have things that require that it come from a client's actual game (things like menus and other things that are actually displayed on the HUD.


All times are GMT -4. The time now is 09:40.

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